forked from 1b-agent/opencadstudio-upstream
fix(visual): keep Extension snap guide on acquired OTRACK ray
This commit is contained in:
1 parent
54fb20d343
commit
4ad00fad33
1 file changed
+23
-3
+23
-3
@@ -1919,10 +1919,26 @@ impl canvas::Program<Message> for SelectionCanvas {
|
|||||||
// toward the snap point, so the guide line and the three
|
// toward the snap point, so the guide line and the three
|
||||||
// dots follow the actual extension path (#238).
|
// dots follow the actual extension path (#238).
|
||||||
let dir = self.snap_ext_base.and_then(|base| {
|
let dir = self.snap_ext_base.and_then(|base| {
|
||||||
|
// Reuse the acquired tracking ray when its origin
|
||||||
|
// matches this Extension base. Deriving a new ray
|
||||||
|
// from the moving snap marker makes the short OSNAP
|
||||||
|
// guide rotate even while OTRACK stays stable.
|
||||||
|
let acquired = self.otrack_lines.iter().find_map(|&(origin, tip)| {
|
||||||
|
let offset = (origin.x - base.x).hypot(origin.y - base.y);
|
||||||
|
if offset > 2.0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let dx = tip.x - origin.x;
|
||||||
|
let dy = tip.y - origin.y;
|
||||||
|
let len = dx.hypot(dy);
|
||||||
|
(len > 1e-3).then_some(Point::new(dx / len, dy / len))
|
||||||
|
});
|
||||||
let dx = sp.x - base.x;
|
let dx = sp.x - base.x;
|
||||||
let dy = sp.y - base.y;
|
let dy = sp.y - base.y;
|
||||||
let len = (dx * dx + dy * dy).sqrt();
|
let len = dx.hypot(dy);
|
||||||
(len > 1e-3).then(|| (base, Point::new(dx / len, dy / len)))
|
acquired
|
||||||
|
.or_else(|| (len > 1e-3).then(|| Point::new(dx / len, dy / len)))
|
||||||
|
.map(|u| (base, u))
|
||||||
});
|
});
|
||||||
// Dashed guide line from that endpoint, through the snap
|
// Dashed guide line from that endpoint, through the snap
|
||||||
// point and a little beyond, so the extension path is
|
// point and a little beyond, so the extension path is
|
||||||
@@ -1935,7 +1951,11 @@ impl canvas::Program<Message> for SelectionCanvas {
|
|||||||
},
|
},
|
||||||
..canvas::Stroke::default().with_color(marker).with_width(1.0)
|
..canvas::Stroke::default().with_color(marker).with_width(1.0)
|
||||||
};
|
};
|
||||||
let tip = Point::new(sp.x + u.x * 18.0, sp.y + u.y * 18.0);
|
let along = (sp.x - base.x) * u.x + (sp.y - base.y) * u.y;
|
||||||
|
let tip = Point::new(
|
||||||
|
base.x + u.x * (along + 18.0),
|
||||||
|
base.y + u.y * (along + 18.0),
|
||||||
|
);
|
||||||
// `base` is a projected entity endpoint: clip before
|
// `base` is a projected entity endpoint: clip before
|
||||||
// stroking (see `clip_seg`).
|
// stroking (see `clip_seg`).
|
||||||
if let Some((a, b)) = clip_seg(base, tip, bounds) {
|
if let Some((a, b)) = clip_seg(base, tip, bounds) {
|
||||||
|
|||||||
Reference in new issue
Block a user