From 90a239b410ac62eb93f9a873eb3303c77efed6ee Mon Sep 17 00:00:00 2001 From: ZachAR3 Date: Sun, 25 Oct 2026 00:22:55 +0200 Subject: [PATCH 01/30] CIRCLE: tangent snaps for the radius and for 3P points (fixes #1512) At CIRCLE's radius and diameter prompts a TAN pick on a circle or arc used the tangent point as seen from the center, which gives the wrong radius, and the 3P points took a tangent as a plain point. These prompts now take the tangent as deferred and CIRCLE resolves it: - Radius or diameter: the circle around the center that touches the curve, on the side it was picked. - 3P: the circle through the plain points that touches every curve picked with TAN, solved by the Tan, Tan, Tan solver (a plain point is a circle of radius zero). Three tangent picks give Tan, Tan, Tan. Points with no such circle report "Circle does not exist." and ask for the last point again. A perpendicular from the base is still resolved from it, so PER keeps giving a circle tangent to a line. Only prompts that ask for deferred snaps change: LINE's have no base. --- crates/engine/src/cmd/draw.rs | 61 ++++++++++++++++++++++-- crates/engine/src/prompt.rs | 5 +- crates/engine/src/snap.rs | 24 ++++++---- crates/engine/tests/it/snap_overrides.rs | 50 +++++++++++++++++++ docs/ui-parity.md | 5 +- 5 files changed, 127 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index ce8c8f7d10..9c7e88feec 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -740,6 +740,8 @@ impl Interactive for PlineM { struct CircleM { mode: u8, // 0 center-radius, 1 = 3P, 2 = 2P, 3 = TTR pts: Vec, + /// 3P: the circle or arc each point was picked on with a tangent snap, by point. + tans: Vec>, diameter: bool, /// The `Ttr` option hands over to the tangent-circle machine. delegate: Option>, @@ -758,18 +760,22 @@ impl Interactive for CircleM { match (self.mode, n) { (0, 0) => Prompt::new("Specify center point for circle", Accept::POINT).kw(&["3P", "2P", "Ttr (tan tan radius)"]), (0, _) if self.diameter => { - Prompt::new("Specify diameter of circle", Accept::POINT_OR_NUMBER).base_opt(self.pts.first().copied()).distance() + Prompt::new("Specify diameter of circle", Accept::POINT_OR_NUMBER).base_opt(self.pts.first().copied()).distance().deferred() } (0, _) => { - let p = - Prompt::new("Specify radius of circle", Accept::POINT_OR_NUMBER).kw(&["Diameter"]).base_opt(self.pts.first().copied()).distance(); + let p = Prompt::new("Specify radius of circle", Accept::POINT_OR_NUMBER) + .kw(&["Diameter"]) + .base_opt(self.pts.first().copied()) + .distance() + .deferred(); if last_r > 0.0 { p.default(format!("{last_r:.4}")) } else { p } } (1, k) => Prompt::new( ["Specify first point on circle", "Specify second point on circle", "Specify third point on circle"].get(k).copied().unwrap_or(""), Accept::POINT, ) - .base_opt(self.pts.last().copied()), + .base_opt(self.pts.last().copied()) + .deferred(), (2, k) => Prompt::new( if k == 0 { "Specify first end point of circle's diameter" } else { "Specify second end point of circle's diameter" }, Accept::POINT, @@ -809,7 +815,14 @@ impl Interactive for CircleM { let r = if self.diameter { c.dist(*e) / 2.0 } else { c.dist(*e) }; Some(Circle::new(*c, r)) } - 1 if self.pts.len() == 3 => Circle::from_3_points(self.pts[0], self.pts[1], self.pts[2]), + 1 if self.pts.len() == 3 => match self.three_points() { + Some(c) => Some(c), + None => { + self.pts.pop(); + self.tans.truncate(self.pts.len()); + return Err(crate::EngineError::Other("Circle does not exist.".into())); + } + }, 2 if self.pts.len() == 2 => Some(Circle::from_2_points(self.pts[0], self.pts[1])), _ => None, }; @@ -819,6 +832,31 @@ impl Interactive for CircleM { } Ok(Step::Continue) } + // 3P: a point picked with a tangent snap makes the circle tangent to that curve (#1512). + Input::Deferred(d) if self.mode == 1 => { + let tan = match d.curve { + snap::SnapCurve::Circle { center, radius } | snap::SnapCurve::Arc { center, radius, .. } if d.mode == snap::mode::TAN => { + Some(Circle::new(center, radius)) + } + _ => None, + }; + self.tans.resize(self.pts.len(), None); + self.tans.push(tan); + self.input(s, Input::Point(d.at)) + } + // A tangent picked for the radius: the circle around the center that touches the + // curve, on the side it was picked (#1512). + Input::Deferred(d) if self.mode == 0 && self.pts.len() == 1 => { + let Some(&c) = self.pts.first() else { return Ok(Step::Continue) }; + let touch = d.curve.perpendiculars(c, d.at).into_iter().min_by(|a, b| a.dist(d.at).total_cmp(&b.dist(d.at))); + match touch.map(|t| c.dist(t)).filter(|r| *r > 1e-12 && r.is_finite()) { + Some(r) => { + finish_circle(s, Circle::new(c, r))?; + Ok(Step::Done) + } + None => Err(crate::EngineError::Other("No circle around the center is tangent there.".into())), + } + } Input::Text(t) if self.mode == 0 && self.pts.len() == 1 => { let v = number(&t).ok_or_else(|| crate::EngineError::Other("Requires numeric distance or second point.".into()))?; let r = if self.diameter { v / 2.0 } else { v }; @@ -863,6 +901,19 @@ impl Interactive for CircleM { } } +impl CircleM { + /// The 3P circle: through the three points, or tangent to the curves picked with TAN. + fn three_points(&self) -> Option { + let [a, b, c] = <[Vec2; 3]>::try_from(self.pts.as_slice()).ok()?; + if self.tans.iter().all(Option::is_none) { + return Circle::from_3_points(a, b, c); + } + // A plain point is a circle of radius zero to pass through. + let obj = |i: usize, p: Vec2| (super::curves::TanObj::Circle(self.tans.get(i).copied().flatten().unwrap_or(Circle::new(p, 0.0))), p); + super::curves::ttt([obj(0, a), obj(1, b), obj(2, c)]) + } +} + fn finish_circle(s: &mut Session, c: Circle) -> Result<()> { s.add_entity(circle(c.center, c.radius))?; s.doc_mut()?.header.set_f64("CIRCLERAD", c.radius); diff --git a/crates/engine/src/prompt.rs b/crates/engine/src/prompt.rs index 63883240cb..a441d81881 100644 --- a/crates/engine/src/prompt.rs +++ b/crates/engine/src/prompt.rs @@ -38,8 +38,9 @@ pub struct Prompt { /// Rubber-band origin (for direct distance entry, ortho and polar). pub base: Option, /// The command resolves deferred tangent/perpendicular snaps ([`Input::Deferred`]) at this - /// prompt (a point with no base yet, e.g. the first point of a line). Elsewhere a deferred - /// pick arrives as the plain point it was picked at. + /// prompt (a point with no base yet, e.g. the first point of a line; with a base, only + /// tangents, e.g. a circle's radius). Elsewhere a deferred pick arrives as the plain point it + /// was picked at. pub deferred: bool, /// The base is a rectangle's first corner (ZOOM Window, RECTANG, ARRAYRECT's unit cell): ortho /// does not bend the opposite corner, so the rectangle keeps its area. diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 956d919c7c..f739afe0ab 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -110,7 +110,7 @@ impl SnapCurve { } /// Points on the curve whose perpendicular passes through `p`; `picked` is where the curve /// was picked, kept when `p` is the center of a circle or arc (every radius is perpendicular). - fn perpendiculars(&self, p: Vec2, picked: Vec2) -> Vec { + pub(crate) fn perpendiculars(&self, p: Vec2, picked: Vec2) -> Vec { match self { SnapCurve::Circle { center, radius } | SnapCurve::Arc { center, radius, .. } => { let u = (p - *center).normalized(); @@ -202,7 +202,9 @@ fn prim_segments(p: &Prim) -> Vec { /// Tangent and perpendicular snaps need the base point (the other end of the line). With no /// base and `deferred` set (the prompt says it can resolve them, `Prompt.deferred`), /// they snap as *deferred*: the hit carries the curve and is resolved once the other end is -/// known. Deferred hits only win where no other snap does (they are as unspecific as Nearest). +/// known. With a base and `deferred` set, tangents are deferred too (CIRCLE's radius: the circle +/// around the base that touches the curve, #1512). Deferred hits only win where no other snap +/// does (they are as unspecific as Nearest). pub fn osnap(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Option { if osmode == 0 || osmode & mode::OFF != 0 { return None; @@ -489,7 +491,7 @@ fn finish( _ => {} } } - if osmode & mode::TAN != 0 { + if osmode & mode::TAN != 0 && !deferred { let pts = match p { // Only the tangent points that lie on the arc itself (not its circle). Prim::Seg(Segment::Arc { arc, .. }) => Circle::new(arc.center, arc.radius) @@ -516,10 +518,9 @@ fn finish( if let Some((m, p)) = best { return Some(SnapHit { point: *p, mode: *m, name: name_of(*m), viewport: None, deferred: None }); } - if base.is_none() - && deferred - && let Some(h) = deferred_hit(near_prims, cursor, aperture, osmode, clip) - { + // With a base, perpendiculars are resolved from it above; only tangents are left to defer. + let deferrable = if base.is_some() { osmode & mode::TAN } else { osmode }; + if deferred && let Some(h) = deferred_hit(near_prims, cursor, aperture, deferrable, clip) { return Some(h); } if osmode & mode::NEA != 0 { @@ -1171,9 +1172,14 @@ mod tests { let df = h.deferred.unwrap(); assert_eq!(df.curve, SnapCurve::Circle { center: Vec2::new(20.0, 0.0), radius: 2.0 }); assert_eq!(h.input(), crate::Input::Deferred(df)); - // With a base it is an ordinary tangent. - let t = osnap(&d, &Space::Model, Vec2::new(19.9, 1.9), 1.0, mode::TAN, Some(Vec2::new(10.0, 0.0)), true).unwrap(); + // With a base it is an ordinary tangent, unless the prompt resolves it (CIRCLE's radius). + let t = osnap(&d, &Space::Model, Vec2::new(19.9, 1.9), 1.0, mode::TAN, Some(Vec2::new(10.0, 0.0)), false).unwrap(); assert!(t.deferred.is_none() && t.name == "Tangent"); + let t = osnap(&d, &Space::Model, at, 0.5, mode::TAN, Some(Vec2::new(10.0, 0.0)), true).unwrap(); + assert_eq!(t.name, "Deferred Tangent"); + // A perpendicular from the base is still resolved from it. + let p = osnap(&d, &Space::Model, Vec2::new(2.0, 0.2), 0.5, mode::PER, Some(Vec2::new(2.0, 5.0)), true).unwrap(); + assert!(p.deferred.is_none() && p.point.near(Vec2::new(2.0, 0.0), 1e-9)); // A specific snap still wins over a deferred one. let q = osnap(&d, &Space::Model, at, 0.5, mode::TAN | mode::QUA, None, true).unwrap(); assert_eq!(q.mode, mode::QUA); diff --git a/crates/engine/tests/it/snap_overrides.rs b/crates/engine/tests/it/snap_overrides.rs index a02ab92da5..3d6e0402ce 100644 --- a/crates/engine/tests/it/snap_overrides.rs +++ b/crates/engine/tests/it/snap_overrides.rs @@ -21,6 +21,17 @@ fn last_line(s: &Session) -> (Vec2, Vec2) { s.doc().unwrap().model.iter().filter_map(|e| if let EntityKind::Line(l) = &e.kind { Some((l.a.xy(), l.b.xy())) } else { None }).last().unwrap() } +/// The last circle drawn as (center, radius). +fn last_circle(s: &Session) -> (Vec2, f64) { + s.doc() + .unwrap() + .model + .iter() + .filter_map(|e| if let EntityKind::Circle(c) = &e.kind { Some((c.center.xy(), c.radius)) } else { None }) + .last() + .unwrap() +} + fn near(p: Vec2, x: f64, y: f64) -> bool { p.near(Vec2::new(x, y), 1e-9) } @@ -116,3 +127,42 @@ fn a_command_keyword_wins_over_a_snap_word() { s.cmdline("arc _cen").unwrap(); assert!(s.prompt_text().ends_with("Center of:"), "{}", s.prompt_text()); } + +#[test] +fn tan_for_a_circle_radius_touches_the_picked_circle() { + // #1512: the circle around the center that touches the circle at 20,20 radius 3, on the side + // it was picked: the near side (radius 7), the far side (13), and through Diameter. + for (script, center, r) in [ + ("CIRCLE 30,20 TAN 23.02,20.03\n", (30.0, 20.0), 7.0), + ("CIRCLE 30,20 TAN 16.98,19.97\n", (30.0, 20.0), 13.0), + ("CIRCLE 20,10 D TAN 20.03,17.02\n", (20.0, 10.0), 7.0), + ] { + let mut s = drawing(); + s.script(script).unwrap(); + assert!(s.running.is_none(), "{script}: {}", s.prompt_text()); + let (c, got) = last_circle(&s); + assert!(near(c, center.0, center.1) && (got - r).abs() < 1e-9, "{script}: {c:?} r={got}"); + } +} + +#[test] +fn tan_for_a_3p_circle_touches_the_picked_circles() { + // #1512: through two points and tangent to the circle at 20,20 radius 3, the tangent pick + // first or last. + for script in ["CIRCLE 3P 26,20 26,26 TAN 23.02,20.03\n", "CIRCLE 3P TAN 23.02,20.03 26,20 26,26\n"] { + let mut s = drawing(); + s.script(script).unwrap(); + assert!(s.running.is_none(), "{script}: {}", s.prompt_text()); + let (c, r) = last_circle(&s); + assert!((c.dist(Vec2::new(26.0, 20.0)) - r).abs() < 1e-9 && (c.dist(Vec2::new(26.0, 26.0)) - r).abs() < 1e-9, "{script}"); + assert!((c.dist(Vec2::new(20.0, 20.0)) - (3.0 + r)).abs() < 1e-9, "{script}: {c:?} r={r}"); + } + // Tan, Tan, Tan: the circle between three circles of radius 1, picked on their inner sides. + let mut s = Session::new(); + s.script("CIRCLE 0,0 1\nCIRCLE 6,0 1\nCIRCLE 3,5 1\nCIRCLE 3P TAN 0.98,0.2 TAN 5.02,0.2 TAN 3.01,3.98\n").unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + let (c, r) = last_circle(&s); + for k in [(0.0, 0.0), (6.0, 0.0), (3.0, 5.0)] { + assert!((c.dist(Vec2::new(k.0, k.1)) - (1.0 + r)).abs() < 1e-9, "{c:?} r={r}"); + } +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index c06e8f242b..aec4911769 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-22 · **Change:** minor (distinct polyline midpoint grips) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (CIRCLE tangent snaps) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) How CADCraft's interaction compares with AutoCAD's: point entry, object snaps, tracking, dynamic input, grips, selection, the command line, chrome and navigation. A drafter's speed in AutoCAD @@ -69,7 +69,7 @@ ignored; there are no context menus. Remaining: **≈ 110–170 Opus 5.5 hours** | Extension | yes, with dashed extension path | yes: rest on a line or arc end, then the line runs on (a ray) and the arc round its circle; dotted path and "Extension: d < a°" (`snap/tracking.rs`); not from ellipse, spline or polyline-arc ends | | Insertion | text, mtext, blocks, attributes, attdefs | TEXT, MTEXT, INSERT; no ATTDEF or MLEADER | | Perpendicular | every curve, deferred | lines, arcs, circles, xlines; deferred for the first point (#168) | -| Tangent | circles, arcs, ellipses, splines, deferred | arcs and circles; deferred for the first point; **no ellipse or spline** | +| Tangent | circles, arcs, ellipses, splines, deferred | arcs and circles; deferred for the first point and for CIRCLE's radius and 3P points (#1512); **no ellipse or spline** | | Nearest | every curve | yes | | Apparent intersection | projected intersection | yes in 2D: where objects near the cursor would meet if extended; an object rested on sends its whole extension, so its crossing with another object snaps too (`snap.rs` `osnap_with`, `snap/tracking.rs`) | | Parallel | yes, with parallel path | yes: rest on a line, then a path parallel to it runs through the base point (`snap/tracking.rs`) | @@ -203,6 +203,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Date | Change | Summary | |---|---|---| +| 2026-10-25 | minor | CIRCLE takes tangent snaps on circles and arcs (#1512): for the radius or diameter, the circle around the center touches the picked curve on the side it was picked; for 3P points, the circle passes through the plain points and touches the picked curves (Tan, Tan, Tan from three tangent picks) | | 2026-10-22 | minor | Polyline segment midpoint grips use rectangles, distinct from square vertex grips, with matching hover and pick bounds (#1950) | | 2026-10-13 | minor | Filled-region highlight boundaries are traversed in deterministic coordinate order, fixing dash-phase jumps on CPU hover/selection redraws and GPU highlight rebuilds; CPU dash-position, pixel and GPU mesh regressions | | 2026-10-14 | minor | Selection cycling (#1143): the list and badge of SELECTIONCYCLING, Shift+Space through overlapping objects (#1145) | From 97fbaf7da40db7c804f0ef245b1a3d5944205015 Mon Sep 17 00:00:00 2001 From: ZachAR3 Date: Sun, 25 Oct 2026 02:14:02 +0100 Subject: [PATCH 02/30] CIRCLE: keep ellipse and spline tangents, and touch an arc within its sweep (#1512) At CIRCLE's deferred prompts only tangents to circles and arcs are deferred; ellipses and splines keep the ordinary tangent from the base, as before. A 3P circle solved for an arc's circle must touch the arc itself: a circle that touches the arc's circle off the sweep is refused with "Circle does not exist." --- crates/engine/src/cmd/draw.rs | 25 ++++++++++++++---------- crates/engine/src/snap.rs | 10 ++++++---- crates/engine/tests/it/snap_curves.rs | 3 +++ crates/engine/tests/it/snap_overrides.rs | 11 +++++++++++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index 9c7e88feec..a1f4f0bed7 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -741,7 +741,7 @@ struct CircleM { mode: u8, // 0 center-radius, 1 = 3P, 2 = 2P, 3 = TTR pts: Vec, /// 3P: the circle or arc each point was picked on with a tangent snap, by point. - tans: Vec>, + tans: Vec>, diameter: bool, /// The `Ttr` option hands over to the tangent-circle machine. delegate: Option>, @@ -834,12 +834,7 @@ impl Interactive for CircleM { } // 3P: a point picked with a tangent snap makes the circle tangent to that curve (#1512). Input::Deferred(d) if self.mode == 1 => { - let tan = match d.curve { - snap::SnapCurve::Circle { center, radius } | snap::SnapCurve::Arc { center, radius, .. } if d.mode == snap::mode::TAN => { - Some(Circle::new(center, radius)) - } - _ => None, - }; + let tan = (d.mode == snap::mode::TAN && !matches!(d.curve, snap::SnapCurve::Line { .. })).then_some(d.curve); self.tans.resize(self.pts.len(), None); self.tans.push(tan); self.input(s, Input::Point(d.at)) @@ -908,9 +903,19 @@ impl CircleM { if self.tans.iter().all(Option::is_none) { return Circle::from_3_points(a, b, c); } - // A plain point is a circle of radius zero to pass through. - let obj = |i: usize, p: Vec2| (super::curves::TanObj::Circle(self.tans.get(i).copied().flatten().unwrap_or(Circle::new(p, 0.0))), p); - super::curves::ttt([obj(0, a), obj(1, b), obj(2, c)]) + let tan = |i: usize| self.tans.get(i).copied().flatten(); + // A plain point is a circle of radius zero to pass through; an arc is solved as its circle. + let target = |i: usize, p: Vec2| { + let circle = match tan(i) { + Some(snap::SnapCurve::Circle { center, radius } | snap::SnapCurve::Arc { center, radius, .. }) => Circle::new(center, radius), + _ => Circle::new(p, 0.0), + }; + super::curves::TanObj::Circle(circle) + }; + let pts = [a, b, c]; + let found = super::curves::ttt([(target(0, a), a), (target(1, b), b), (target(2, c), c)])?; + // The circle must touch an arc within its sweep, not elsewhere on the arc's circle. + pts.iter().enumerate().all(|(i, p)| tan(i).is_none_or(|t| t.contains(target(i, *p).touch(&found)))).then_some(found) } } diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index f739afe0ab..79093e57d8 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -202,9 +202,9 @@ fn prim_segments(p: &Prim) -> Vec { /// Tangent and perpendicular snaps need the base point (the other end of the line). With no /// base and `deferred` set (the prompt says it can resolve them, `Prompt.deferred`), /// they snap as *deferred*: the hit carries the curve and is resolved once the other end is -/// known. With a base and `deferred` set, tangents are deferred too (CIRCLE's radius: the circle -/// around the base that touches the curve, #1512). Deferred hits only win where no other snap -/// does (they are as unspecific as Nearest). +/// known. With a base and `deferred` set, tangents to circles and arcs are deferred too (CIRCLE's +/// radius: the circle around the base that touches the curve, #1512). Deferred hits only win +/// where no other snap does (they are as unspecific as Nearest). pub fn osnap(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Option { if osmode == 0 || osmode & mode::OFF != 0 { return None; @@ -491,8 +491,10 @@ fn finish( _ => {} } } - if osmode & mode::TAN != 0 && !deferred { + if osmode & mode::TAN != 0 { let pts = match p { + // A deferred prompt resolves tangents to circles and arcs itself. + Prim::Seg(Segment::Arc { .. }) | Prim::Circle(_) if deferred => Vec::new(), // Only the tangent points that lie on the arc itself (not its circle). Prim::Seg(Segment::Arc { arc, .. }) => Circle::new(arc.center, arc.radius) .tangent_points(bp) diff --git a/crates/engine/tests/it/snap_curves.rs b/crates/engine/tests/it/snap_curves.rs index e8b9de030a..ec0d0b422b 100644 --- a/crates/engine/tests/it/snap_curves.rs +++ b/crates/engine/tests/it/snap_curves.rs @@ -70,6 +70,9 @@ fn elliptical_arc_perpendicular_and_tangent_from_a_base_point() { let (q, m) = along_quarter(&s, mode::TAN, Some(base)).expect("a tangent point on the arc"); assert_eq!(m, mode::TAN); assert!(on_quarter(q) && Vec2::new(q.x / 16.0, q.y / 4.0).dot(q - base).abs() < 1e-9, "{q:?}"); + // The same tangent at a prompt that resolves deferred snaps (CIRCLE's 3P points, #1512). + let h = snap::osnap(s.doc().unwrap(), &Space::Model, q, 0.3, mode::TAN, Some(base), true).expect("tangent at a deferred prompt"); + assert!(h.mode == mode::TAN && h.deferred.is_none() && h.point.near(q, 1e-9), "{h:?}"); // Perpendicular from (10,10): the line from the base runs along the normal. let base = Vec2::new(10.0, 10.0); let (q, m) = along_quarter(&s, mode::PER, Some(base)).expect("a perpendicular foot on the arc"); diff --git a/crates/engine/tests/it/snap_overrides.rs b/crates/engine/tests/it/snap_overrides.rs index 3d6e0402ce..c015a8f249 100644 --- a/crates/engine/tests/it/snap_overrides.rs +++ b/crates/engine/tests/it/snap_overrides.rs @@ -166,3 +166,14 @@ fn tan_for_a_3p_circle_touches_the_picked_circles() { assert!((c.dist(Vec2::new(k.0, k.1)) - (1.0 + r)).abs() < 1e-9, "{c:?} r={r}"); } } + +#[test] +fn tan_for_a_3p_circle_touches_an_arc_within_its_sweep() { + // #1512: through 26,20 and 26,26, the circles tangent to the circle at 20,20 radius 3 touch it + // on the right or the far left, both off an arc swept from 90° to 100°: no circle. + let mut s = Session::new(); + s.execute("arc", &serde_json::json!({"center": [20, 20], "radius": 3, "start": 90, "end": 100})).unwrap(); + s.script("CIRCLE 3P 26,20 26,26 TAN 19.74,22.99\n").unwrap(); + assert!(s.prompt_text().contains("third point"), "{}", s.prompt_text()); + assert!(!s.doc().unwrap().model.iter().any(|e| matches!(e.kind, EntityKind::Circle(_)))); +} From 98401d6de2efcb90f43bbd8b2a3a16398ac13d18 Mon Sep 17 00:00:00 2001 From: ZachAR3 Date: Sun, 25 Oct 2026 02:47:57 +0100 Subject: [PATCH 03/30] CIRCLE: a 3P circle takes the tangent solution that touches the arc (#1512) The arc check ran on the solver's best circle only, so when that one touched the arc's circle off the sweep, a valid circle that touches the arc was reported as nonexistent. The Tan, Tan, Tan solver now takes a filter (ttt_where), and 3P skips off-arc candidates before choosing. --- crates/engine/src/cmd/curves.rs | 8 ++++++++ crates/engine/src/cmd/draw.rs | 4 ++-- crates/engine/tests/it/snap_overrides.rs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/curves.rs b/crates/engine/src/cmd/curves.rs index 7fe05239df..4340a9f0b0 100644 --- a/crates/engine/src/cmd/curves.rs +++ b/crates/engine/src/cmd/curves.rs @@ -344,6 +344,11 @@ fn eq_variants(o: &TanObj) -> Vec { /// Circle tangent to three objects, nearest the pick points (Newton on all sign combinations). pub fn ttt(objs: [(TanObj, Vec2); 3]) -> Option { + ttt_where(objs, |_| true) +} + +/// [`ttt`] among the circles `ok` accepts. +pub fn ttt_where(objs: [(TanObj, Vec2); 3], ok: impl Fn(&Circle) -> bool) -> Option { let [(o1, p1), (o2, p2), (o3, p3)] = objs; let mut starts: Vec<[f64; 3]> = Vec::new(); let cen = (p1 + p2 + p3) / 3.0; @@ -380,6 +385,9 @@ pub fn ttt(objs: [(TanObj, Vec2); 3]) -> Option { continue; } let c = Circle::new(Vec2::new(x[0], x[1]), x[2]); + if !ok(&c) { + continue; + } let sc = score(&c, &objs); if best.is_none_or(|(b, _)| sc < b - 1e-12) { best = Some((sc, c)); diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index a1f4f0bed7..b11d4fd615 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -913,9 +913,9 @@ impl CircleM { super::curves::TanObj::Circle(circle) }; let pts = [a, b, c]; - let found = super::curves::ttt([(target(0, a), a), (target(1, b), b), (target(2, c), c)])?; // The circle must touch an arc within its sweep, not elsewhere on the arc's circle. - pts.iter().enumerate().all(|(i, p)| tan(i).is_none_or(|t| t.contains(target(i, *p).touch(&found)))).then_some(found) + let on_arcs = |found: &Circle| pts.iter().enumerate().all(|(i, p)| tan(i).is_none_or(|t| t.contains(target(i, *p).touch(found)))); + super::curves::ttt_where([(target(0, a), a), (target(1, b), b), (target(2, c), c)], on_arcs) } } diff --git a/crates/engine/tests/it/snap_overrides.rs b/crates/engine/tests/it/snap_overrides.rs index c015a8f249..8d86baefe7 100644 --- a/crates/engine/tests/it/snap_overrides.rs +++ b/crates/engine/tests/it/snap_overrides.rs @@ -177,3 +177,16 @@ fn tan_for_a_3p_circle_touches_an_arc_within_its_sweep() { assert!(s.prompt_text().contains("third point"), "{}", s.prompt_text()); assert!(!s.doc().unwrap().model.iter().any(|e| matches!(e.kind, EntityKind::Circle(_)))); } + +#[test] +fn tan_for_a_3p_circle_takes_the_solution_that_touches_the_arc() { + // #1512: through 26,20 and 26,26, the circles tangent to the circle at 20,20 radius 3 touch it + // at about 29.6° and -103.3°. Picked at 20° on an arc swept from 200° to 25°, the 29.6° + // circle is nearer the pick but off the arc: the -103.3° one (radius 6.0826) is drawn. + let mut s = Session::new(); + s.execute("arc", &serde_json::json!({"center": [20, 20], "radius": 3, "start": 200, "end": 25})).unwrap(); + s.script("CIRCLE 3P 26,20 26,26 TAN 22.82,21.03\n").unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + let (c, r) = last_circle(&s); + assert!((c.dist(Vec2::new(20.0, 20.0)) - (r - 3.0)).abs() < 1e-9 && (r - 6.082575694955838).abs() < 1e-9, "{c:?} r={r}"); +} From f4f0702d08740e97236b9ce7bb35ff83d24b377e Mon Sep 17 00:00:00 2001 From: ZachAR3 Date: Sun, 25 Oct 2026 03:08:29 +0100 Subject: [PATCH 04/30] CIRCLE: a tangent circle never lies on the picked circle (#1512) A radius picked with TAN around the picked circle's own center, or a 3P circle tangent twice to one circle through a point on it, would only reproduce that circle; both now report that no such circle exists. --- crates/engine/src/cmd/draw.rs | 20 ++++++++++++++++---- crates/engine/tests/it/snap_overrides.rs | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index b11d4fd615..8e25b61942 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -843,7 +843,10 @@ impl Interactive for CircleM { // curve, on the side it was picked (#1512). Input::Deferred(d) if self.mode == 0 && self.pts.len() == 1 => { let Some(&c) = self.pts.first() else { return Ok(Step::Continue) }; - let touch = d.curve.perpendiculars(c, d.at).into_iter().min_by(|a, b| a.dist(d.at).total_cmp(&b.dist(d.at))); + // Around the picked curve's own center the circle would lie on it, not touch it. + let concentric = + matches!(d.curve, snap::SnapCurve::Circle { center, .. } | snap::SnapCurve::Arc { center, .. } if center.near(c, 1e-9)); + let touch = d.curve.perpendiculars(c, d.at).into_iter().filter(|_| !concentric).min_by(|a, b| a.dist(d.at).total_cmp(&b.dist(d.at))); match touch.map(|t| c.dist(t)).filter(|r| *r > 1e-12 && r.is_finite()) { Some(r) => { finish_circle(s, Circle::new(c, r))?; @@ -913,9 +916,18 @@ impl CircleM { super::curves::TanObj::Circle(circle) }; let pts = [a, b, c]; - // The circle must touch an arc within its sweep, not elsewhere on the arc's circle. - let on_arcs = |found: &Circle| pts.iter().enumerate().all(|(i, p)| tan(i).is_none_or(|t| t.contains(target(i, *p).touch(found)))); - super::curves::ttt_where([(target(0, a), a), (target(1, b), b), (target(2, c), c)], on_arcs) + // The circle must touch an arc within its sweep, not elsewhere on the arc's circle, and + // not be the picked circle itself (which lies on it rather than touching it). + let touches = |found: &Circle| { + pts.iter().enumerate().all(|(i, p)| { + tan(i).is_none_or(|t| { + let same = matches!(target(i, *p), super::curves::TanObj::Circle(o) + if o.center.dist(found.center) + (o.radius - found.radius).abs() <= 1e-9 * o.radius); + !same && t.contains(target(i, *p).touch(found)) + }) + }) + }; + super::curves::ttt_where([(target(0, a), a), (target(1, b), b), (target(2, c), c)], touches) } } diff --git a/crates/engine/tests/it/snap_overrides.rs b/crates/engine/tests/it/snap_overrides.rs index 8d86baefe7..51d4639500 100644 --- a/crates/engine/tests/it/snap_overrides.rs +++ b/crates/engine/tests/it/snap_overrides.rs @@ -190,3 +190,23 @@ fn tan_for_a_3p_circle_takes_the_solution_that_touches_the_arc() { let (c, r) = last_circle(&s); assert!((c.dist(Vec2::new(20.0, 20.0)) - (r - 3.0)).abs() < 1e-9 && (r - 6.082575694955838).abs() < 1e-9, "{c:?} r={r}"); } + +#[test] +fn tan_for_a_circle_radius_refuses_the_picked_circles_own_center() { + // #1512: a circle around 20,20 would lie on the circle there, not touch it. + let mut s = drawing(); + s.script("CIRCLE 20,20 TAN 23.02,20.03\n").unwrap(); + assert!(s.prompt_text().contains("radius of circle"), "{}", s.prompt_text()); + assert!(s.log.iter().any(|l| l.contains("No circle around the center is tangent there.")), "{:?}", s.log); + assert_eq!(s.doc().unwrap().model.iter().filter(|e| matches!(e.kind, EntityKind::Circle(_))).count(), 1); +} + +#[test] +fn tan_for_a_3p_circle_refuses_the_picked_circle_itself() { + // #1512: tangent twice to the circle and through a point on it is only the circle itself. + let mut s = drawing(); + s.script("CIRCLE 3P TAN 23.02,20.03 TAN 16.98,20.03 20,23\n").unwrap(); + assert!(s.prompt_text().contains("third point"), "{}", s.prompt_text()); + assert!(s.log.iter().any(|l| l.contains("Circle does not exist.")), "{:?}", s.log); + assert_eq!(s.doc().unwrap().model.iter().filter(|e| matches!(e.kind, EntityKind::Circle(_))).count(), 1); +} From 4a0063f5f6ee046e3694c7741f9b8a838de27b1b Mon Sep 17 00:00:00 2001 From: Francesco BV Date: Tue, 27 Oct 2026 18:31:12 +0100 Subject: [PATCH 05/30] Object snap: Center found by moving onto a circle, arc, ellipse or polyline arc With the default running snaps (OSMODE 4133: END, CEN, INT, EXT) moving the cursor onto a circle, an arc or the middle of a polyline arc found nothing: Center only snapped with the cursor on the center itself. As in AutoCAD, the cursor on a circle, arc, ellipse or polyline arc (also inside block references) now finds its center (snap::curve_centers), scored by how near the curve is so a nearer endpoint or intersection still wins; Tab cycling offers it too. Regression tests open DXF (with $OSMODE 0, which never changes the profile's running snaps) and DWG files and snap on lines, intersections, circles, arcs and polylines. ui-parity: Center row. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/engine/src/snap.rs | 41 ++++-- crates/engine/tests/it/main.rs | 2 + .../engine/tests/it/osnap_opened_drawings.rs | 112 +++++++++++++++++ .../engine/tests/it/snap_center_on_curve.rs | 118 ++++++++++++++++++ docs/ui-parity.md | 5 +- 5 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 crates/engine/tests/it/osnap_opened_drawings.rs create mode 100644 crates/engine/tests/it/snap_center_on_curve.rs diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 956d919c7c..f4082035ad 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -507,14 +507,15 @@ fn finish( } } let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); - let best = cands.iter().filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture).min_by(|a, b| { - // Prefer more specific modes when nearly equidistant. - let da = snap_score(a.0, a.1, cursor, aperture); - let db = snap_score(b.0, b.1, cursor, aperture); - da.total_cmp(&db) - }); - if let Some((m, p)) = best { - return Some(SnapHit { point: *p, mode: *m, name: name_of(*m), viewport: None, deferred: None }); + // Prefer more specific modes when nearly equidistant. + let mut scored: Vec<(f64, u32, Vec2)> = cands + .iter() + .filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture) + .map(|(m, p)| (snap_score(*m, *p, cursor, aperture), *m, *p)) + .collect(); + scored.extend(curve_centers(near_prims, cursor, aperture, osmode).into_iter().filter(|(_, c)| visible(*c)).map(|(d, c)| (d, mode::CEN, c))); + if let Some((_, m, p)) = scored.into_iter().min_by(|a, b| a.0.total_cmp(&b.0)) { + return Some(SnapHit { point: p, mode: m, name: name_of(m), viewport: None, deferred: None }); } if base.is_none() && deferred @@ -546,6 +547,30 @@ fn finish( None } +/// Center, as in AutoCAD: with the cursor over a circle, an arc (also a polyline's) or an +/// ellipse, the running Center snap finds its center however far away it is. Each center comes +/// with how far the curve is from `cursor` (its score), so a nearer endpoint or intersection still +/// wins. Empty unless Center is among `osmode`. +fn curve_centers(prims: &[Prim], cursor: Vec2, aperture: f64, osmode: u32) -> Vec<(f64, Vec2)> { + let mut out = Vec::new(); + if osmode & mode::CEN == 0 { + return out; + } + for p in prims.iter().take(2000) { + let (center, on) = match p { + Prim::Circle(c) => (c.center, c.closest(cursor)), + Prim::Seg(s @ Segment::Arc { arc, .. }) => (arc.center, fix_circle(s).closest(cursor)), + Prim::Ellipse(e) => (e.center, e.closest(cursor)), + _ => continue, + }; + let d = on.dist(cursor); + if center.is_finite() && d.is_finite() && d <= aperture { + out.push((d, center)); + } + } + out +} + fn snap_score(mode: u32, point: Vec2, cursor: Vec2, aperture: f64) -> f64 { point.dist(cursor) - if mode == mode::INT || mode == mode::END { aperture * 0.15 } else { 0.0 } } diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index c4c4a1ce6b..68d5195d2a 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -83,6 +83,7 @@ mod offset_closed_spline; mod offset_ellipse_side; mod offset_move; mod options_profile; +mod osnap_opened_drawings; mod overkill; mod parallel_display_list; mod pedit_splinedit; @@ -117,6 +118,7 @@ mod setvar_coverage; mod shapes; mod snap_annotations; mod snap_blocks; +mod snap_center_on_curve; mod snap_curves; mod snap_intersections_aperture; mod snap_nearest; diff --git a/crates/engine/tests/it/osnap_opened_drawings.rs b/crates/engine/tests/it/osnap_opened_drawings.rs new file mode 100644 index 0000000000..58e80eefe3 --- /dev/null +++ b/crates/engine/tests/it/osnap_opened_drawings.rs @@ -0,0 +1,112 @@ +//! Running object snaps in a fresh drawing and in drawings opened from DXF and DWG files, with +//! AutoCAD's default modes (OSMODE 4133: Endpoint, Center, Intersection, Extension). +//! +//! Moving onto a circle, an arc or a polyline arc finds its Center. OSMODE is a profile setting, +//! as in AutoCAD (saved in the registry there, not the drawing): a file's `$OSMODE` header +//! variable, 0 included, never changes the running snaps. + +use cadcraft_engine::Session; +use cadcraft_engine::doc::Drawing; +use cadcraft_engine::geom::Vec2; +use cadcraft_engine::snap::{mode, tracking::CursorQuery}; +use serde_json::json; + +/// AutoCAD's default running snaps. +const DEFAULT: u32 = 4133; + +fn polar(c: Vec2, r: f64, deg: f64) -> Vec2 { + let a = deg.to_radians(); + c + Vec2::new(r * a.cos(), r * a.sin()) +} + +/// A line crossed by another, a circle, an arc and a polyline with a straight and an arc segment. +fn draw(s: &mut Session) { + s.execute("line", &json!({ "points": [[0, 0], [20, 0]] })).unwrap(); + s.execute("line", &json!({ "points": [[5, -5], [5, 5]] })).unwrap(); + s.execute("circle", &json!({ "center": [50, 0], "radius": 5 })).unwrap(); + s.execute("arc", &json!({ "center": [80, 0], "radius": 5, "start": 0, "end": 180 })).unwrap(); + // 100,0 to 110,0 straight, then a half circle (bulge 1) to 130,0 round 120,0, below the axis. + s.execute("pline", &json!({ "vertices": [[100, 0], {"p": [110, 0], "bulge": 1.0}, [130, 0]] })).unwrap(); +} + +fn drawing() -> Drawing { + let mut s = Session::new(); + draw(&mut s); + s.doc().unwrap().clone() +} + +/// Where a click at `cursor` lands while LINE asks for its first point (the drawing area's path). +fn snap(s: &mut Session, cursor: Vec2) -> Option<(Vec2, u32)> { + if s.running.is_none() { + s.start("line").unwrap(); + } + let q = CursorQuery { base: None, deferred: true, corner: false, aperture: 1.0, tol: 0.5, now: 0.0, shift: false }; + let r = s.snap_cursor(cursor, &q); + r.snap.map(|h| (r.point, h.mode)) +} + +fn assert_snaps(s: &mut Session, what: &str) { + assert_eq!(s.settings.osmode, DEFAULT, "{what}: the running snaps are the profile's"); + let cases = [ + ("the line's end", Vec2::new(20.2, 0.1), Vec2::new(20.0, 0.0), &[mode::END][..]), + ("the lines' crossing", Vec2::new(5.2, 0.15), Vec2::new(5.0, 0.0), &[mode::INT][..]), + ("the circle", polar(Vec2::new(50.0, 0.0), 5.3, 45.0), Vec2::new(50.0, 0.0), &[mode::CEN][..]), + ("the arc", polar(Vec2::new(80.0, 0.0), 5.2, 90.0), Vec2::new(80.0, 0.0), &[mode::CEN][..]), + ("the arc's end", Vec2::new(85.2, 0.1), Vec2::new(85.0, 0.0), &[mode::END][..]), + ("the polyline's vertex", Vec2::new(110.2, 0.1), Vec2::new(110.0, 0.0), &[mode::END][..]), + ("the polyline's arc", polar(Vec2::new(120.0, 0.0), 10.2, 270.0), Vec2::new(120.0, 0.0), &[mode::CEN][..]), + ]; + for (name, cursor, want, modes) in cases { + let (p, m) = snap(s, cursor).unwrap_or_else(|| panic!("{what}: no snap on {name}")); + assert!(modes.contains(&m), "{what}, {name}: mode {m}"); + assert!(p.near(want, 1e-6), "{what}, {name}: {p:?}"); + } + // Away from everything: nothing. + assert_eq!(snap(s, Vec2::new(35.0, 20.0)), None, "{what}"); + // F3 off: nothing; on again: back. + s.execute("osnap", &json!({})).unwrap(); + assert_eq!(snap(s, Vec2::new(20.2, 0.1)), None, "{what}: F3 off"); + s.execute("osnap", &json!({})).unwrap(); + assert_eq!(snap(s, Vec2::new(20.2, 0.1)).map(|h| h.1), Some(mode::END), "{what}: F3 on"); +} + +#[test] +fn default_snaps_work_in_a_fresh_drawing() { + let mut s = Session::new(); + draw(&mut s); + assert_snaps(&mut s, "fresh drawing"); +} + +/// `text` with `$OSMODE` set to `value` at the top of its header. +fn with_osmode(text: &str, value: u32) -> String { + let at = text.find("HEADER").expect("a header section") + "HEADER".len(); + let eol = if text.contains("\r\n") { "\r\n" } else { "\n" }; + let (head, tail) = text.split_at(at); + format!("{head}{eol} 9{eol}$OSMODE{eol} 70{eol}{value}{tail}") +} + +#[test] +fn a_dxf_with_osmode_0_keeps_the_running_snaps() { + let text = String::from_utf8(cadcraft_io::write(&drawing(), "snaps.dxf").unwrap()).unwrap(); + let text = with_osmode(&text, 0); + let d = cadcraft_io::read(text.as_bytes(), "snaps.dxf").unwrap(); + let mut s = Session::new(); + // OSMODE is the profile's: the user's own choice survives opening the file. + s.execute("setvar", &json!({ "name": "OSMODE", "value": DEFAULT })).unwrap(); + s.open_drawing(d, "snaps.dxf", None); + assert_snaps(&mut s, "DXF with $OSMODE 0"); + // Nor does a file change a profile without Center. + let mut s = Session::new(); + s.execute("setvar", &json!({ "name": "OSMODE", "value": mode::END })).unwrap(); + s.open_drawing(cadcraft_io::read(with_osmode(&text, DEFAULT).as_bytes(), "x.dxf").unwrap(), "x.dxf", None); + assert_eq!(s.settings.osmode, mode::END); +} + +#[test] +fn default_snaps_work_in_a_drawing_opened_from_dwg() { + let bytes = cadcraft_io::write(&drawing(), "snaps.dwg").unwrap(); + let d = cadcraft_io::read(&bytes, "snaps.dwg").unwrap(); + let mut s = Session::new(); + s.open_drawing(d, "snaps.dwg", None); + assert_snaps(&mut s, "DWG"); +} diff --git a/crates/engine/tests/it/snap_center_on_curve.rs b/crates/engine/tests/it/snap_center_on_curve.rs new file mode 100644 index 0000000000..51c0bc9231 --- /dev/null +++ b/crates/engine/tests/it/snap_center_on_curve.rs @@ -0,0 +1,118 @@ +//! Center snaps from the curve, as in AutoCAD: with the cursor over a circle, an arc, an +//! ellipse or a polyline arc (also inside a block reference) the running Center snap finds its +//! center, however far away it is. Before, the center was only found with the cursor on the +//! center itself, so moving onto a circle with the default running snaps (END, CEN, INT, EXT) +//! showed nothing. + +use cadcraft_engine::Session; +use cadcraft_engine::doc::{Common, EntityKind, Insert, Space}; +use cadcraft_engine::geom::{Vec2, Vec3}; +use cadcraft_engine::pointmod::snap_candidates; +use cadcraft_engine::snap::{self, mode}; +use serde_json::json; + +/// AutoCAD's default running snaps (OSMODE 4133). +const DEFAULT: u32 = 4133; + +fn snap_at(s: &Session, cursor: Vec2, aperture: f64, osmode: u32) -> Option<(Vec2, u32)> { + snap::osnap(s.doc().unwrap(), &Space::Model, cursor, aperture, osmode, None, false).map(|h| (h.point, h.mode)) +} + +fn polar(c: Vec2, r: f64, deg: f64) -> Vec2 { + let a = deg.to_radians(); + c + Vec2::new(r * a.cos(), r * a.sin()) +} + +#[test] +fn cursor_on_a_circle_snaps_to_its_center() { + let mut s = Session::new(); + s.execute("circle", &json!({ "center": [100, 50], "radius": 20 })).unwrap(); + let c = Vec2::new(100.0, 50.0); + for deg in [10.0, 45.0, 130.0, 250.0, 300.0] { + // A hair off the circle, well inside the aperture; the center is 20 units away. + let cursor = polar(c, 20.3, deg); + let (p, m) = snap_at(&s, cursor, 1.0, DEFAULT).unwrap_or_else(|| panic!("no snap on the circle at {deg}°")); + assert_eq!(m, mode::CEN, "at {deg}°"); + assert!(p.near(c, 1e-9), "at {deg}°: {p:?}"); + } + // Away from the circle (outside the aperture) there is nothing. + assert_eq!(snap_at(&s, polar(c, 23.0, 45.0), 1.0, DEFAULT), None); + // Center off: no center. + assert_eq!(snap_at(&s, polar(c, 20.3, 45.0), 1.0, mode::END), None); + // On the center itself, as before. + assert_eq!(snap_at(&s, c + Vec2::new(0.2, 0.1), 1.0, DEFAULT).map(|h| h.1), Some(mode::CEN)); +} + +#[test] +fn arcs_ellipses_and_polyline_arcs_snap_to_their_centers() { + let mut s = Session::new(); + s.execute("arc", &json!({ "center": [0, 0], "radius": 10, "start": 0, "end": 90 })).unwrap(); + s.execute("ellipse", &json!({ "center": [50, 0], "major": [8, 0], "ratio": 0.5 })).unwrap(); + // A polyline with a half-circle bulge from (100,0) to (120,0): center (110,0), radius 10. + s.execute("pline", &json!({ "vertices": [{"p": [100, 0], "bulge": 1.0}, [120, 0]] })).unwrap(); + let arc = snap_at(&s, polar(Vec2::ZERO, 10.2, 45.0), 1.0, DEFAULT).unwrap(); + assert_eq!(arc.1, mode::CEN); + assert!(arc.0.near(Vec2::ZERO, 1e-9)); + // The arc runs 0°-90°: on its circle at 200° (not on the arc) there is no center. + assert_eq!(snap_at(&s, polar(Vec2::ZERO, 10.2, 200.0), 1.0, DEFAULT), None); + let el = snap_at(&s, Vec2::new(50.0, 4.2), 1.0, DEFAULT).unwrap(); + assert_eq!(el.1, mode::CEN); + assert!(el.0.near(Vec2::new(50.0, 0.0), 1e-9)); + let pl = snap_at(&s, polar(Vec2::new(110.0, 0.0), 10.2, 270.0), 1.0, DEFAULT).unwrap(); + assert_eq!(pl.1, mode::CEN, "the bulge's arc"); + assert!(pl.0.near(Vec2::new(110.0, 0.0), 1e-9), "{:?}", pl.0); +} + +#[test] +fn a_nearer_endpoint_or_intersection_still_wins() { + let mut s = Session::new(); + s.execute("circle", &json!({ "center": [0, 0], "radius": 10 })).unwrap(); + s.execute("line", &json!({ "points": [[10, 0], [30, 0]] })).unwrap(); + // At the line's end on the circle: Endpoint/Intersection, not the far center. + let (p, m) = snap_at(&s, Vec2::new(10.2, 0.1), 1.0, DEFAULT).unwrap(); + assert!(m == mode::END || m == mode::INT, "{m}"); + assert!(p.near(Vec2::new(10.0, 0.0), 1e-9)); +} + +#[test] +fn circles_inside_block_references_snap_to_their_centers() { + let mut s = Session::new(); + let c = s.execute("circle", &json!({ "center": [5, 0], "radius": 2 })).unwrap()["handle"].as_str().unwrap().to_string(); + s.execute("block", &json!({ "name": "H", "base": [0, 0], "handles": [c], "keep": "delete" })).unwrap(); + let kind = EntityKind::Insert(Insert { + block: "H".into(), + insert: Vec3::new(100.0, 100.0, 0.0), + scale: Vec3::new(3.0, 3.0, 1.0), + rotation: 0.0, + attribs: Vec::new(), + cols: 1, + rows: 1, + col_spacing: 0.0, + row_spacing: 0.0, + }); + s.doc_mut().unwrap().add(&Space::Model, Common::default(), kind).unwrap(); + // The circle lands at (115,100) with radius 6. + let (p, m) = snap_at(&s, polar(Vec2::new(115.0, 100.0), 6.2, 60.0), 1.0, DEFAULT).unwrap(); + assert_eq!(m, mode::CEN); + assert!(p.near(Vec2::new(115.0, 100.0), 1e-9), "{p:?}"); +} + +#[test] +fn tab_cycling_offers_the_center_from_the_curve() { + let mut s = Session::new(); + s.execute("circle", &json!({ "center": [0, 0], "radius": 10 })).unwrap(); + let all = snap_candidates(s.doc().unwrap(), &Space::Model, polar(Vec2::ZERO, 10.2, 30.0), 1.0, DEFAULT, None, false); + assert_eq!(all.iter().filter(|h| h.mode == mode::CEN && h.point.near(Vec2::ZERO, 1e-9)).count(), 1, "{all:?}"); +} + +#[test] +fn the_cursor_query_snaps_to_the_center_from_the_curve() { + // The path the drawing area uses (Session::snap_cursor): the point a click would take. + let mut s = Session::new(); + s.execute("circle", &json!({ "center": [0, 0], "radius": 50 })).unwrap(); + s.start("line").unwrap(); + let q = snap::tracking::CursorQuery { base: None, deferred: true, corner: false, aperture: 1.0, tol: 0.5, now: 0.0, shift: false }; + let r = s.snap_cursor(polar(Vec2::ZERO, 50.4, 33.0), &q); + assert_eq!(r.snap.map(|h| h.mode), Some(mode::CEN)); + assert!(r.point.near(Vec2::ZERO, 1e-9), "{:?}", r.point); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index c06e8f242b..7b9c8b79db 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-22 · **Change:** minor (distinct polyline midpoint grips) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-27 · **Change:** minor (Center found from the curve) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) How CADCraft's interaction compares with AutoCAD's: point entry, object snaps, tracking, dynamic input, grips, selection, the command line, chrome and navigation. A drafter's speed in AutoCAD @@ -61,7 +61,7 @@ ignored; there are no context menus. Remaining: **≈ 110–170 Opus 5.5 hours** |---|---|---| | Endpoint | every curve, solid/3D vertices, dimension ends | lines, arcs, polyline segments, open ellipses and splines, ray base, solid/trace corners | | Midpoint | every curve incl. ellipse/spline arcs, polyline segments | segments only; **none on circles, ellipses, splines** | -| Center | arcs, circles, ellipses, polyarcs | arcs, circles, ellipses | +| Center | arcs, circles, ellipses, polyarcs | arcs, circles, ellipses, polyline arcs (also inside block references); found with the cursor on the curve, however far the center is, as in AutoCAD (`snap.rs` `curve_centers`) | | Geometric center | any closed polyline, spline | closed LWPOLYLINE only | | Node | points, dimension definition points, text alignment points | POINT only | | Quadrant | circles, arcs, ellipses | yes | @@ -203,6 +203,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | Center snaps from the curve: with the cursor on a circle, arc, ellipse or polyline arc (in block references too) the running Center snap finds its center, a nearer endpoint or intersection still winning; Tab cycling offers it | | 2026-10-22 | minor | Polyline segment midpoint grips use rectangles, distinct from square vertex grips, with matching hover and pick bounds (#1950) | | 2026-10-13 | minor | Filled-region highlight boundaries are traversed in deterministic coordinate order, fixing dash-phase jumps on CPU hover/selection redraws and GPU highlight rebuilds; CPU dash-position, pixel and GPU mesh regressions | | 2026-10-14 | minor | Selection cycling (#1143): the list and badge of SELECTIONCYCLING, Shift+Space through overlapping objects (#1145) | From 64cb95d8ec61ebf3c5396546178e4a250cd2e6f7 Mon Sep 17 00:00:00 2001 From: Francesco BV Date: Tue, 27 Oct 2026 19:52:14 +0100 Subject: [PATCH 06/30] Tab cycles through every object snap under the aperture, not one per mode (gaps U4) Tab at a point prompt offered only the closest snap of each running mode, so of several line ends under the aperture only one was reachable. The candidate gathering is split out of osnap_in_with_prims (collect_in) and the new snap::osnap_all keeps every candidate: each mode's points of every object nearby, the intersections, perpendicular and tangent points from the base, the deferred snap and the nearest point of each object, in layout viewports too, ranked with the click snap's score (Nearest and deferred last), without repeats and capped at 256. finish and finish_all share base_snaps and nearest_points. pointmod::snap_candidates puts the click snap first, then osnap_all's list. Tests: every endpoint under the aperture is offered; 1,200 endpoints and their crossings give at most 257 finite, unrepeated candidates; NaN or infinite cursors, base points and apertures, zero or negative apertures, OSMODE 0 and the F3 bit give none; with the real pointer Tab visits three line ends and comes back round. gaps: U4 removed. ui-parity: Tab row. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/engine/src/pointmod.rs | 11 +- crates/engine/src/snap.rs | 189 +++++++++++++++----- crates/engine/tests/it/main.rs | 1 + crates/engine/tests/it/snap_tab_cycling.rs | 73 ++++++++ crates/ui-egui/tests/it/main.rs | 1 + crates/ui-egui/tests/it/snap_tab_cycling.rs | 51 ++++++ docs/gaps.md | 4 +- docs/ui-parity.md | 5 +- 8 files changed, 284 insertions(+), 51 deletions(-) create mode 100644 crates/engine/tests/it/snap_tab_cycling.rs create mode 100644 crates/ui-egui/tests/it/snap_tab_cycling.rs diff --git a/crates/engine/src/pointmod.rs b/crates/engine/src/pointmod.rs index 74c1ab0835..e8c4033eca 100644 --- a/crates/engine/src/pointmod.rs +++ b/crates/engine/src/pointmod.rs @@ -120,17 +120,14 @@ pub fn snap_name(m: u32) -> &'static str { } /// The candidate snaps near `cursor` for Tab cycling: the snap [`crate::snap::osnap`] picks -/// first, then the closest snap of each other mode in `osmode`, nearest first, without repeats. +/// first, then every other snap of the modes in `osmode` under the aperture (each endpoint of +/// each object, each intersection …; [`crate::snap::osnap_all`]), best first, without repeats. pub fn snap_candidates(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Vec { if osmode & !mode::HATCH == 0 || osmode & mode::OFF != 0 { return Vec::new(); } - let osnap = |m: u32| crate::snap::osnap(d, space, cursor, aperture, m, base, deferred); - let extra = osmode & mode::HATCH; - let mut per_mode: Vec = mode::ALL.iter().filter(|(b, _)| osmode & b != 0).filter_map(|(b, _)| osnap(*b | extra)).collect(); - per_mode.sort_by(|a, b| a.point.dist(cursor).total_cmp(&b.point.dist(cursor))); - let mut out: Vec = osnap(osmode).into_iter().collect(); - for h in per_mode { + let mut out: Vec = crate::snap::osnap(d, space, cursor, aperture, osmode, base, deferred).into_iter().collect(); + for h in crate::snap::osnap_all(d, space, cursor, aperture, osmode, base, deferred) { if !out.iter().any(|o| o.mode == h.mode && o.point.near(h.point, aperture * 1e-6)) { out.push(h); } diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 956d919c7c..d390efa70a 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -308,6 +308,72 @@ fn osnap_in_with_prims( frozen: &[String], clip: Option, ) -> Option<(Option, Vec)> { + let (cands, near_prims) = collect_in(d, space, ix, cursor, aperture, osmode, frozen)?; + let hit = finish(cands, &near_prims, cursor, aperture, osmode, base, deferred, clip); + Some((hit, near_prims)) +} + +/// Every snap of `osmode` under the aperture round `cursor`, best first: Tab cycles through +/// these. Each mode's points of every object nearby, the intersections, perpendicular and +/// tangent points from `base`, the deferred snaps and the nearest point of each object, without +/// repeats and at most [`MAX_CYCLE`]; in viewports too, as [`osnap`] snaps. +pub fn osnap_all(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Vec { + if osmode == 0 || osmode & mode::OFF != 0 || !cursor.is_finite() || !(aperture.is_finite() && aperture > 0.0) { + return Vec::new(); + } + let ix = crate::spatial::index(d, space); + let mut out: Vec = Vec::new(); + if let Some((cands, prims)) = collect_in(d, space, &ix, cursor, aperture, osmode, &[]) { + out = finish_all(cands, &prims, cursor, aperture, osmode, base, deferred, None); + } + let model = Space::Model; + let views = viewport::near(d, space, cursor, aperture); + if !views.is_empty() { + let model_ix = crate::spatial::index(d, &model); + for view in views { + let (mc, ma, mb) = (view.to_model(cursor), aperture / view.scale, base.map(|p| view.to_model(p))); + if !mc.is_finite() || !(ma.is_finite() && ma > 0.0) || mb.is_some_and(|p| !p.is_finite()) { + continue; + } + let Some((cands, prims)) = collect_in(d, &model, &model_ix, mc, ma, osmode, &view.viewport.frozen_layers) else { continue }; + out.extend(finish_all(cands, &prims, mc, ma, osmode, mb, deferred, Some(view.model_clip)).into_iter().filter_map(|h| view.hit(h))); + } + } + out.sort_by(|a, b| rank(a, cursor, aperture).total_cmp(&rank(b, cursor, aperture))); + let mut unique: Vec = Vec::with_capacity(out.len().min(MAX_CYCLE)); + for h in out { + if unique.len() >= MAX_CYCLE { + break; + } + if !unique.iter().any(|u| u.mode == h.mode && u.point.near(h.point, aperture * 1e-6)) { + unique.push(h); + } + } + unique +} + +/// Most snaps [`osnap_all`] offers. +const MAX_CYCLE: usize = 256; + +/// Where a snap ranks among [`osnap_all`]'s: by [`snap_score`], the unspecific ones (Nearest, +/// deferred) after every other. +fn rank(h: &SnapHit, cursor: Vec2, aperture: f64) -> f64 { + let vague = h.mode == mode::NEA || h.deferred.is_some(); + snap_score(h.mode, h.point, cursor, aperture) + if vague { aperture * 4.0 } else { 0.0 } +} + +/// The candidate snap points near `cursor` (each with its mode) and the primitives near it: +/// [`gather_in`]'s, plus the intersections between those primitives. +#[allow(clippy::too_many_arguments)] +fn collect_in( + d: &Drawing, + space: &Space, + ix: &Option>, + cursor: Vec2, + aperture: f64, + osmode: u32, + frozen: &[String], +) -> Option<(Vec<(u32, Vec2)>, Vec)> { let (mut cands, near_prims) = gather_in(d, space, ix, cursor, aperture, osmode, frozen)?; // Intersections between nearby primitives; Apparent Intersection also where their extensions // meet (lines extended, arcs as full circles: in 2D, the "apparent" crossing of objects @@ -345,8 +411,7 @@ fn osnap_in_with_prims( } } } - let hit = finish(cands, &near_prims, cursor, aperture, osmode, base, deferred, clip); - Some((hit, near_prims)) + Some((cands, near_prims)) } fn finite_intersection_probe(cursor: Vec2, aperture: f64) -> Option { @@ -470,6 +535,88 @@ fn finish( deferred: bool, clip: Option, ) -> Option { + base_snaps(&mut cands, near_prims, osmode, base); + let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); + let best = cands.iter().filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture).min_by(|a, b| { + // Prefer more specific modes when nearly equidistant. + let da = snap_score(a.0, a.1, cursor, aperture); + let db = snap_score(b.0, b.1, cursor, aperture); + da.total_cmp(&db) + }); + if let Some((m, p)) = best { + return Some(SnapHit { point: *p, mode: *m, name: name_of(*m), viewport: None, deferred: None }); + } + if base.is_none() + && deferred + && let Some(h) = deferred_hit(near_prims, cursor, aperture, osmode, clip) + { + return Some(h); + } + if osmode & mode::NEA != 0 { + // The closest point of all nearby objects, whatever their drawing order. + let nb = nearest_points(near_prims, cursor, aperture, clip).into_iter().min_by(|a, b| a.dist(cursor).total_cmp(&b.dist(cursor))); + if let Some(p) = nb { + return Some(SnapHit { point: p, mode: mode::NEA, name: "Nearest", viewport: None, deferred: None }); + } + } + None +} + +/// [`finish`], keeping every candidate: the specific snaps best first, then the deferred snap, +/// then the nearest point of each object nearby. +#[allow(clippy::too_many_arguments)] +fn finish_all( + mut cands: Vec<(u32, Vec2)>, + near_prims: &[Prim], + cursor: Vec2, + aperture: f64, + osmode: u32, + base: Option, + deferred: bool, + clip: Option, +) -> Vec { + base_snaps(&mut cands, near_prims, osmode, base); + let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); + let mut scored: Vec<(f64, u32, Vec2)> = cands + .iter() + .filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture) + .map(|(m, p)| (snap_score(*m, *p, cursor, aperture), *m, *p)) + .collect(); + scored.sort_by(|a, b| a.0.total_cmp(&b.0)); + let mut out: Vec = + scored.into_iter().map(|(_, m, p)| SnapHit { point: p, mode: m, name: name_of(m), viewport: None, deferred: None }).collect(); + if base.is_none() + && deferred + && let Some(h) = deferred_hit(near_prims, cursor, aperture, osmode, clip) + { + out.push(h); + } + if osmode & mode::NEA != 0 { + let mut near = nearest_points(near_prims, cursor, aperture, clip); + near.sort_by(|a, b| a.dist(cursor).total_cmp(&b.dist(cursor))); + out.extend(near.into_iter().map(|p| SnapHit { point: p, mode: mode::NEA, name: "Nearest", viewport: None, deferred: None })); + } + out +} + +/// The point of each nearby primitive closest to `cursor`, within the aperture. +fn nearest_points(near_prims: &[Prim], cursor: Vec2, aperture: f64, clip: Option) -> Vec { + let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); + let mut out = Vec::new(); + for p in near_prims { + let c = match p { + Prim::Circle(c) => Some(c.closest(cursor)), + _ => prim_segments(p).iter().map(|s| fix_circle(s).closest(cursor)).min_by(|a, b| a.dist(cursor).total_cmp(&b.dist(cursor))), + }; + if let Some(c) = c.filter(|c| visible(*c) && c.dist(cursor) <= aperture) { + out.push(c); + } + } + out +} + +/// Add the perpendicular and tangent points from the base point `base`. +fn base_snaps(cands: &mut Vec<(u32, Vec2)>, near_prims: &[Prim], osmode: u32, base: Option) { // Perpendicular / tangent from the base point. if let Some(bp) = base { for p in near_prims { @@ -506,44 +653,6 @@ fn finish( } } } - let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); - let best = cands.iter().filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture).min_by(|a, b| { - // Prefer more specific modes when nearly equidistant. - let da = snap_score(a.0, a.1, cursor, aperture); - let db = snap_score(b.0, b.1, cursor, aperture); - da.total_cmp(&db) - }); - if let Some((m, p)) = best { - return Some(SnapHit { point: *p, mode: *m, name: name_of(*m), viewport: None, deferred: None }); - } - if base.is_none() - && deferred - && let Some(h) = deferred_hit(near_prims, cursor, aperture, osmode, clip) - { - return Some(h); - } - if osmode & mode::NEA != 0 { - // The closest point of all nearby objects, whatever their drawing order. - let mut nb: Option<(f64, Vec2)> = None; - let mut consider = |c: Vec2| { - let dd = c.dist(cursor); - if visible(c) && dd <= aperture && nb.is_none_or(|(bd, _)| dd < bd) { - nb = Some((dd, c)); - } - }; - for p in near_prims { - for s in prim_segments(p) { - consider(fix_circle(&s).closest(cursor)); - } - if let Prim::Circle(c) = p { - consider(c.closest(cursor)); - } - } - if let Some((_, p)) = nb { - return Some(SnapHit { point: p, mode: mode::NEA, name: "Nearest", viewport: None, deferred: None }); - } - } - None } fn snap_score(mode: u32, point: Vec2, cursor: Vec2, aperture: f64) -> f64 { diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index c4c4a1ce6b..52f93e685a 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -121,6 +121,7 @@ mod snap_curves; mod snap_intersections_aperture; mod snap_nearest; mod snap_overrides; +mod snap_tab_cycling; mod snap_tracking; mod snaps_more; mod space_is_enter; diff --git a/crates/engine/tests/it/snap_tab_cycling.rs b/crates/engine/tests/it/snap_tab_cycling.rs new file mode 100644 index 0000000000..45a21efea1 --- /dev/null +++ b/crates/engine/tests/it/snap_tab_cycling.rs @@ -0,0 +1,73 @@ +//! Tab cycling through object snaps: a crowd of candidates is capped, hostile cursors and +//! apertures give no candidates, and the list never repeats a snap. + +use cadcraft_engine::Session; +use cadcraft_engine::doc::Space; +use cadcraft_engine::geom::Vec2; +use cadcraft_engine::pointmod::snap_candidates; +use cadcraft_engine::snap::mode; +use serde_json::json; + +#[test] +fn a_crowd_of_snaps_is_capped_and_never_repeats() { + let mut s = Session::new(); + // 600 short lines fanning out from points packed round the origin: 1,200 endpoints. + for i in 0..600 { + let a = f64::from(i) * 0.01; + let p = [1e-3 * a.cos(), 1e-3 * a.sin()]; + s.execute("line", &json!({ "points": [p, [a.cos(), a.sin()]] })).unwrap(); + } + let d = s.doc().unwrap(); + let cands = snap_candidates(d, &Space::Model, Vec2::ZERO, 0.5, mode::END | mode::INT | mode::NEA, None, false); + assert!(!cands.is_empty()); + assert!(cands.len() <= 257, "{} candidates", cands.len()); + for (i, a) in cands.iter().enumerate() { + assert!(a.point.is_finite()); + assert!(!cands.iter().skip(i + 1).any(|b| b.mode == a.mode && b.point == a.point), "{a:?} repeats"); + } +} + +#[test] +fn hostile_cursor_and_aperture_give_no_candidates() { + let mut s = Session::new(); + s.execute("line", &json!({ "points": [[0, 0], [10, 0]] })).unwrap(); + let d = s.doc().unwrap(); + let space = Space::Model; + let all = mode::END | mode::MID | mode::INT | mode::NEA | mode::PER; + for (c, ap) in [ + (Vec2::new(f64::NAN, 0.0), 0.5), + (Vec2::new(0.0, f64::INFINITY), 0.5), + (Vec2::ZERO, f64::NAN), + (Vec2::ZERO, 0.0), + (Vec2::ZERO, -1.0), + (Vec2::ZERO, f64::INFINITY), + ] { + assert!(snap_candidates(d, &space, c, ap, all, None, false).is_empty(), "{c:?} {ap}"); + assert!(snap_candidates(d, &space, c, ap, all, Some(Vec2::new(f64::NAN, 1.0)), true).is_empty(), "{c:?} {ap}"); + } + // A huge but finite aperture still answers, from the objects there are. + let far = snap_candidates(d, &space, Vec2::ZERO, 1e300, mode::END, None, false); + assert!(far.iter().all(|h| h.point.is_finite())); + // Object snaps off (or only the OFF bit) offer nothing. + assert!(snap_candidates(d, &space, Vec2::ZERO, 0.5, 0, None, false).is_empty()); + assert!(snap_candidates(d, &space, Vec2::ZERO, 0.5, mode::END | mode::OFF, None, false).is_empty()); +} + +#[test] +fn every_endpoint_under_the_aperture_is_offered_not_one_per_mode() { + let mut s = Session::new(); + // Three line ends close together, all within the aperture of the cursor between them. + for (a, b) in [([0.0, 0.0], [10.0, 0.0]), ([0.06, 0.05], [0.06, 10.0]), ([0.03, -0.06], [-10.0, -10.0])] { + s.execute("line", &json!({ "points": [a, b] })).unwrap(); + } + let d = s.doc().unwrap(); + let cands = snap_candidates(d, &Space::Model, Vec2::new(0.03, 0.0), 0.125, mode::END, None, false); + let ends: Vec = cands.iter().filter(|h| h.mode == mode::END).map(|h| h.point).collect(); + assert_eq!(ends.len(), 3, "{cands:?}"); + for want in [Vec2::new(0.0, 0.0), Vec2::new(0.06, 0.05), Vec2::new(0.03, -0.06)] { + assert!(ends.iter().any(|p| p.near(want, 1e-12)), "{want:?} in {ends:?}"); + } + // The first is the snap a click would take. + let first = snap_candidates(d, &Space::Model, Vec2::new(0.03, 0.0), 0.125, mode::END, None, false).first().map(|h| h.point); + assert_eq!(first, cadcraft_engine::snap::osnap(d, &Space::Model, Vec2::new(0.03, 0.0), 0.125, mode::END, None, false).map(|h| h.point)); +} diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index c32012e1ab..d4871d6de5 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -29,6 +29,7 @@ mod rapid_clicks; mod selection_cycling; mod shared_controls; mod shortcut_menus; +mod snap_tab_cycling; mod status_bar_toggles; mod style_dialogs; mod system_cursor; diff --git a/crates/ui-egui/tests/it/snap_tab_cycling.rs b/crates/ui-egui/tests/it/snap_tab_cycling.rs new file mode 100644 index 0000000000..c7b4cd290f --- /dev/null +++ b/crates/ui-egui/tests/it/snap_tab_cycling.rs @@ -0,0 +1,51 @@ +//! Tab at a point prompt steps through every object snap under the aperture (each endpoint of +//! each object nearby), not just the closest snap of each running mode, and comes back round. + +use cadcraft_engine::Session; +use cadcraft_geom::Vec2; +use cadcraft_ui_egui::{CadApp, Services}; +use egui::{Event, vec2}; +use egui_kittest::Harness; +use serde_json::json; + +#[test] +fn tab_cycles_through_every_endpoint_under_the_aperture() { + let mut s = Session::new(); + // Three line ends close together (within the aperture of the cursor between them). + for (a, b) in [([0.0, 0.0], [10.0, 0.0]), ([0.06, 0.05], [0.06, 10.0]), ([0.03, -0.06], [-10.0, -10.0])] { + s.execute("line", &json!({ "points": [a, b] })).unwrap(); + } + s.execute("setvar", &json!({ "name": "OSMODE", "value": 1 })).unwrap(); + s.execute("view.set", &json!({ "center": [0, 0], "height": 20 })).unwrap(); + let mut app = CadApp::new(s, Services::default()); + app.canvas.zoom_pending = false; + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + |ui, app: &mut CadApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + app, + ); + h.run_steps(3); + h.state_mut().session.start("line").unwrap(); + h.run_steps(2); + let xf = h.state().canvas.xf.unwrap(); + let at = xf.to_screen(Vec2::new(0.03, 0.0)); + h.event(Event::PointerMoved(at)); + h.run_steps(2); + let mut seen: Vec = Vec::new(); + for i in 0..4 { + let p = h.state().canvas.snap.map(|s| s.point).unwrap(); + if i < 3 { + assert!(!seen.iter().any(|q| q.near(p, 1e-9)), "Tab {i} repeats {p:?} ({seen:?})"); + } else { + assert!(seen.first().is_some_and(|q| q.near(p, 1e-9)), "the fourth Tab comes back round"); + } + seen.push(p); + h.event(Event::Text("\t".into())); + h.run_steps(2); + } + for want in [Vec2::new(0.0, 0.0), Vec2::new(0.06, 0.05), Vec2::new(0.03, -0.06)] { + assert!(seen.iter().any(|q| q.near(want, 1e-9)), "{want:?} in {seen:?}"); + } +} diff --git a/docs/gaps.md b/docs/gaps.md index 9c0bf3630f..3fb8add71f 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Where CADCraft falls short of AutoCAD -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (Named Viewports dialog: U11 narrowed; MVIEW Restore and PURGE of multiline styles had landed: F15 and F21 corrected) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-27 · **Change:** minor (Tab snap cycling offers every candidate: U4 closed) · **Target:** Autodesk AutoCAD 2027 Every known shortfall, one row each, ranked within each section by user impact. This is the work list: agents pick from here (top of a section first), and remove or update a row in the same PR @@ -58,7 +58,6 @@ Options ▸ Selection can now require two separate clicks for a selection window or allow clicks and drag (2, default), saved in the user profile. Drag-only mode (1) remains unavailable. | # | Gap | User impact | Est. | |---|---|---|---| -| U4 | Tab snap cycling offers the closest snap of each mode, not every candidate. Typed snap overrides (`END`, `MID` … `NON`), the Shift/Ctrl+right-click snap menu and Tab cycling landed (#393), the menu's Temporary track point in #441 | Low | 1 | | U5 | Grip menus open on right-click only (no hover menu, no Ctrl to cycle the options); no multifunctional grips on dimensions, MLEADER, hatches or text; Add Vertex on an arc segment straightens it. Hot-grip options (Base point, Copy, Undo, Reference, eXit), multiple hot grips and the polyline/line/arc grip menus landed (#425) | Low-medium | 2–4 | | U6 | Selection: lasso; the CLass keyword; isolation saved with the drawing (OBJECTISOLATIONMODE 1) and the status-bar isolate button. Press-drag windows (#63), the W, C, F, WP and CP keywords (#226), BOX, AUto, SIngle, Multiple, Group, Add, Remove and Undo, SELECTSIMILAR, ISOLATEOBJECTS/HIDEOBJECTS/UNISOLATEOBJECTS (#428) and selection cycling (#1143) landed | Medium | 3–5 | | U7 | Right-click menus: no in-place layout tab rename or Move or Copy dialog, no Select All Layouts, no Paste to command line; palette menus are on the Layers rows and the Properties background only. The command menu (held right-click: Enter, Cancel, Recent Input, options, Snap Overrides, Pan/Zoom), the selection menu with object edits, command line, drawing tab, layout tab and palette menus landed (#512) | Low | 1–2 | @@ -150,6 +149,7 @@ Detail: [localization-parity.md](localization-parity.md). | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | Tab snap cycling steps through every snap of the running modes under the aperture (each endpoint, intersection … of each object nearby, at most 256), not one per mode: U4 closed | | 2026-10-25 | minor | Named Viewports (View ▸ Viewports ▸ Named Viewports..., `vports.named`) lists the saved viewport configurations with a preview and the current one's name, and restores or deletes one; in a layout Restore places it as MVIEW Restore does: U11 narrowed. F15 and U11 no longer list MVIEW Restore (#633), and F21 no longer says PURGE skips multiline styles | | 2026-10-25 | minor | DIMTFILL limits: with DIMTFILL 1 (the drawing's background color) the written `*D` block and EXPLODE keep no background mask (a WIPEOUT over the text box would), and a true-color DIMTFILLCLR is written to DXF as the nearest ACI: F7 updated | | 2026-10-24 | minor | COMPAREEXPORT (typed, or Export on the comparison bar) opens the comparison as a new untitled drawing, `compare_ vs .dwg`: this drawing's objects in one group and the other drawing's differing objects in a second group, in the comparison colors (green, red, gray for objects in both), block contents and style colors included: F22 narrowed | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index c06e8f242b..dbc20528c2 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-22 · **Change:** minor (distinct polyline midpoint grips) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-27 · **Change:** minor (Tab cycles every candidate snap) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) How CADCraft's interaction compares with AutoCAD's: point entry, object snaps, tracking, dynamic input, grips, selection, the command line, chrome and navigation. A drafter's speed in AutoCAD @@ -75,7 +75,7 @@ ignored; there are no context menus. Remaining: **≈ 110–170 Opus 5.5 hours** | Parallel | yes, with parallel path | yes: rest on a line, then a path parallel to it runs through the base point (`snap/tracking.rs`) | | Temporary overrides typed at a prompt (`END`, `MID`, `INT` …) | yes | **no**: the text arrives as plain input | | Shift/Ctrl+right-click snap menu | yes | yes: From, Mid Between 2 Points, Point Filters, the snap modes, None, Osnap Settings; no Temporary track point yet (`context_menu.rs`) | -| Tab to cycle candidate snaps | yes | yes, through the closest snap of each running mode under the cursor (`pointmod::snap_candidates`) | +| Tab to cycle candidate snaps | yes | yes, through every snap of the running modes under the aperture: each endpoint, midpoint, intersection … of each object nearby, best first, at most 256 (`snap::osnap_all` via `pointmod::snap_candidates`) | | AutoSnap marker, tooltip, magnet, aperture box | yes | marker per mode and name label; aperture from APERTURE; no magnet, no aperture box | | OSNAPZ, 3D object snaps | yes | no | @@ -203,6 +203,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | Tab cycles through every snap under the aperture, not the closest of each mode (gaps U4) | | 2026-10-22 | minor | Polyline segment midpoint grips use rectangles, distinct from square vertex grips, with matching hover and pick bounds (#1950) | | 2026-10-13 | minor | Filled-region highlight boundaries are traversed in deterministic coordinate order, fixing dash-phase jumps on CPU hover/selection redraws and GPU highlight rebuilds; CPU dash-position, pixel and GPU mesh regressions | | 2026-10-14 | minor | Selection cycling (#1143): the list and badge of SELECTIONCYCLING, Shift+Space through overlapping objects (#1145) | From 55ec024e31823b6e77157c56acfd132ce1311281 Mon Sep 17 00:00:00 2001 From: Francesco BV Date: Thu, 29 Oct 2026 08:52:22 +0100 Subject: [PATCH 07/30] Object snap: the center from the curve ranks behind snap points A center found from its curve was scored by the cursor's distance to the curve, so it beat the Midpoint or Quadrant of the same curve under the cursor (those lie on the curve), and they could only be picked with Tab. Now finish() tries the curve centers only when no snap point is in the aperture, as in AutoCAD: Endpoint, Midpoint, Quadrant and Intersection under the cursor win, the center shows elsewhere on the curve. Hits from layout viewports are compared with paper-space ones by the same rank (tier, then the score scaled into paper units), so a center keeps its curve distance there instead of being rescored by the distance to the center point. The 2,000-item work limit counts circles, arcs and ellipses only, so straight segments gathered before them can't hide them. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/engine/src/snap.rs | 79 ++++++++++++------ .../engine/tests/it/snap_center_on_curve.rs | 82 +++++++++++++++++++ docs/ui-parity.md | 4 +- 3 files changed, 136 insertions(+), 29 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index f4082035ad..973e021712 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -246,7 +246,7 @@ pub(crate) fn osnap_with_neighborhood( }; let views = viewport::near(d, space, cursor, aperture); if views.is_empty() { - return (best, near_prims); + return (best.map(|(h, _)| h), near_prims); } let model = Space::Model; let model_ix = crate::spatial::index(d, &model); @@ -269,14 +269,30 @@ pub(crate) fn osnap_with_neighborhood( &view.viewport.frozen_layers, Some(view.model_clip), ) - .and_then(|h| view.hit(h)); - if let Some(hit) = hit - && best.as_ref().is_none_or(|b| snap_score(hit.mode, hit.point, cursor, aperture) < snap_score(b.mode, b.point, cursor, aperture)) + // The rank was found in model units: paper units are model units times the scale. + .and_then(|(h, r)| Some((view.hit(h)?, Rank { score: r.score * view.scale, ..r }))); + if let Some((hit, rank)) = hit + && best.as_ref().is_none_or(|(_, b)| rank.beats(b)) { - best = Some(hit); + best = Some((hit, rank)); } } - (best, near_prims) + (best.map(|(h, _)| h), near_prims) +} + +/// How a hit ranks against the hits of another space (paper space, another viewport): first the +/// order [`finish`] tries them in (snap points, then a center found from its curve, then +/// deferred snaps and Nearest), then its score within that tier, in the units of the cursor. +#[derive(Clone, Copy, Debug)] +struct Rank { + tier: u8, + score: f64, +} + +impl Rank { + fn beats(&self, other: &Rank) -> bool { + self.tier.cmp(&other.tier).then(self.score.total_cmp(&other.score)).is_lt() + } } #[allow(clippy::too_many_arguments)] @@ -291,7 +307,7 @@ fn osnap_in( deferred: bool, frozen: &[String], clip: Option, -) -> Option { +) -> Option<(SnapHit, Rank)> { osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, frozen, clip).and_then(|(hit, _)| hit) } @@ -307,7 +323,7 @@ fn osnap_in_with_prims( deferred: bool, frozen: &[String], clip: Option, -) -> Option<(Option, Vec)> { +) -> Option<(Option<(SnapHit, Rank)>, Vec)> { let (mut cands, near_prims) = gather_in(d, space, ix, cursor, aperture, osmode, frozen)?; // Intersections between nearby primitives; Apparent Intersection also where their extensions // meet (lines extended, arcs as full circles: in 2D, the "apparent" crossing of objects @@ -458,7 +474,8 @@ fn gather_in( Some((cands, near_prims)) } -/// Picks the best of the gathered candidates, adding the base-dependent and deferred snaps. +/// Picks the best of the gathered candidates, adding the base-dependent and deferred snaps, with +/// its [`Rank`]. #[allow(clippy::too_many_arguments)] fn finish( mut cands: Vec<(u32, Vec2)>, @@ -469,7 +486,7 @@ fn finish( base: Option, deferred: bool, clip: Option, -) -> Option { +) -> Option<(SnapHit, Rank)> { // Perpendicular / tangent from the base point. if let Some(bp) = base { for p in near_prims { @@ -507,21 +524,28 @@ fn finish( } } let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); + let hit = |point: Vec2, m: u32| SnapHit { point, mode: m, name: name_of(m), viewport: None, deferred: None }; // Prefer more specific modes when nearly equidistant. - let mut scored: Vec<(f64, u32, Vec2)> = cands + let best = cands .iter() .filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture) .map(|(m, p)| (snap_score(*m, *p, cursor, aperture), *m, *p)) - .collect(); - scored.extend(curve_centers(near_prims, cursor, aperture, osmode).into_iter().filter(|(_, c)| visible(*c)).map(|(d, c)| (d, mode::CEN, c))); - if let Some((_, m, p)) = scored.into_iter().min_by(|a, b| a.0.total_cmp(&b.0)) { - return Some(SnapHit { point: p, mode: m, name: name_of(m), viewport: None, deferred: None }); + .min_by(|a, b| a.0.total_cmp(&b.0)); + if let Some((score, m, p)) = best { + return Some((hit(p, m), Rank { tier: 0, score })); + } + // A center found from its curve only when no snap point is in the aperture: the Midpoint or + // Quadrant under the cursor wins over the center of the same curve, as in AutoCAD. + let center = curve_centers(near_prims, cursor, aperture, osmode).into_iter().filter(|(_, c)| visible(*c)).min_by(|a, b| a.0.total_cmp(&b.0)); + if let Some((score, c)) = center { + return Some((hit(c, mode::CEN), Rank { tier: 1, score })); } if base.is_none() && deferred && let Some(h) = deferred_hit(near_prims, cursor, aperture, osmode, clip) { - return Some(h); + let score = h.point.dist(cursor); + return Some((h, Rank { tier: 2, score })); } if osmode & mode::NEA != 0 { // The closest point of all nearby objects, whatever their drawing order. @@ -540,8 +564,8 @@ fn finish( consider(c.closest(cursor)); } } - if let Some((_, p)) = nb { - return Some(SnapHit { point: p, mode: mode::NEA, name: "Nearest", viewport: None, deferred: None }); + if let Some((score, p)) = nb { + return Some((SnapHit { point: p, mode: mode::NEA, name: "Nearest", viewport: None, deferred: None }, Rank { tier: 2, score })); } } None @@ -549,20 +573,21 @@ fn finish( /// Center, as in AutoCAD: with the cursor over a circle, an arc (also a polyline's) or an /// ellipse, the running Center snap finds its center however far away it is. Each center comes -/// with how far the curve is from `cursor` (its score), so a nearer endpoint or intersection still -/// wins. Empty unless Center is among `osmode`. +/// with how far the curve is from `cursor` (its score); [`finish`] tries them only when no snap +/// point is in the aperture. Empty unless Center is among `osmode`. fn curve_centers(prims: &[Prim], cursor: Vec2, aperture: f64, osmode: u32) -> Vec<(f64, Vec2)> { let mut out = Vec::new(); if osmode & mode::CEN == 0 { return out; } - for p in prims.iter().take(2000) { - let (center, on) = match p { - Prim::Circle(c) => (c.center, c.closest(cursor)), - Prim::Seg(s @ Segment::Arc { arc, .. }) => (arc.center, fix_circle(s).closest(cursor)), - Prim::Ellipse(e) => (e.center, e.closest(cursor)), - _ => continue, - }; + // The work limit counts the curves only, so straight segments before them can't hide them. + let curves = prims.iter().filter_map(|p| match p { + Prim::Circle(c) => Some((c.center, c.closest(cursor))), + Prim::Seg(s @ Segment::Arc { arc, .. }) => Some((arc.center, fix_circle(s).closest(cursor))), + Prim::Ellipse(e) => Some((e.center, e.closest(cursor))), + _ => None, + }); + for (center, on) in curves.take(2000) { let d = on.dist(cursor); if center.is_finite() && d.is_finite() && d <= aperture { out.push((d, center)); diff --git a/crates/engine/tests/it/snap_center_on_curve.rs b/crates/engine/tests/it/snap_center_on_curve.rs index 51c0bc9231..20a3c24106 100644 --- a/crates/engine/tests/it/snap_center_on_curve.rs +++ b/crates/engine/tests/it/snap_center_on_curve.rs @@ -116,3 +116,85 @@ fn the_cursor_query_snaps_to_the_center_from_the_curve() { assert_eq!(r.snap.map(|h| h.mode), Some(mode::CEN)); assert!(r.point.near(Vec2::ZERO, 1e-9), "{:?}", r.point); } + +/// The arc of the review of #2347 (and #1114's test): center (100,50), radius 80, 30°-150°. +fn review_arc() -> Session { + let mut s = Session::new(); + s.execute("arc", &json!({ "center": [100, 50], "radius": 80, "start": 30, "end": 150 })).unwrap(); + s +} + +#[test] +fn a_midpoint_under_the_cursor_beats_the_center_from_the_curve() { + let s = review_arc(); + // On the arc's midpoint (100,130) with Center and Midpoint running: Midpoint, as in AutoCAD. + for cursor in [Vec2::new(100.05, 130.0), Vec2::new(100.2, 130.1)] { + assert_eq!(snap_at(&s, cursor, 0.5, mode::CEN | mode::MID), Some((Vec2::new(100.0, 130.0), mode::MID)), "at {cursor:?}"); + assert_eq!(snap_at(&s, cursor, 0.5, mode::MID), Some((Vec2::new(100.0, 130.0), mode::MID)), "at {cursor:?}"); + } + // Elsewhere on the arc, with no snap point in the aperture, the center from the curve. + let (p, m) = snap_at(&s, polar(Vec2::new(100.0, 50.0), 80.1, 70.0), 0.5, mode::CEN | mode::MID).unwrap(); + assert_eq!(m, mode::CEN); + assert!(p.near(Vec2::new(100.0, 50.0), 1e-9), "{p:?}"); +} + +#[test] +fn a_quadrant_under_the_cursor_beats_the_center_from_the_curve() { + let mut s = Session::new(); + s.execute("circle", &json!({ "center": [20, 0], "radius": 2 })).unwrap(); + let cursor = Vec2::new(20.1, 2.0); + assert_eq!(snap_at(&s, cursor, 0.5, mode::CEN | mode::QUA), Some((Vec2::new(20.0, 2.0), mode::QUA))); + assert_eq!(snap_at(&s, cursor, 0.5, mode::QUA), Some((Vec2::new(20.0, 2.0), mode::QUA))); + // Away from the quadrants the center from the curve. + let (p, m) = snap_at(&s, polar(Vec2::new(20.0, 0.0), 2.1, 45.0), 0.5, mode::CEN | mode::QUA).unwrap(); + assert_eq!(m, mode::CEN); + assert!(p.near(Vec2::new(20.0, 0.0), 1e-9), "{p:?}"); +} + +#[test] +fn many_straight_segments_do_not_hide_a_circle_from_center() { + // A polyline of 2,500 straight segments zigzagging over the cursor, then a circle: the + // work limit counts circles and arcs only, so the circle's center is still found. + let mut s = Session::new(); + let vertices: Vec<[f64; 2]> = (0..=2500).map(|i| [i as f64 * 0.04, if i % 2 == 0 { 0.0 } else { 100.0 }]).collect(); + s.execute("pline", &json!({ "vertices": vertices })).unwrap(); + s.execute("circle", &json!({ "center": [50, 50], "radius": 20 })).unwrap(); + let (p, m) = snap_at(&s, polar(Vec2::new(50.0, 50.0), 20.2, 100.0), 0.5, mode::CEN).unwrap(); + assert_eq!(m, mode::CEN); + assert!(p.near(Vec2::new(50.0, 50.0), 1e-9), "{p:?}"); +} + +#[test] +fn a_viewport_center_keeps_its_curve_distance_against_paper_space() { + use cadcraft_engine::doc::{Circle, Drawing, Viewport}; + let mut d = Drawing::new_imperial(); + let paper = Space::Paper("Layout1".into()); + // Model circle (10,0) r16 seen through a viewport at half scale: paper center (100,50), radius 8. + d.add(&Space::Model, Common::default(), EntityKind::Circle(Circle { center: Vec3::new(10.0, 0.0, 0.0), radius: 16.0 })).unwrap(); + let vp = Viewport { + center: Vec3::new(100.0, 50.0, 0.0), + width: 20.0, + height: 20.0, + view_center: Vec2::new(10.0, 0.0), + view_height: 40.0, + id: 2, + locked: false, + frozen_layers: Vec::new(), + layer_colors: Vec::new(), + clip: None, + on: true, + }; + d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap(); + // A small paper-space circle whose curve passes 0.3 from the cursor and whose center is + // nearer the cursor (3.3) than the model circle's (8). + d.add(&paper, Common::default(), EntityKind::Circle(Circle { center: Vec3::new(108.0, 53.3, 0.0), radius: 3.0 })).unwrap(); + // The cursor is on the model circle (0.1 off in paper units): its center wins. + let h = snap::osnap(&d, &paper, Vec2::new(108.1, 50.0), 0.5, mode::CEN, None, false).unwrap(); + assert_eq!(h.mode, mode::CEN); + assert!(h.point.near(Vec2::new(100.0, 50.0), 1e-9), "{h:?}"); + assert!(h.viewport.is_some()); + // On the paper circle, away from the model one: its center. + let h = snap::osnap(&d, &paper, Vec2::new(108.0, 56.35), 0.5, mode::CEN, None, false).unwrap(); + assert!(h.point.near(Vec2::new(108.0, 53.3), 1e-9), "{h:?}"); + assert!(h.viewport.is_none()); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 7b9c8b79db..af6e227227 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -61,7 +61,7 @@ ignored; there are no context menus. Remaining: **≈ 110–170 Opus 5.5 hours** |---|---|---| | Endpoint | every curve, solid/3D vertices, dimension ends | lines, arcs, polyline segments, open ellipses and splines, ray base, solid/trace corners | | Midpoint | every curve incl. ellipse/spline arcs, polyline segments | segments only; **none on circles, ellipses, splines** | -| Center | arcs, circles, ellipses, polyarcs | arcs, circles, ellipses, polyline arcs (also inside block references); found with the cursor on the curve, however far the center is, as in AutoCAD (`snap.rs` `curve_centers`) | +| Center | arcs, circles, ellipses, polyarcs | arcs, circles, ellipses, polyline arcs (also inside block references); found with the cursor on the curve, however far the center is, when no snap point is in the aperture, as in AutoCAD (`snap.rs` `curve_centers`) | | Geometric center | any closed polyline, spline | closed LWPOLYLINE only | | Node | points, dimension definition points, text alignment points | POINT only | | Quadrant | circles, arcs, ellipses | yes | @@ -203,7 +203,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Date | Change | Summary | |---|---|---| -| 2026-10-27 | minor | Center snaps from the curve: with the cursor on a circle, arc, ellipse or polyline arc (in block references too) the running Center snap finds its center, a nearer endpoint or intersection still winning; Tab cycling offers it | +| 2026-10-27 | minor | Center snaps from the curve: with the cursor on a circle, arc, ellipse or polyline arc (in block references too) the running Center snap finds its center when no snap point (Endpoint, Midpoint, Quadrant, Intersection) is in the aperture; through layout viewports too; Tab cycling offers it | | 2026-10-22 | minor | Polyline segment midpoint grips use rectangles, distinct from square vertex grips, with matching hover and pick bounds (#1950) | | 2026-10-13 | minor | Filled-region highlight boundaries are traversed in deterministic coordinate order, fixing dash-phase jumps on CPU hover/selection redraws and GPU highlight rebuilds; CPU dash-position, pixel and GPU mesh regressions | | 2026-10-14 | minor | Selection cycling (#1143): the list and badge of SELECTIONCYCLING, Shift+Space through overlapping objects (#1145) | From 4ce72c668ad6734a604e4eba10115d6df94360f8 Mon Sep 17 00:00:00 2001 From: austin62jake <340374338+austin62jake@users.noreply.github.com> Date: Thu, 5 Nov 2026 07:39:52 -0600 Subject: [PATCH 08/30] fix(snap): PER and TAN snap from anywhere on the object (#2800) With a base point, a perpendicular or tangent snap was kept only when its foot or tangent point lay within the aperture, so hovering elsewhere on the line or circle found nothing, and a typed `per` said "No Perpendicular found for specified point". As in AutoCAD, these snaps name an object, not a spot on it: from anywhere over the object, the point jumps to the foot or the tangent point. They now also qualify when their object passes within the aperture, as a fallback after every snap point within the aperture, so an endpoint, midpoint or intersection under the cursor still wins. Of several objects, the one nearest the cursor gives the snap; of several points on one (an arc's antipodes, a circle's two tangents), the one nearest the cursor. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/snap.rs | 138 ++++++++++++++++++++--- crates/engine/tests/it/snap_overrides.rs | 17 +++ 2 files changed, 142 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 061b0772b9..91ae9ee748 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -459,6 +459,14 @@ fn gather_in( } /// Picks the best of the gathered candidates, adding the base-dependent and deferred snaps. +/// +/// In order of preference: +/// 1. the snap point within `aperture` of the cursor that scores best (see [`snap_score`]), +/// perpendicular and tangent points from the base point included; +/// 2. with a base point, a perpendicular or tangent on an object that passes within `aperture`, +/// wherever its point lies (see [`from_base_on_object`]); +/// 3. a deferred perpendicular or tangent (no base point yet); +/// 4. Nearest. #[allow(clippy::too_many_arguments)] fn finish( mut cands: Vec<(u32, Vec2)>, @@ -470,24 +478,27 @@ fn finish( deferred: bool, clip: Option, ) -> Option { - // Perpendicular / tangent from the base point. + // Perpendicular / tangent from the base point, each with the index in `near_prims` of the + // object it lies on, for step 2. + let mut from_base: Vec = Vec::new(); if let Some(bp) = base { - for p in near_prims { + for (prim, p) in near_prims.iter().enumerate() { + let mut found = |mode: u32, points: Vec| from_base.extend(points.into_iter().map(|point| FromBase { mode, point, prim })); if osmode & mode::PER != 0 { - match p { - Prim::Seg(Segment::Line(l)) => cands.push((mode::PER, l.project(bp))), + let pts = match p { + Prim::Seg(Segment::Line(l)) => vec![l.project(bp)], // Both antipodes, filtered to the arc's sweep: a perpendicular in the gap is // not offered, and the far side is still found. Prim::Seg(Segment::Arc { arc, .. }) => { - let curve = SnapCurve::Arc { center: arc.center, radius: arc.radius, start: arc.start, end: arc.end }; - cands.extend(curve.perpendiculars(bp, bp).into_iter().map(|q| (mode::PER, q))); + SnapCurve::Arc { center: arc.center, radius: arc.radius, start: arc.start, end: arc.end }.perpendiculars(bp, bp) } - Prim::Circle(c) => cands.push((mode::PER, c.closest(bp))), - Prim::Infinite { base: b0, dir, .. } => cands.push((mode::PER, *b0 + *dir * (bp - *b0).dot(*dir))), - Prim::Ellipse(e) => cands.extend(curves::ellipse_perpendiculars(e, bp).into_iter().map(|q| (mode::PER, q))), - Prim::Spline(s) => cands.extend(curves::spline_perpendiculars(s, bp).into_iter().map(|q| (mode::PER, q))), - _ => {} - } + Prim::Circle(c) => vec![c.closest(bp)], + Prim::Infinite { base: b0, dir, .. } => vec![*b0 + *dir * (bp - *b0).dot(*dir)], + Prim::Ellipse(e) => curves::ellipse_perpendiculars(e, bp), + Prim::Spline(s) => curves::spline_perpendiculars(s, bp), + _ => Vec::new(), + }; + found(mode::PER, pts); } if osmode & mode::TAN != 0 { let pts = match p { @@ -502,9 +513,10 @@ fn finish( Prim::Spline(s) => curves::spline_tangents(s, bp), _ => Vec::new(), }; - cands.extend(pts.into_iter().map(|t| (mode::TAN, t))); + found(mode::TAN, pts); } } + cands.extend(from_base.iter().map(|f| (f.mode, f.point))); } let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); let best = cands.iter().filter(|(_, p)| visible(*p) && p.dist(cursor) <= aperture).min_by(|a, b| { @@ -516,6 +528,9 @@ fn finish( if let Some((m, p)) = best { return Some(SnapHit { point: *p, mode: *m, name: name_of(*m), viewport: None, deferred: None }); } + if let Some(h) = from_base_on_object(&from_base, near_prims, cursor, aperture, visible) { + return Some(h); + } if base.is_none() && deferred && let Some(h) = deferred_hit(near_prims, cursor, aperture, osmode, clip) @@ -550,6 +565,55 @@ fn snap_score(mode: u32, point: Vec2, cursor: Vec2, aperture: f64) -> f64 { point.dist(cursor) - if mode == mode::INT || mode == mode::END { aperture * 0.15 } else { 0.0 } } +/// A perpendicular ([`mode::PER`]) or tangent ([`mode::TAN`]) point found from the base point, +/// with the index in `near_prims` of the object it lies on. +struct FromBase { + mode: u32, + point: Vec2, + prim: usize, +} + +/// A perpendicular or tangent from the base point on an object that passes within `aperture` of +/// the cursor, wherever the foot or tangent point lies (#2800). +/// +/// These snaps name an object, not a spot on it: you can't know in advance where the foot of a +/// perpendicular will be, so, as in AutoCAD, hovering anywhere over the object finds it and the +/// point jumps there. [`finish`] asks for this only when no snap point lies within the aperture, +/// so an endpoint, midpoint or intersection under the cursor still wins. +/// +/// The object nearest the cursor wins; of several points on it (an arc's two antipodes, a +/// circle's two tangents), the one nearest the cursor. +fn from_base_on_object(found: &[FromBase], near_prims: &[Prim], cursor: Vec2, aperture: f64, visible: impl Fn(Vec2) -> bool) -> Option { + if found.is_empty() { + return None; + } + // `near_prims` holds every object whose box comes near the cursor, so the true distance is + // checked here. It is measured once per object, and only for objects with a point to offer: + // an ellipse or a spline is measured on its tessellation. + let mut reach: Vec> = vec![None; near_prims.len()]; + // (distance from the cursor to the object, distance from the cursor to the point, the point) + let mut best: Option<(f64, f64, &FromBase)> = None; + for f in found.iter().filter(|f| visible(f.point)) { + let Some(slot) = reach.get_mut(f.prim) else { continue }; + let to_object = *slot.get_or_insert_with(|| near_prims.get(f.prim).map_or(f64::INFINITY, |p| distance_to_prim(p, cursor))); + // A NaN distance (from a degenerate object) never qualifies. + if to_object.is_nan() || to_object > aperture { + continue; + } + let to_point = f.point.dist(cursor); + let better = best.is_none_or(|(o, d, _)| to_object.total_cmp(&o).then(to_point.total_cmp(&d)).is_lt()); + if better { + best = Some((to_object, to_point, f)); + } + } + best.map(|(_, _, f)| SnapHit { point: f.point, mode: f.mode, name: name_of(f.mode), viewport: None, deferred: None }) +} + +/// The distance from `cursor` to the nearest point of `p`, measured as Nearest measures it. +fn distance_to_prim(p: &Prim, cursor: Vec2) -> f64 { + prim_segments(p).iter().map(|s| fix_circle(s).closest(cursor).dist(cursor)).fold(f64::INFINITY, f64::min) +} + /// Upper bound on the block-reference objects one snap query looks at (hostile files). const MAX_BLOCK_LEAVES: usize = 20_000; @@ -1112,6 +1176,54 @@ mod tests { assert!(h.point.near(Vec2::new(3.0, 0.0), 1e-9)); } + /// #2800: hovering anywhere over the line finds the perpendicular, though its foot (2,0) is + /// six units from the cursor; it used to snap only within the aperture of the foot. + #[test] + fn perpendicular_from_base_anywhere_on_the_line() { + let d = drawing(); + let h = osnap(&d, &Space::Model, Vec2::new(8.0, 0.1), 0.5, mode::PER, Some(Vec2::new(2.0, 4.0)), false).unwrap(); + assert!(h.point.near(Vec2::new(2.0, 0.0), 1e-9), "{h:?}"); + assert_eq!(h.mode, mode::PER); + } + + /// #2800: the tangent point is found from anywhere on the circle; of its two tangent points + /// from the base, the one nearer the cursor. + #[test] + fn tangent_from_base_anywhere_on_the_circle() { + let d = drawing(); + // From (30,0), 10 from the centre (20,0) of the radius-2 circle: the tangent points are + // at cos = 2/10 from the line to the base, (20.4, ±1.9596). + let upper = Vec2::new(20.4, 2.0 * (1.0f64 - 0.04).sqrt()); + let on_circle = Vec2::new(20.0 - 2.0 * std::f64::consts::FRAC_1_SQRT_2, 2.0 * std::f64::consts::FRAC_1_SQRT_2); + let h = osnap(&d, &Space::Model, on_circle, 0.5, mode::TAN, Some(Vec2::new(30.0, 0.0)), false).unwrap(); + assert!(h.point.near(upper, 1e-9), "{h:?}"); + let mirrored = Vec2::new(on_circle.x, -on_circle.y); + let h = osnap(&d, &Space::Model, mirrored, 0.5, mode::TAN, Some(Vec2::new(30.0, 0.0)), false).unwrap(); + assert!(h.point.near(Vec2::new(upper.x, -upper.y), 1e-9), "{h:?}"); + } + + /// With several objects under the aperture, the one nearest the cursor gives the + /// perpendicular, even when another object's foot is nearer. + #[test] + fn perpendicular_from_base_takes_the_object_nearest_the_cursor() { + let d = drawing(); + // 0.4 above the horizontal line and 0.2 right of the vertical one: the vertical line wins, + // with its foot (5,4) farther from the cursor than the horizontal line's (2,0). + let h = osnap(&d, &Space::Model, Vec2::new(5.2, 0.4), 0.5, mode::PER, Some(Vec2::new(2.0, 4.0)), false).unwrap(); + assert!(h.point.near(Vec2::new(5.0, 4.0), 1e-9), "{h:?}"); + } + + /// A snap point under the cursor still beats a perpendicular whose foot is away from it, and + /// an object outside the aperture gives none, though its box is near. + #[test] + fn perpendicular_from_base_yields_to_points_under_the_cursor() { + let d = drawing(); + let base = Some(Vec2::new(2.0, 4.0)); + let h = osnap(&d, &Space::Model, Vec2::new(9.9, 0.05), 0.5, mode::END | mode::PER, base, false).unwrap(); + assert_eq!((h.point, h.mode), (Vec2::new(10.0, 0.0), mode::END)); + assert!(osnap(&d, &Space::Model, Vec2::new(8.0, 0.7), 0.5, mode::PER, base, false).is_none()); + } + #[test] fn ortho_and_polar() { assert_eq!(ortho(Vec2::ZERO, Vec2::new(5.0, 1.0)), Vec2::new(5.0, 0.0)); diff --git a/crates/engine/tests/it/snap_overrides.rs b/crates/engine/tests/it/snap_overrides.rs index a02ab92da5..bbd3739da6 100644 --- a/crates/engine/tests/it/snap_overrides.rs +++ b/crates/engine/tests/it/snap_overrides.rs @@ -80,6 +80,23 @@ fn nothing_to_snap_to_rejects_the_point() { assert!(near(s.last_point, 10.0, 10.0)); } +/// #2800: a typed PER or TAN finds its point from a pick anywhere on the object, as in AutoCAD. +/// The pick used to have to land within the aperture (0.125 here) of the foot or tangent point, +/// which you can't know in advance; elsewhere it said "No Perpendicular found". +#[test] +fn typed_per_and_tan_snap_from_anywhere_on_the_object() { + let mut s = drawing(); + // From (5,5), PER picked at (3,0) on the line 0,0–10,0: two units from the foot (5,0). + s.script("LINE 5,5 PER 3,0\n\n").unwrap(); + let (a, b) = last_line(&s); + assert!(near(a, 5.0, 5.0) && near(b, 5.0, 0.0), "{a:?} {b:?}"); + // From (30,20), TAN picked at the top of the circle (centre 20,20, radius 3): the tangent + // points are at cos = 3/10 from the line to the base, and the upper one is nearer the pick. + s.script("LINE 30,20 TAN 20,23\n\n").unwrap(); + let (a, b) = last_line(&s); + assert!(near(a, 30.0, 20.0) && near(b, 20.9, 20.0 + 3.0 * 0.91f64.sqrt()), "{a:?} {b:?}"); +} + #[test] fn from_nests_with_a_snap_override() { let mut s = drawing(); From 8acdceeb61260d51f3646ab98842466cd9127991 Mon Sep 17 00:00:00 2001 From: austin62jake <340374338+austin62jake@users.noreply.github.com> Date: Thu, 5 Nov 2026 08:05:36 -0600 Subject: [PATCH 09/30] fix(snap): a circle offers both perpendicular points from the base (CodeRabbit on #2825) PER on a circle offered only the point nearest the base point, so with the new object fallback a pick on the circle's far side jumped across it. Like an arc, a circle now offers both antipodes, and the one nearer the cursor wins. From the circle's centre, where every point is perpendicular, the point under the cursor is taken. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/snap.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 91ae9ee748..f3e6118928 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -492,7 +492,10 @@ fn finish( Prim::Seg(Segment::Arc { arc, .. }) => { SnapCurve::Arc { center: arc.center, radius: arc.radius, start: arc.start, end: arc.end }.perpendiculars(bp, bp) } - Prim::Circle(c) => vec![c.closest(bp)], + // Both antipodes too, so a pick on the far side of the circle snaps there + // rather than across it. From the centre every point is perpendicular: the + // one under the cursor. + Prim::Circle(c) => SnapCurve::Circle { center: c.center, radius: c.radius }.perpendiculars(bp, cursor), Prim::Infinite { base: b0, dir, .. } => vec![*b0 + *dir * (bp - *b0).dot(*dir)], Prim::Ellipse(e) => curves::ellipse_perpendiculars(e, bp), Prim::Spline(s) => curves::spline_perpendiculars(s, bp), @@ -1202,6 +1205,22 @@ mod tests { assert!(h.point.near(Vec2::new(upper.x, -upper.y), 1e-9), "{h:?}"); } + /// A circle offers both perpendicular points from the base, so a pick on its far side snaps + /// there, not to the near side across the circle (CodeRabbit on #2825). + #[test] + fn perpendicular_from_base_on_a_circle_takes_the_side_under_the_cursor() { + let d = drawing(); + // The circle at (20,0), radius 2, seen from (30,0): perpendicular at (22,0) and (18,0). + let base = Some(Vec2::new(30.0, 0.0)); + let far = osnap(&d, &Space::Model, Vec2::new(18.1, 0.1), 0.5, mode::PER, base, false).unwrap(); + assert!(far.point.near(Vec2::new(18.0, 0.0), 1e-9), "{far:?}"); + // Away from both points, at (19, √3) on the circle: 2 from (18,0) and √12 from (22,0). + let top = osnap(&d, &Space::Model, Vec2::new(19.0, 3.0f64.sqrt()), 0.5, mode::PER, base, false).unwrap(); + assert!(top.point.near(Vec2::new(18.0, 0.0), 1e-9), "{top:?}"); + let near = osnap(&d, &Space::Model, Vec2::new(21.9, 0.1), 0.5, mode::PER, base, false).unwrap(); + assert!(near.point.near(Vec2::new(22.0, 0.0), 1e-9), "{near:?}"); + } + /// With several objects under the aperture, the one nearest the cursor gives the /// perpendicular, even when another object's foot is nearer. #[test] From c40ff9603e84ef09982d8d042495f227450c3477 Mon Sep 17 00:00:00 2001 From: jayzed80 Date: Sat, 14 Nov 2026 14:54:49 +0000 Subject: [PATCH 10/30] Snap: skip VPLAYER-frozen layers in MSPACE (#3158) --- crates/engine/src/cmd/layout/tests.rs | 58 +++++++++++++++++++++++++++ crates/engine/src/doc_state.rs | 9 ++++- crates/engine/src/pointmod.rs | 24 +++++++++-- crates/engine/src/snap.rs | 36 ++++++++++------- crates/engine/src/snap/tracking.rs | 55 +++++++++++++++++++++---- crates/ui-egui/src/canvas/cursor.rs | 6 ++- 6 files changed, 159 insertions(+), 29 deletions(-) diff --git a/crates/engine/src/cmd/layout/tests.rs b/crates/engine/src/cmd/layout/tests.rs index 57d52a7ef4..ea58305ed8 100644 --- a/crates/engine/src/cmd/layout/tests.rs +++ b/crates/engine/src/cmd/layout/tests.rs @@ -372,3 +372,61 @@ fn plot_path_extension_picks_the_format_like_export() { assert!(!dir.join("w.png").exists(), "nothing written when `output` and the path disagree"); std::fs::remove_dir_all(&dir).ok(); } + +#[test] +fn osnap_in_mspace_skips_vplayer_frozen_layers() { + let mut s = Session::new(); + s.execute("layer.new", &json!({"name": "Hidden"})).unwrap(); + s.execute("line", &json!({"points": [[60, -25], [70, -25]]})).unwrap(); + let line_h = s.doc().unwrap().model.iter().last().unwrap().handle; + s.execute("properties.set", &json!({"handles": [line_h], "layer": "Hidden"})).unwrap(); + s.execute("layout.set", &json!({"name": "Layout1"})).unwrap(); + s.execute("mview", &json!({"p1": [20, 20], "p2": [220, 120]})).unwrap(); + let vp_h = viewports(&s, "Layout1").last().unwrap().0; + s.execute("vplayer", &json!({"handles": [vp_h], "freeze": ["Hidden"]})).unwrap(); + s.execute("mspace", &json!({"handle": vp_h})).unwrap(); + + let ap = s.pixel_size() * s.settings.aperture.max(1.0); + let d = ap * 0.5; + let model_before = s.doc().unwrap().model.len(); + for (ovr, pt, name) in [ + ("end", format!("{},-25", 60.0 + d), "Endpoint"), + ("mid", format!("{},-25", 65.0 + d), "Midpoint"), + ("nea", format!("63,{}", -25.0 + d), "Nearest"), + ] { + s.cmdline("line").unwrap(); + s.cmdline(ovr).unwrap(); + s.cmdline(&pt).unwrap(); + assert_eq!( + s.log.last().map(String::as_str), + Some(format!("No {name} found for specified point.").as_str()), + "{ovr} should not snap to a line on a VPLAYER-frozen layer; log: {:?}", + s.log + ); + s.cmdline("").unwrap(); + } + assert_eq!(s.doc().unwrap().model.len(), model_before, "no new line should be created"); + + // Running osnaps through snap_cursor must also ignore the VPLAYER-frozen layer. + s.settings.osmode = crate::snap::mode::END | crate::snap::mode::MID | crate::snap::mode::NEA; + let cs = s.snap_cursor( + cadcraft_geom::Vec2::new(60.0 + d, -25.0), + &crate::snap::tracking::CursorQuery { base: None, deferred: false, corner: false, aperture: ap, tol: ap, now: 0.0, shift: false }, + ); + assert!(cs.snap.is_none(), "running osnap should not snap to a VPLAYER-frozen line: {:?}", cs.snap); + + // A block reference on layer "0" containing an entity on "Hidden" must also not snap. + s.execute("block", &json!({"name": "B", "base": [60, -25], "handles": [line_h]})).unwrap(); + let model_with_block = s.doc().unwrap().model.len(); + s.cmdline("line").unwrap(); + s.cmdline("end").unwrap(); + s.cmdline(&format!("{},-25", 60.0 + d)).unwrap(); + assert_eq!( + s.log.last().map(String::as_str), + Some("No Endpoint found for specified point."), + "end should not snap to a block entity on a VPLAYER-frozen layer; log: {:?}", + s.log + ); + s.cmdline("").unwrap(); + assert_eq!(s.doc().unwrap().model.len(), model_with_block); +} diff --git a/crates/engine/src/doc_state.rs b/crates/engine/src/doc_state.rs index f3862f90ab..63406f05d5 100644 --- a/crates/engine/src/doc_state.rs +++ b/crates/engine/src/doc_state.rs @@ -119,10 +119,17 @@ impl DocState { } /// The active MSPACE viewport, if it still exists in the current layout. pub fn active_viewport(&self) -> Option<(Handle, cadcraft_doc::Viewport)> { + self.active_viewport_ref().map(|(h, v)| (h, v.clone())) + } + /// Layers frozen in the active MSPACE viewport, if any. + pub fn active_viewport_frozen(&self) -> &[String] { + self.active_viewport_ref().map_or(&[], |(_, v)| &v.frozen_layers) + } + fn active_viewport_ref(&self) -> Option<(Handle, &cadcraft_doc::Viewport)> { let h = self.mspace?; let e = self.doc.space(&self.space)?.get(h)?; match &e.kind { - cadcraft_doc::EntityKind::Viewport(v) if v.height > 1e-12 && v.view_height > 1e-12 => Some((h, v.clone())), + cadcraft_doc::EntityKind::Viewport(v) if v.height > 1e-12 && v.view_height > 1e-12 => Some((h, v)), _ => None, } } diff --git a/crates/engine/src/pointmod.rs b/crates/engine/src/pointmod.rs index 74c1ab0835..f5dda5ca99 100644 --- a/crates/engine/src/pointmod.rs +++ b/crates/engine/src/pointmod.rs @@ -122,10 +122,25 @@ pub fn snap_name(m: u32) -> &'static str { /// The candidate snaps near `cursor` for Tab cycling: the snap [`crate::snap::osnap`] picks /// first, then the closest snap of each other mode in `osmode`, nearest first, without repeats. pub fn snap_candidates(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Vec { + snap_candidates_with_frozen(d, space, cursor, aperture, osmode, base, deferred, &[]) +} + +/// [`snap_candidates`] skipping entities (and block leaves) on `frozen` layers in `space`. +#[allow(clippy::too_many_arguments)] +pub fn snap_candidates_with_frozen( + d: &Drawing, + space: &Space, + cursor: Vec2, + aperture: f64, + osmode: u32, + base: Option, + deferred: bool, + frozen: &[String], +) -> Vec { if osmode & !mode::HATCH == 0 || osmode & mode::OFF != 0 { return Vec::new(); } - let osnap = |m: u32| crate::snap::osnap(d, space, cursor, aperture, m, base, deferred); + let osnap = |m: u32| crate::snap::osnap_with_frozen(d, space, cursor, aperture, m, base, deferred, frozen); let extra = osmode & mode::HATCH; let mut per_mode: Vec = mode::ALL.iter().filter(|(b, _)| osmode & b != 0).filter_map(|(b, _)| osnap(*b | extra)).collect(); per_mode.sort_by(|a, b| a.point.dist(cursor).total_cmp(&b.point.dist(cursor))); @@ -342,12 +357,15 @@ impl Session { Frame::Snap { mode } => { // Snap the point with this mode alone, within the aperture. let prompt = self.current_prompt(); - let space = self.space(); + let (doc, space, frozen) = { + let st = self.state()?; + (st.doc.clone(), st.edit_space(), st.active_viewport_frozen().to_vec()) + }; let aperture = self.pixel_size() * self.settings.aperture.max(1.0); let hatch = if self.settings.osnaphatch { mode::HATCH } else { 0 }; let base = prompt.as_ref().and_then(|q| q.base); let deferred = prompt.as_ref().is_some_and(|q| q.deferred); - let hit = crate::snap::osnap(self.doc()?, &space, p, aperture, mode | hatch, base, deferred); + let hit = crate::snap::osnap_with_frozen(&doc, &space, p, aperture, mode | hatch, base, deferred, &frozen); match hit { Some(h) if self.point_mods.is_empty() => return self.input_snapped(h), Some(h) => p = h.point, diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 061b0772b9..9d290039b8 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -204,13 +204,29 @@ fn prim_segments(p: &Prim) -> Vec { /// they snap as *deferred*: the hit carries the curve and is resolved once the other end is /// known. Deferred hits only win where no other snap does (they are as unspecific as Nearest). pub fn osnap(d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, osmode: u32, base: Option, deferred: bool) -> Option { + osnap_with_frozen(d, space, cursor, aperture, osmode, base, deferred, &[]) +} + +/// [`osnap`] skipping entities (and block leaves) on `frozen` layers in `space`. +#[allow(clippy::too_many_arguments)] +pub fn osnap_with_frozen( + d: &Drawing, + space: &Space, + cursor: Vec2, + aperture: f64, + osmode: u32, + base: Option, + deferred: bool, + frozen: &[String], +) -> Option { if osmode == 0 || osmode & mode::OFF != 0 { return None; } let ix = crate::spatial::index(d, space); - osnap_with(d, space, &ix, cursor, aperture, osmode, base, deferred) + osnap_with_neighborhood(d, space, &ix, cursor, aperture, osmode, base, deferred, frozen).0 } +#[cfg(test)] #[allow(clippy::too_many_arguments)] pub(crate) fn osnap_with( d: &Drawing, @@ -222,7 +238,7 @@ pub(crate) fn osnap_with( base: Option, deferred: bool, ) -> Option { - osnap_with_neighborhood(d, space, ix, cursor, aperture, osmode, base, deferred).0 + osnap_with_neighborhood(d, space, ix, cursor, aperture, osmode, base, deferred, &[]).0 } /// Find the best object snap and retain the local-space primitives gathered for that query. @@ -236,11 +252,12 @@ pub(crate) fn osnap_with_neighborhood( osmode: u32, base: Option, deferred: bool, + frozen: &[String], ) -> (Option, Option>) { if osmode == 0 || osmode & mode::OFF != 0 || !cursor.is_finite() || !(aperture.is_finite() && aperture > 0.0) { return (None, None); } - let (mut best, near_prims) = match osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, &[], None) { + let (mut best, near_prims) = match osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, frozen, None) { Some((hit, prims)) => (hit, Some(prims)), None => (None, None), }; @@ -390,18 +407,7 @@ pub(crate) fn extendable(p: &Prim) -> bool { /// The snap candidates of `osmode` and the primitives within `aperture` of `cursor`; `None` /// when the drawing can't be searched. -pub(crate) fn gather( - d: &Drawing, - space: &Space, - ix: &Option>, - cursor: Vec2, - aperture: f64, - osmode: u32, -) -> Option<(Vec<(u32, Vec2)>, Vec)> { - gather_in(d, space, ix, cursor, aperture, osmode, &[]) -} - -fn gather_in( +pub(crate) fn gather_in( d: &Drawing, space: &Space, ix: &Option>, diff --git a/crates/engine/src/snap/tracking.rs b/crates/engine/src/snap/tracking.rs index 9db1873ff6..c827181743 100644 --- a/crates/engine/src/snap/tracking.rs +++ b/crates/engine/src/snap/tracking.rs @@ -480,13 +480,38 @@ impl Tracker { cfg: &TrackConfig, base: Option, ) -> Option { - let t = self.find(d, space, cursor, aperture, tol, cfg, base); + self.track_with_frozen(d, space, cursor, aperture, tol, cfg, base, &[]) + } + + #[allow(clippy::too_many_arguments)] + pub(crate) fn track_with_frozen( + &mut self, + d: &Drawing, + space: &Space, + cursor: Vec2, + aperture: f64, + tol: f64, + cfg: &TrackConfig, + base: Option, + frozen: &[String], + ) -> Option { + let t = self.find(d, space, cursor, aperture, tol, cfg, base, frozen); self.last = t.clone(); t } #[allow(clippy::too_many_arguments)] - fn find(&self, d: &Drawing, space: &Space, cursor: Vec2, aperture: f64, tol: f64, cfg: &TrackConfig, base: Option) -> Option { + fn find( + &self, + d: &Drawing, + space: &Space, + cursor: Vec2, + aperture: f64, + tol: f64, + cfg: &TrackConfig, + base: Option, + frozen: &[String], + ) -> Option { if !(cursor.is_finite() && aperture.is_finite() && tol.is_finite() && aperture > 0.0 && tol > 0.0) { return None; } @@ -536,7 +561,7 @@ impl Tracker { // 2. A path crossing an object. if cfg.running(mode::INT | mode::APP) { let ix = crate::spatial::index(d, space); - let prims = super::gather(d, space, &ix, cursor, aperture, mode::NEA).map(|(_, p)| p).unwrap_or_default(); + let prims = super::gather_in(d, space, &ix, cursor, aperture, mode::NEA, frozen).map(|(_, p)| p).unwrap_or_default(); for prim in prims.iter().take(200) { let extend = cfg.running(mode::APP) && super::extendable(prim); for seg in super::prim_segments(prim) { @@ -586,12 +611,26 @@ pub fn candidate( aperture: f64, cfg: &TrackConfig, base: Option, +) -> Option { + candidate_with_frozen(d, space, cursor, hit, aperture, cfg, base, &[]) +} + +#[allow(clippy::too_many_arguments)] +pub(crate) fn candidate_with_frozen( + d: &Drawing, + space: &Space, + cursor: Vec2, + hit: Option<&SnapHit>, + aperture: f64, + cfg: &TrackConfig, + base: Option, + frozen: &[String], ) -> Option { if !can_acquire(cursor, aperture, cfg) { return None; } let ix = crate::spatial::index(d, space); - let prims = super::gather(d, space, &ix, cursor, aperture, mode::NEA).map(|(_, p)| p).unwrap_or_default(); + let prims = super::gather_in(d, space, &ix, cursor, aperture, mode::NEA, frozen).map(|(_, p)| p).unwrap_or_default(); candidate_from_prims(cursor, hit, aperture, cfg, base, &prims) } @@ -787,7 +826,7 @@ impl crate::Session { s.orthomode ^= q.shift; let angbase = self.angle_settings().angbase; let Ok(st) = self.state() else { return CursorSnap { point: raw, ..Default::default() } }; - let (doc, space) = (st.doc.clone(), st.edit_space()); + let (doc, space, frozen) = (st.doc.clone(), st.edit_space(), st.active_viewport_frozen().to_vec()); if !raw.is_finite() { return CursorSnap { point: raw, ..Default::default() }; } @@ -796,10 +835,10 @@ impl crate::Session { let cfg = TrackConfig::relative_to(&s, angbase, last); let osmode = s.osmode | if s.osnaphatch { mode::HATCH } else { 0 }; let ix = crate::spatial::index(&doc, &space); - let (hit, near_prims) = super::osnap_with_neighborhood(&doc, &space, &ix, raw, q.aperture, osmode, q.base, q.deferred); + let (hit, near_prims) = super::osnap_with_neighborhood(&doc, &space, &ix, raw, q.aperture, osmode, q.base, q.deferred, &frozen); let cand = match (osmode & mode::HATCH, near_prims.as_deref()) { (0, Some(prims)) => candidate_with_prims(raw, hit.as_ref(), q.aperture, &cfg, q.base, prims), - _ => candidate(&doc, &space, raw, hit.as_ref(), q.aperture, &cfg, q.base), + _ => candidate_with_frozen(&doc, &space, raw, hit.as_ref(), q.aperture, &cfg, q.base, &frozen), }; let wait = self.tracking.hover(cand, q.now, cfg.shift_acquire, q.shift); if let Some(h) = hit { @@ -813,7 +852,7 @@ impl crate::Session { let (origin, angle) = super::grid_frame(&doc); p = super::grid_snap(p, doc.header.snap_unit(), origin, angle); } - if let Some(mut t) = self.tracking.track(&doc, &space, p, q.aperture, q.tol, &cfg, q.base) { + if let Some(mut t) = self.tracking.track_with_frozen(&doc, &space, p, q.aperture, q.tol, &cfg, q.base, &frozen) { // PolarSnap (SNAPTYPE 1): steps of POLARDIST, or of the snap X spacing when it is 0. let step = if s.polardist > 0.0 { s.polardist } else { s.snapunit.x }; if s.snapmode diff --git a/crates/ui-egui/src/canvas/cursor.rs b/crates/ui-egui/src/canvas/cursor.rs index 02f1cf4c20..f38e00cd78 100644 --- a/crates/ui-egui/src/canvas/cursor.rs +++ b/crates/ui-egui/src/canvas/cursor.rs @@ -189,12 +189,14 @@ pub(super) fn override_cursor(app: &mut CadApp, raw: Vec2, xf: &Xf) { let s = &app.session.settings; let osmode = over.unwrap_or(s.osmode) | if s.osnaphatch { snap::mode::HATCH } else { 0 }; let Ok(st) = app.session.state() else { return }; + let space = st.edit_space(); + let frozen = st.active_viewport_frozen(); let hit = match cycle { Some(i) => { - let cands = cadcraft_engine::pointmod::snap_candidates(&st.doc, &st.edit_space(), raw, ap, osmode, base, deferred); + let cands = cadcraft_engine::pointmod::snap_candidates_with_frozen(&st.doc, &space, raw, ap, osmode, base, deferred, frozen); cands.get(i % cands.len().max(1)).copied() } - None => snap::osnap(&st.doc, &st.edit_space(), raw, ap, osmode, base, deferred), + None => snap::osnap_with_frozen(&st.doc, &space, raw, ap, osmode, base, deferred, frozen), }; let p = match (hit, app.canvas.snap) { (Some(h), _) => { From c00bc5994952899075dd3781a1a3651c5db03c1f Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:28:59 -0700 Subject: [PATCH 11/30] Snap tests: fill in the Insert clip and Viewport twist fields that main added after #2347 --- crates/engine/tests/it/snap_center_on_curve.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/engine/tests/it/snap_center_on_curve.rs b/crates/engine/tests/it/snap_center_on_curve.rs index 20a3c24106..cbb551b305 100644 --- a/crates/engine/tests/it/snap_center_on_curve.rs +++ b/crates/engine/tests/it/snap_center_on_curve.rs @@ -89,6 +89,7 @@ fn circles_inside_block_references_snap_to_their_centers() { rows: 1, col_spacing: 0.0, row_spacing: 0.0, + clip: None, }); s.doc_mut().unwrap().add(&Space::Model, Common::default(), kind).unwrap(); // The circle lands at (115,100) with radius 6. @@ -183,6 +184,7 @@ fn a_viewport_center_keeps_its_curve_distance_against_paper_space() { layer_colors: Vec::new(), clip: None, on: true, + twist: 0.0, }; d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap(); // A small paper-space circle whose curve passes 0.3 from the cursor and whose center is From b1dcb46e088e2ca534da27134099075c82866133 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:37:04 -0700 Subject: [PATCH 12/30] Snap test: convert the test's own DWG in process, as main's DWG reader now asks --- crates/engine/tests/it/osnap_opened_drawings.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/engine/tests/it/osnap_opened_drawings.rs b/crates/engine/tests/it/osnap_opened_drawings.rs index 58e80eefe3..9e6525114b 100644 --- a/crates/engine/tests/it/osnap_opened_drawings.rs +++ b/crates/engine/tests/it/osnap_opened_drawings.rs @@ -104,6 +104,8 @@ fn a_dxf_with_osmode_0_keeps_the_running_snaps() { #[test] fn default_snaps_work_in_a_drawing_opened_from_dwg() { + // The drawing is the test's own, so it is converted in this process. + cadcraft_io::dwg_worker::allow_in_process(); let bytes = cadcraft_io::write(&drawing(), "snaps.dwg").unwrap(); let d = cadcraft_io::read(&bytes, "snaps.dwg").unwrap(); let mut s = Session::new(); From c2af11dfa79e7172860a62c5feed5884b877627e Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:39:55 -0700 Subject: [PATCH 13/30] Nearest: a curve crossing a viewport edge offers its visible point The Nearest from #2350 took each object's closest point first and only then dropped it when the viewport clipped it, so an ellipse or spline whose closest point lay just outside the viewport offered nothing, though another of its points was in the aperture and in view. Each segment's point is now checked before the closest is chosen, as before #2350, in one helper the click snap and the Tab list share. --- crates/engine/src/snap.rs | 39 ++++++++++--------- .../tests/it/measure_distance_snapping.rs | 21 +++++++++- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index b7bace5c6c..87159b643d 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -634,9 +634,9 @@ fn finish( } if osmode & mode::NEA != 0 { // The closest point of all nearby objects, whatever their drawing order. - let nb = nearest_points(near_prims, cursor, aperture, clip).into_iter().min_by(|a, b| a.dist(cursor).total_cmp(&b.dist(cursor))); - if let Some(p) = nb { - return Some((SnapHit::plain(mode::NEA, p), Rank { tier: 3, score: p.dist(cursor) })); + let nb = near_prims.iter().filter_map(|p| nearest_point(p, cursor, aperture, &visible)).min_by(|a, b| a.0.total_cmp(&b.0)); + if let Some((score, p)) = nb { + return Some((SnapHit::plain(mode::NEA, p), Rank { tier: 3, score })); } } None @@ -682,28 +682,31 @@ fn finish_all( out.push((h, Rank { tier: 2, score })); } if osmode & mode::NEA != 0 { - out.extend( - nearest_points(near_prims, cursor, aperture, clip).into_iter().map(|p| (SnapHit::plain(mode::NEA, p), Rank { tier: 3, score: p.dist(cursor) })), - ); + let near = near_prims.iter().filter_map(|p| nearest_point(p, cursor, aperture, &visible)); + out.extend(near.map(|(score, p)| (SnapHit::plain(mode::NEA, p), Rank { tier: 3, score }))); } out.sort_by(|a, b| a.1.cmp(&b.1)); out } -/// The point of each nearby primitive closest to `cursor`, within the aperture. -fn nearest_points(near_prims: &[Prim], cursor: Vec2, aperture: f64, clip: Option) -> Vec { - let visible = |p: Vec2| p.is_finite() && clip.is_none_or(|c| c.contains(p)); - let mut out = Vec::new(); - for p in near_prims { - let c = match p { - Prim::Circle(c) => Some(c.closest(cursor)), - _ => prim_segments(p).iter().map(|s| fix_circle(s).closest(cursor)).min_by(|a, b| a.dist(cursor).total_cmp(&b.dist(cursor))), - }; - if let Some(c) = c.filter(|c| visible(*c) && c.dist(cursor) <= aperture) { - out.push(c); +/// The point of `p` closest to `cursor` among its visible points within `aperture`, with its +/// distance: each segment's closest point is checked before the closest is chosen, so a curve +/// whose closest point is clipped away (outside a viewport) still offers the visible one. +fn nearest_point(p: &Prim, cursor: Vec2, aperture: f64, visible: &impl Fn(Vec2) -> bool) -> Option<(f64, Vec2)> { + let mut nb: Option<(f64, Vec2)> = None; + let mut consider = |c: Vec2| { + let dd = c.dist(cursor); + if visible(c) && dd <= aperture && nb.is_none_or(|(bd, _)| dd < bd) { + nb = Some((dd, c)); } + }; + for s in prim_segments(p) { + consider(fix_circle(&s).closest(cursor)); } - out + if let Prim::Circle(c) = p { + consider(c.closest(cursor)); + } + nb } /// The perpendicular and tangent points from the base point `base` (none without one), each diff --git a/crates/engine/tests/it/measure_distance_snapping.rs b/crates/engine/tests/it/measure_distance_snapping.rs index 30c313ad3a..576dbc3eb6 100644 --- a/crates/engine/tests/it/measure_distance_snapping.rs +++ b/crates/engine/tests/it/measure_distance_snapping.rs @@ -1,6 +1,6 @@ //! DIST snaps to the model geometry displayed in paper-space viewports (#516). -use cadcraft_engine::doc::{Block, Circle, Common, Drawing, Entity, EntityKind, Handle, Insert, Line, Space, Viewport}; +use cadcraft_engine::doc::{Block, Circle, Common, Drawing, Ellipse, Entity, EntityKind, Handle, Insert, Line, Space, Viewport}; use cadcraft_engine::geom::{Vec2, Vec3}; use cadcraft_engine::snap::{SnapCurve, SnapHit, mode, osnap}; use cadcraft_engine::{Input, Session}; @@ -389,3 +389,22 @@ fn malformed_and_paper_space_viewports_are_not_snap_sources() { assert!(osnap(&d, &paper, Vec2::new(95.1, 50.1), 0.5, mode::END, None, false).is_none()); } } + +/// Nearest on a curve that leaves the viewport: the curve's closest point to the cursor is outside +/// the viewport, another point of it within the aperture is inside, and Nearest snaps there. +#[test] +fn nearest_takes_the_visible_part_of_a_curve_crossing_the_viewport_edge() { + let (mut d, paper) = drawing(); + // The viewport shows model y up to 20. A tall ellipse peaks at (15, 20.1), just outside. + let ellipse = Ellipse { center: Vec3::new(15.0, 0.0, 0.0), major: Vec3::new(0.0, 20.1, 0.0), ratio: 0.1, start: 0.0, end: std::f64::consts::TAU }; + d.add(&Space::Model, Common::default(), EntityKind::Ellipse(ellipse)).unwrap(); + // The viewport's border is on a layer that is off, so it offers no Nearest of its own. + d.layers.push(cadcraft_engine::doc::Layer { name: "Border".into(), on: false, ..Default::default() }); + let vp = viewport(&d, &paper); + d.modify_entity(vp, |e| e.common.layer = "Border".into()).unwrap(); + // Model (15, 19.99): 0.11 from the peak, about 0.2 from where the ellipse comes back inside. + let cursor = Vec2::new(102.5, 59.995); + let hit = osnap(&d, &paper, cursor, 0.5, mode::NEA, None, false).expect("a visible nearest point"); + let model = hit.viewport.expect("seen through the viewport").point; + assert!(model.y <= 20.0 + 1e-9 && model.dist(Vec2::new(15.0, 19.99)) <= 1.0, "{hit:?}"); +} From a2f732118f975d061cf0d856266eaae6320c4cd9 Mon Sep 17 00:00:00 2001 From: Oliver Hagmann <268387159+ohagmann@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:43:12 -0700 Subject: [PATCH 14/30] Snap tests from #1673: Tab keeps each viewport's snap and every deferred snap Carried from #1673 onto the #2350 Tab list: overlapping viewports each offer their model point, the deferred tangent and perpendicular on one circle are both offered, and a click across spaces. That last test is inverted from #1673: with #2347's ranking a viewport Endpoint beats a paper-space Nearest that scores closer, as a snap point beats Nearest within one space; Tab starts at the click's snap and still reaches the Nearest. --- crates/engine/src/snap.rs | 11 +++++ .../tests/it/measure_distance_snapping.rs | 43 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 87159b643d..0e72e8f697 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -1402,6 +1402,17 @@ mod tests { assert_eq!(h.name, "Intersection"); } + /// Tab cycling sees every deferred snap within the aperture: on a circle with no base point, + /// its quadrant, then the deferred tangent and the deferred perpendicular at the same spot. + #[test] + fn osnap_all_ranks_every_candidate() { + let d = drawing(); + let all = osnap_all(&d, &Space::Model, Vec2::new(22.1, 0.1), 0.5, mode::QUA | mode::TAN | mode::PER, None, true); + let kinds: Vec<(u32, bool)> = all.iter().map(|h| (h.mode, h.deferred.is_some())).collect(); + assert_eq!(kinds, [(mode::QUA, false), (mode::TAN, true), (mode::PER, true)], "{all:?}"); + assert!(osnap_all(&d, &Space::Model, Vec2::new(50.0, 50.0), 0.5, mode::QUA | mode::TAN | mode::PER, None, true).is_empty()); + } + #[test] fn center_quadrant_tangent() { let d = drawing(); diff --git a/crates/engine/tests/it/measure_distance_snapping.rs b/crates/engine/tests/it/measure_distance_snapping.rs index 576dbc3eb6..0dcdb5b8f9 100644 --- a/crates/engine/tests/it/measure_distance_snapping.rs +++ b/crates/engine/tests/it/measure_distance_snapping.rs @@ -2,7 +2,8 @@ use cadcraft_engine::doc::{Block, Circle, Common, Drawing, Ellipse, Entity, EntityKind, Handle, Insert, Line, Space, Viewport}; use cadcraft_engine::geom::{Vec2, Vec3}; -use cadcraft_engine::snap::{SnapCurve, SnapHit, mode, osnap}; +use cadcraft_engine::pointmod::snap_candidates; +use cadcraft_engine::snap::{SnapCurve, SnapHit, mode, osnap, osnap_all}; use cadcraft_engine::{Input, Session}; use serde_json::json; @@ -278,6 +279,46 @@ fn clipped_endpoints_do_not_hide_a_visible_candidate() { assert!(osnap(&d, &paper, Vec2::new(110.11, 51.0), 0.2, mode::END, None, false).is_none()); } +/// Across spaces a click takes the viewport's Endpoint over a paper-space Nearest that scores +/// closer, as within one space a snap point beats Nearest. Tab starts at the click's snap and +/// still reaches the paper-space Nearest. +#[test] +fn a_viewport_endpoint_beats_a_closer_paper_space_nearest() { + let (mut d, paper) = drawing(); + // A paper-space line 0.3 left of the model endpoint (0, 0), which the viewport shows at (95, 50). + d.add(&paper, Common::default(), EntityKind::Line(Line { a: Vec3::new(94.7, 48.0, 0.0), b: Vec3::new(94.7, 52.0, 0.0) })).unwrap(); + let (cursor, modes) = (Vec2::new(94.8, 50.0), mode::END | mode::NEA); + let hit = osnap(&d, &paper, cursor, 0.5, modes, None, false).unwrap(); + assert!(hit.mode == mode::END && hit.viewport.is_some() && hit.point.near(Vec2::new(95.0, 50.0), 1e-9), "{hit:?}"); + let all = snap_candidates(&d, &paper, cursor, 0.5, modes, None, false); + assert_eq!(all.first(), Some(&hit), "Tab starts at the click's snap"); + assert!( + all.iter().any(|h| h.mode == mode::NEA && h.viewport.is_none() && h.point.near(Vec2::new(94.7, 50.0), 1e-9)), + "Tab reaches the paper-space Nearest: {all:?}" + ); +} + +/// Overlapping viewports can show different model points at one paper point; Tab offers each, +/// since DIST measures in the model units of the viewport picked. +#[test] +fn overlapping_viewports_each_offer_their_model_point() { + let (mut d, paper) = drawing(); + // This viewport shows the model endpoint (20, 0) at paper (100, 50), a second one over it (0, 0). + edit_viewport(&mut d, &paper, |vp| vp.view_center = Vec2::new(20.0, 0.0)); + let mut vp = match &d.entity(viewport(&d, &paper)).unwrap().kind { + EntityKind::Viewport(vp) => vp.clone(), + _ => panic!("viewport fixture"), + }; + vp.view_center = Vec2::new(0.0, 0.0); + vp.id = 3; + d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap(); + let all = osnap_all(&d, &paper, Vec2::new(100.05, 50.04), 0.5, mode::END, None, false); + let mut models: Vec = + all.iter().filter(|h| h.point.near(Vec2::new(100.0, 50.0), 1e-9)).filter_map(|h| h.viewport).map(|v| v.point).collect(); + models.sort_by(|a, b| a.x.total_cmp(&b.x)); + assert_eq!(models, [Vec2::new(0.0, 0.0), Vec2::new(20.0, 0.0)], "{all:?}"); +} + #[test] fn viewport_frozen_layers_do_not_hide_paper_space_geometry() { let (mut d, paper) = drawing(); From 080c96aa0667eb1251301d7326d85f73bbf04585 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:45:11 -0700 Subject: [PATCH 15/30] Tab: snaps seen through different viewports stay apart in the list The Tab list dropped a snap as a repeat when another had the same mode and paper point, so where two viewports overlap only one of their model points could be picked, and DIST measures in the model units of the viewport picked. A repeat now also has to come from the same viewport (and be deferred or not alike), in osnap_all and in snap_candidates. Makes overlapping_viewports_each_offer_their_model_point (from #1673) pass. --- crates/engine/src/pointmod.rs | 2 +- crates/engine/src/snap.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/pointmod.rs b/crates/engine/src/pointmod.rs index cd68852164..7410a2be52 100644 --- a/crates/engine/src/pointmod.rs +++ b/crates/engine/src/pointmod.rs @@ -150,7 +150,7 @@ pub fn snap_candidates_with_frozen( } let mut out: Vec = crate::snap::osnap_with_frozen(d, space, cursor, aperture, osmode, base, deferred, frozen).into_iter().collect(); for h in crate::snap::osnap_all_with_frozen(d, space, cursor, aperture, osmode, base, deferred, frozen) { - if !out.iter().any(|o| o.mode == h.mode && o.point.near(h.point, aperture * 1e-6)) { + if !out.iter().any(|o| o.same(&h, aperture)) { out.push(h); } } diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 0e72e8f697..b68eec264a 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -69,6 +69,17 @@ impl SnapHit { SnapHit { point, mode, name: name_of(mode), viewport: None, deferred: None } } + /// The same snap as `o`, for a Tab list without repeats: the same mode at the same point + /// (within a millionth of `aperture`), deferred or not alike, and from the same source (this + /// space, or one viewport). Overlapping viewports can show different model points at one paper + /// point; each stays a candidate, since DIST measures in the model units of the viewport picked. + pub(crate) fn same(&self, o: &SnapHit, aperture: f64) -> bool { + self.mode == o.mode + && self.deferred.is_some() == o.deferred.is_some() + && self.viewport.map(|v| v.viewport) == o.viewport.map(|v| v.viewport) + && self.point.near(o.point, aperture * 1e-6) + } + /// The command input a pick at this snap gives: a deferred snap or a plain point. pub fn input(&self) -> crate::Input { match self.deferred { @@ -411,7 +422,7 @@ pub fn osnap_all_with_frozen( if unique.len() >= MAX_CYCLE { break; } - if !unique.iter().any(|u| u.mode == h.mode && u.point.near(h.point, aperture * 1e-6)) { + if !unique.iter().any(|u| u.same(&h, aperture)) { unique.push(h); } } From 5bfba91aa8afa0ebf8d2155ef549e57709afdedc Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:47:22 -0700 Subject: [PATCH 16/30] Tab: every deferred tangent and perpendicular under the aperture The Tab list took the one deferred snap a click would, so with a circle under the cursor and no base point the deferred perpendicular could not be reached after the deferred tangent, nor a second curve's deferred snap. The list now has one deferred snap per curve and mode (ported from #1673), ranked after the snap points; the click still takes the nearest. Makes osnap_all_ranks_every_candidate (from #1673) pass. --- crates/engine/src/snap.rs | 49 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index b68eec264a..f845c94a29 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -655,7 +655,7 @@ fn finish( /// [`finish`], keeping every candidate with its [`Rank`], in the order [`finish`] prefers them: /// the snap points best first, then the perpendiculars and tangents on the objects under the -/// cursor and the centers found from their curves, then the deferred snap, then the nearest point +/// cursor and the centers found from their curves, then the deferred snaps, then the nearest point /// of each object nearby. #[allow(clippy::too_many_arguments)] fn finish_all( @@ -688,9 +688,9 @@ fn finish_all( .map(|(score, c)| (SnapHit::plain(mode::CEN, c), Rank { tier: 1, score })), ); let deferrable = if base.is_some() { osmode & mode::TAN } else { osmode }; - if deferred && let Some(h) = deferred_hit(near_prims, cursor, aperture, deferrable, clip) { - let score = h.point.dist(cursor); - out.push((h, Rank { tier: 2, score })); + if deferred { + let hits = deferred_hits(near_prims, cursor, aperture, deferrable, clip); + out.extend(hits.into_iter().map(|h| (h, Rank { tier: 2, score: h.point.dist(cursor) }))); } if osmode & mode::NEA != 0 { let near = near_prims.iter().filter_map(|p| nearest_point(p, cursor, aperture, &visible)); @@ -1140,6 +1140,47 @@ fn xform_prim(p: &Prim, m: &Mat3) -> Prim { } } +/// Every deferred tangent and perpendicular within `aperture` of `cursor`, for Tab: one per curve +/// and mode, in drawing order (the caller ranks them), so Tab can go from the tangent to the +/// perpendicular on the same circle, and to the deferred snap of each curve nearby. A click takes +/// the nearest one ([`deferred_hit`]). +fn deferred_hits(prims: &[Prim], cursor: Vec2, aperture: f64, osmode: u32, clip: Option) -> Vec { + let mut hits = Vec::new(); + if osmode & (mode::TAN | mode::PER) == 0 { + return hits; + } + for p in prims { + let curve = match p { + Prim::Circle(c) => SnapCurve::Circle { center: c.center, radius: c.radius }, + Prim::Seg(Segment::Arc { arc, .. }) => SnapCurve::Arc { center: arc.center, radius: arc.radius, start: arc.start, end: arc.end }, + Prim::Seg(Segment::Line(l)) => SnapCurve::Line { a: l.a, b: l.b }, + Prim::Infinite { base, dir, .. } => SnapCurve::Line { a: *base, b: *base + *dir }, + _ => continue, + }; + // Where the curve was picked: a circle's, an arc's or a segment's own span, an xline/ray + // anywhere. + let at = match curve { + SnapCurve::Circle { center, radius } => Circle::new(center, radius).closest(cursor), + SnapCurve::Arc { center, radius, start, end } => cadcraft_geom::Arc::new(center, radius, start, end).closest(cursor), + SnapCurve::Line { a, b } => { + let l = cadcraft_geom::Line::new(a, b); + if matches!(p, Prim::Seg(_)) { l.closest(cursor) } else { l.project(cursor) } + } + }; + if !(at.is_finite() && clip.is_none_or(|c| c.contains(at)) && at.dist(cursor) <= aperture) { + continue; + } + let modes: &[(u32, &'static str)] = match curve { + SnapCurve::Circle { .. } | SnapCurve::Arc { .. } => &[(mode::TAN, "Deferred Tangent"), (mode::PER, "Deferred Perpendicular")], + SnapCurve::Line { .. } => &[(mode::PER, "Deferred Perpendicular")], + }; + for &(m, name) in modes.iter().filter(|(m, _)| osmode & m != 0) { + hits.push(SnapHit { point: at, mode: m, name, viewport: None, deferred: Some(Deferred { mode: m, curve, at }) }); + } + } + hits +} + /// The nearest deferred tangent/perpendicular within `aperture` of `cursor`. fn deferred_hit(prims: &[Prim], cursor: Vec2, aperture: f64, osmode: u32, clip: Option) -> Option { let mut best: Option<(f64, SnapHit)> = None; From 6971715295430699fedeb6b00eed12004578b566 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:51:37 -0700 Subject: [PATCH 17/30] Tab: a base point that is not a number gives no candidates With a finite cursor and aperture, a NaN or infinite base passed the Tab list's guards and it still offered snaps, though the perpendicular and tangent points from such a base mean nothing (a viewport already skips it). osnap_all and snap_candidates now return none for it. --- crates/engine/src/pointmod.rs | 3 ++- crates/engine/src/snap.rs | 2 +- crates/engine/tests/it/snap_tab_cycling.rs | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/pointmod.rs b/crates/engine/src/pointmod.rs index 7410a2be52..f474cfb805 100644 --- a/crates/engine/src/pointmod.rs +++ b/crates/engine/src/pointmod.rs @@ -145,7 +145,8 @@ pub fn snap_candidates_with_frozen( deferred: bool, frozen: &[String], ) -> Vec { - if osmode & !mode::HATCH == 0 || osmode & mode::OFF != 0 { + // A base that is not a number would give meaningless perpendiculars and tangents. + if osmode & !mode::HATCH == 0 || osmode & mode::OFF != 0 || base.is_some_and(|b| !b.is_finite()) { return Vec::new(); } let mut out: Vec = crate::snap::osnap_with_frozen(d, space, cursor, aperture, osmode, base, deferred, frozen).into_iter().collect(); diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index f845c94a29..2530fa6222 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -390,7 +390,7 @@ pub fn osnap_all_with_frozen( deferred: bool, frozen: &[String], ) -> Vec { - if osmode == 0 || osmode & mode::OFF != 0 || !cursor.is_finite() || !(aperture.is_finite() && aperture > 0.0) { + if osmode == 0 || osmode & mode::OFF != 0 || !cursor.is_finite() || !(aperture.is_finite() && aperture > 0.0) || base.is_some_and(|b| !b.is_finite()) { return Vec::new(); } let ix = crate::spatial::index(d, space); diff --git a/crates/engine/tests/it/snap_tab_cycling.rs b/crates/engine/tests/it/snap_tab_cycling.rs index 45a21efea1..b5e2436bed 100644 --- a/crates/engine/tests/it/snap_tab_cycling.rs +++ b/crates/engine/tests/it/snap_tab_cycling.rs @@ -71,3 +71,19 @@ fn every_endpoint_under_the_aperture_is_offered_not_one_per_mode() { let first = snap_candidates(d, &Space::Model, Vec2::new(0.03, 0.0), 0.125, mode::END, None, false).first().map(|h| h.point); assert_eq!(first, cadcraft_engine::snap::osnap(d, &Space::Model, Vec2::new(0.03, 0.0), 0.125, mode::END, None, false).map(|h| h.point)); } + +/// A base point that is not a number gives no candidates, though the cursor is on an endpoint: the +/// perpendicular and tangent points from it would be meaningless, as a viewport already treats it. +#[test] +fn a_non_finite_base_gives_no_candidates() { + let mut s = Session::new(); + s.execute("line", &json!({ "points": [[0, 0], [10, 0]] })).unwrap(); + let d = s.doc().unwrap(); + let all = mode::END | mode::PER | mode::TAN | mode::NEA; + for base in [Vec2::new(f64::NAN, 1.0), Vec2::new(1.0, f64::INFINITY), Vec2::new(f64::NEG_INFINITY, f64::NAN)] { + assert!(snap_candidates(d, &Space::Model, Vec2::new(10.01, 0.0), 0.5, all, Some(base), false).is_empty(), "{base:?}"); + assert!(cadcraft_engine::snap::osnap_all(d, &Space::Model, Vec2::new(10.01, 0.0), 0.5, all, Some(base), true).is_empty(), "{base:?}"); + } + // A finite base still offers them. + assert!(!snap_candidates(d, &Space::Model, Vec2::new(10.01, 0.0), 0.5, all, Some(Vec2::new(5.0, 5.0)), false).is_empty()); +} From 0ca0af9026946955927eb705efe95515d1c336b0 Mon Sep 17 00:00:00 2001 From: Marco Arnulfo Date: Fri, 20 Nov 2026 17:57:59 -0700 Subject: [PATCH 18/30] Tab snap tests from #1408: moving away restarts the cycle, a click takes Tab's choice Carried from #1408's crates/ui-egui/tests/tab_snap_cycling.rs onto the #2350 Tab list: moving_the_cursor_away_starts_the_cycle_over and a_click_places_the_candidate_tab_chose, with their three-endpoint fixture. --- crates/ui-egui/tests/it/snap_tab_cycling.rs | 87 ++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/tests/it/snap_tab_cycling.rs b/crates/ui-egui/tests/it/snap_tab_cycling.rs index c7b4cd290f..e4e636fedd 100644 --- a/crates/ui-egui/tests/it/snap_tab_cycling.rs +++ b/crates/ui-egui/tests/it/snap_tab_cycling.rs @@ -2,9 +2,11 @@ //! each object nearby), not just the closest snap of each running mode, and comes back round. use cadcraft_engine::Session; +use cadcraft_engine::doc::{Common, Drawing, EntityKind, Line, Space}; +use cadcraft_engine::snap::mode; use cadcraft_geom::Vec2; use cadcraft_ui_egui::{CadApp, Services}; -use egui::{Event, vec2}; +use egui::{Event, Modifiers, PointerButton, Pos2, vec2}; use egui_kittest::Harness; use serde_json::json; @@ -49,3 +51,86 @@ fn tab_cycles_through_every_endpoint_under_the_aperture() { assert!(seen.iter().any(|q| q.near(want, 1e-9)), "{want:?} in {seen:?}"); } } + +/// Three endpoints near 10,0: 10,0 (the nearest to the cursor), 10.03,0 and 9.95,0. Endpoint is +/// the only running snap, so every candidate is an endpoint. +fn three_ends() -> Harness<'static, CadApp> { + let mut d = Drawing::new_imperial(); + for (a, b) in [((0.0, 0.0), (10.0, 0.0)), ((10.03, 0.0), (20.0, 0.0)), ((9.95, 0.0), (9.95, -5.0))] { + let line = Line { a: Vec2::new(a.0, a.1).to3(0.0), b: Vec2::new(b.0, b.1).to3(0.0) }; + d.add(&Space::Model, Common::default(), EntityKind::Line(line)).unwrap(); + } + let mut session = Session::empty(); + session.open_drawing(d, "Tab snap cycling", None); + session.execute("view.set", &json!({"center":[10,0],"height":8})).unwrap(); + session.settings.osmode = mode::END; + session.settings.snapmode = false; + session.settings.orthomode = false; + let mut app = CadApp::new(session, Services::default()); + app.canvas.zoom_pending = false; + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + |ui, app: &mut CadApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + app, + ); + h.run_steps(5); + h.state_mut().start("line"); + h.run_steps(2); + assert_eq!(h.state().session.running.as_ref().unwrap().id, "line"); + let ap = h.state().session.settings.aperture / h.state().canvas.xf.unwrap().scale; + assert!(ap > 0.07, "all three endpoints lie in the aperture ({ap})"); + h +} + +const CURSOR: Vec2 = Vec2::new(10.01, 0.0); + +fn hover(h: &mut Harness<'_, CadApp>, p: Vec2) -> Pos2 { + let pos = h.state().canvas.xf.unwrap().to_screen(p); + h.event(Event::PointerMoved(pos)); + h.run_steps(3); + pos +} + +/// Tab, as the command line receives it (`cmdline::capture_tab`). +fn tab(h: &mut Harness<'_, CadApp>) { + h.event(Event::Text("\t".into())); + h.run_steps(3); +} + +fn snapped(h: &Harness<'_, CadApp>) -> Vec2 { + let hit = h.state().canvas.snap.expect("a snap marker"); + assert_eq!(hit.mode, mode::END); + hit.point +} + +fn assert_at(got: Vec2, x: f64) { + assert!(got.near(Vec2::new(x, 0.0), 1e-9), "{got:?}, expected {x},0"); +} + +#[test] +fn moving_the_cursor_away_starts_the_cycle_over() { + let mut h = three_ends(); + hover(&mut h, CURSOR); + tab(&mut h); + assert_at(snapped(&h), 10.03); + hover(&mut h, Vec2::new(10.0, 2.0)); + assert!(h.state().canvas.snap.is_none()); + hover(&mut h, CURSOR); + assert_at(snapped(&h), 10.0); +} + +#[test] +fn a_click_places_the_candidate_tab_chose() { + let mut h = three_ends(); + let pos = hover(&mut h, CURSOR); + tab(&mut h); + assert_at(snapped(&h), 10.03); + for pressed in [true, false] { + h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.run_steps(2); + } + let base = h.state().session.current_prompt().and_then(|p| p.base).expect("LINE asks for the next point"); + assert_at(base, 10.03); +} From 9746b6999a4078a5ce7b9e4d718b62d4bc2bffab Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:58:24 -0700 Subject: [PATCH 19/30] Snap: rustfmt --- crates/engine/src/snap.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 2530fa6222..9555c127f7 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -390,7 +390,12 @@ pub fn osnap_all_with_frozen( deferred: bool, frozen: &[String], ) -> Vec { - if osmode == 0 || osmode & mode::OFF != 0 || !cursor.is_finite() || !(aperture.is_finite() && aperture > 0.0) || base.is_some_and(|b| !b.is_finite()) { + if osmode == 0 + || osmode & mode::OFF != 0 + || !cursor.is_finite() + || !(aperture.is_finite() && aperture > 0.0) + || base.is_some_and(|b| !b.is_finite()) + { return Vec::new(); } let ix = crate::spatial::index(d, space); @@ -444,7 +449,6 @@ fn collect_in( osmode: u32, frozen: &[String], ) -> Option<(Vec<(u32, Vec2)>, Vec)> { - let (mut cands, near_prims) = gather_in(d, space, ix, cursor, aperture, osmode, frozen)?; // Intersections between nearby primitives; Apparent Intersection also where their extensions // meet (lines extended, arcs as full circles: in 2D, the "apparent" crossing of objects @@ -816,7 +820,13 @@ struct FromBase { /// /// [`finish`] takes the object nearest the cursor; of several points on it (an arc's two /// antipodes, a circle's two tangents), the one nearest the cursor. -fn from_base_on_objects(found: &[FromBase], near_prims: &[Prim], cursor: Vec2, aperture: f64, visible: impl Fn(Vec2) -> bool) -> Vec<(SnapHit, Rank, f64)> { +fn from_base_on_objects( + found: &[FromBase], + near_prims: &[Prim], + cursor: Vec2, + aperture: f64, + visible: impl Fn(Vec2) -> bool, +) -> Vec<(SnapHit, Rank, f64)> { let mut out = Vec::new(); if found.is_empty() { return out; From ca90388ff3a70c8cd8249c7c0308d2077311a71f Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:23:04 -0700 Subject: [PATCH 20/30] OSMODE test: build each DXF variant from the clean export The second check added $OSMODE = 4133 to text that already had $OSMODE = 0, so the file carried both. Build it from the clean export and assert one. --- crates/engine/tests/it/osnap_opened_drawings.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/engine/tests/it/osnap_opened_drawings.rs b/crates/engine/tests/it/osnap_opened_drawings.rs index 9e6525114b..b97892ac43 100644 --- a/crates/engine/tests/it/osnap_opened_drawings.rs +++ b/crates/engine/tests/it/osnap_opened_drawings.rs @@ -87,8 +87,8 @@ fn with_osmode(text: &str, value: u32) -> String { #[test] fn a_dxf_with_osmode_0_keeps_the_running_snaps() { - let text = String::from_utf8(cadcraft_io::write(&drawing(), "snaps.dxf").unwrap()).unwrap(); - let text = with_osmode(&text, 0); + let clean = String::from_utf8(cadcraft_io::write(&drawing(), "snaps.dxf").unwrap()).unwrap(); + let text = with_osmode(&clean, 0); let d = cadcraft_io::read(text.as_bytes(), "snaps.dxf").unwrap(); let mut s = Session::new(); // OSMODE is the profile's: the user's own choice survives opening the file. @@ -98,7 +98,9 @@ fn a_dxf_with_osmode_0_keeps_the_running_snaps() { // Nor does a file change a profile without Center. let mut s = Session::new(); s.execute("setvar", &json!({ "name": "OSMODE", "value": mode::END })).unwrap(); - s.open_drawing(cadcraft_io::read(with_osmode(&text, DEFAULT).as_bytes(), "x.dxf").unwrap(), "x.dxf", None); + let text = with_osmode(&clean, DEFAULT); + assert_eq!(text.matches("$OSMODE").count(), 1, "one $OSMODE in the file"); + s.open_drawing(cadcraft_io::read(text.as_bytes(), "x.dxf").unwrap(), "x.dxf", None); assert_eq!(s.settings.osmode, mode::END); } From 472d3661ce19243e400f32890dcd2bd4cefe3b99 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:25:05 -0700 Subject: [PATCH 21/30] CIRCLE 3P TAN: solve picks in line with the picked circle's centre CIRCLE 3P 3,0 5,0 TAN on a unit circle at the origin found no circle: the picks were collinear, so the only Newton start lay on y = 0 with every target centre, and each step stayed on that line until the matrix went singular. With collinear picks, also start from circles on both sides of their line. --- crates/engine/src/cmd/curves.rs | 14 ++++++++++++++ crates/engine/tests/it/snap_overrides.rs | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/crates/engine/src/cmd/curves.rs b/crates/engine/src/cmd/curves.rs index 7d8b3ef6a6..51dad0e81e 100644 --- a/crates/engine/src/cmd/curves.rs +++ b/crates/engine/src/cmd/curves.rs @@ -355,6 +355,20 @@ pub fn ttt_where(objs: [(TanObj, Vec2); 3], ok: impl Fn(&Circle) -> bool) -> Opt starts.push([cen.x, cen.y, rad.max(1e-3)]); if let Some(c) = Circle::from_3_points(p1, p2, p3) { starts.push([c.center.x, c.center.y, c.radius]); + } else { + // The picks lie in one line. When the circles picked are centred on it too, every Newton + // step from a start on that line stays on it: start off it as well, on both sides, from + // the circle through the two picks farthest apart and a point beside them. + let (a, b) = [(p1, p2), (p1, p3), (p2, p3)].into_iter().max_by(|x, y| x.0.dist(x.1).total_cmp(&y.0.dist(y.1))).unwrap_or((p1, p3)); + let span = a.dist(b); + let n = (b - a).normalized().perp(); + if span.is_finite() && span > 0.0 && n.is_finite() { + for side in [1.0, -1.0] { + if let Some(c) = Circle::from_3_points(a, b, (a + b) / 2.0 + n * (span * side)) { + starts.push([c.center.x, c.center.y, c.radius]); + } + } + } } let mut best: Option<(f64, Circle)> = None; let scale = rad.max(p1.dist(p2)).max(1e-6); diff --git a/crates/engine/tests/it/snap_overrides.rs b/crates/engine/tests/it/snap_overrides.rs index 4fad12ba2f..95084dfaa7 100644 --- a/crates/engine/tests/it/snap_overrides.rs +++ b/crates/engine/tests/it/snap_overrides.rs @@ -227,3 +227,14 @@ fn tan_for_a_3p_circle_refuses_the_picked_circle_itself() { assert!(s.log.iter().any(|l| l.contains("Circle does not exist.")), "{:?}", s.log); assert_eq!(s.doc().unwrap().model.iter().filter(|e| matches!(e.kind, EntityKind::Circle(_))).count(), 1); } + +#[test] +fn tan_for_a_3p_circle_through_points_in_line_with_the_picked_circles_center() { + // Through 3,0 and 5,0 and tangent to the unit circle at the origin: the two points and that + // circle's center lie on one line, the circle that touches it does not (center 4,±√48, radius 7). + let mut s = Session::new(); + s.script("CIRCLE 0,0 1\nCIRCLE 3P 3,0 5,0 TAN 1,0\n").unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + let (c, r) = last_circle(&s); + assert!(near(Vec2::new(c.x, c.y.abs()), 4.0, 48f64.sqrt()) && (r - 7.0).abs() < 1e-9, "{c:?} r={r}"); +} From 71f4879f9c0bf1f2a5fe0d65c4c47972ca9de23e Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:27:03 -0700 Subject: [PATCH 22/30] Tab: keep deferred snaps of different curves at one point Two circles touching at the cursor each offer a deferred tangent at the same provisional point. SnapHit::same took them for one snap and dropped the second, so Tab could not pick the other circle. Compare the deferred curve. --- crates/engine/src/snap.rs | 11 +++++++---- crates/engine/tests/it/snap_tab_cycling.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index b687f5fbdf..3a7282f1f0 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -70,12 +70,15 @@ impl SnapHit { } /// The same snap as `o`, for a Tab list without repeats: the same mode at the same point - /// (within a millionth of `aperture`), deferred or not alike, and from the same source (this - /// space, or one viewport). Overlapping viewports can show different model points at one paper - /// point; each stays a candidate, since DIST measures in the model units of the viewport picked. + /// (within a millionth of `aperture`), deferred or not alike (and if deferred, on the same + /// curve), and from the same source (this space, or one viewport). Overlapping viewports can + /// show different model points at one paper point; each stays a candidate, since DIST + /// measures in the model units of the viewport picked. pub(crate) fn same(&self, o: &SnapHit, aperture: f64) -> bool { self.mode == o.mode - && self.deferred.is_some() == o.deferred.is_some() + // Deferred snaps on different curves at one provisional point stay apart: the line + // drawn from each depends on its curve. + && self.deferred.map(|d| d.curve) == o.deferred.map(|d| d.curve) && self.viewport.map(|v| v.viewport) == o.viewport.map(|v| v.viewport) && self.point.near(o.point, aperture * 1e-6) } diff --git a/crates/engine/tests/it/snap_tab_cycling.rs b/crates/engine/tests/it/snap_tab_cycling.rs index b5e2436bed..13fb96ddcd 100644 --- a/crates/engine/tests/it/snap_tab_cycling.rs +++ b/crates/engine/tests/it/snap_tab_cycling.rs @@ -87,3 +87,16 @@ fn a_non_finite_base_gives_no_candidates() { // A finite base still offers them. assert!(!snap_candidates(d, &Space::Model, Vec2::new(10.01, 0.0), 0.5, all, Some(Vec2::new(5.0, 5.0)), false).is_empty()); } + +#[test] +fn deferred_snaps_of_two_curves_at_one_point_are_both_offered() { + // Two circles touching at the origin: each offers its own deferred tangent there, and the + // line drawn from it depends on which circle it is. + let mut s = Session::new(); + s.script("CIRCLE 0,1 1\nCIRCLE 0,-2 2\n").unwrap(); + let d = s.doc().unwrap(); + let all = cadcraft_engine::snap::osnap_all(d, &Space::Model, Vec2::new(0.0, 0.1), 0.5, mode::TAN, None, true); + let curves: Vec<_> = all.iter().filter_map(|h| h.deferred.map(|f| f.curve)).collect(); + assert_eq!(curves.len(), 2, "{all:?}"); + assert_ne!(curves.first(), curves.get(1), "{all:?}"); +} From 0314c8bf2a04eb8fa878681fc67c965a7d861158 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:29:20 -0700 Subject: [PATCH 23/30] Snap: a twisted viewport offers its next snap when the best is off it In a twisted viewport the model clip is the box round the turned viewport. A perpendicular foot inside that box but off the viewport could win, and view.hit then rejected it, so the click got no snap from the viewport while Tab still offered a valid one. When the winner falls off the viewport, take the best of the ranked others that is on it; the extra ranking runs only then. --- crates/engine/src/snap.rs | 44 +++++++------------ .../tests/it/measure_distance_snapping.rs | 28 ++++++++++++ 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 3a7282f1f0..064ca31663 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -295,20 +295,22 @@ pub(crate) fn osnap_with_neighborhood( if !model_cursor.is_finite() || !(model_aperture.is_finite() && model_aperture > 0.0) || model_base.is_some_and(|p| !p.is_finite()) { continue; } - let hit = osnap_in( - d, - &model, - &model_ix, - model_cursor, - model_aperture, - osmode, - model_base, - deferred, - &view.viewport.frozen_layers, - Some(view.model_clip), - ) + let Some((cands, prims)) = collect_in(d, &model, &model_ix, model_cursor, model_aperture, osmode, &view.viewport.frozen_layers) + else { + continue; + }; + let clip = Some(view.model_clip); // The rank was found in model units: paper units are model units times the scale. - .and_then(|(h, r)| Some((view.hit(h)?, Rank { score: r.score * view.scale, ..r }))); + let project = |(h, r): (SnapHit, Rank)| Some((view.hit(h)?, Rank { score: r.score * view.scale, ..r })); + let first = finish(cands.clone(), &prims, model_cursor, model_aperture, osmode, model_base, deferred, clip); + // The model clip is the box round the viewport as the model sees it, larger than the + // viewport when it is twisted: a snap inside it can still fall off the viewport. Then the + // best of the others that is on it, as Tab ranks them. + let hit = first.and_then(|f| { + project(f).or_else(|| { + finish_all(cands, &prims, model_cursor, model_aperture, osmode, model_base, deferred, clip).into_iter().find_map(project) + }) + }); if let Some((hit, rank)) = hit && best.as_ref().is_none_or(|(_, b)| rank.beats(b)) { @@ -338,22 +340,6 @@ impl Rank { } } -#[allow(clippy::too_many_arguments)] -fn osnap_in( - d: &Drawing, - space: &Space, - ix: &Option>, - cursor: Vec2, - aperture: f64, - osmode: u32, - base: Option, - deferred: bool, - frozen: &[String], - clip: Option, -) -> Option<(SnapHit, Rank)> { - osnap_in_with_prims(d, space, ix, cursor, aperture, osmode, base, deferred, frozen, clip).and_then(|(hit, _)| hit) -} - #[allow(clippy::too_many_arguments)] fn osnap_in_with_prims( d: &Drawing, diff --git a/crates/engine/tests/it/measure_distance_snapping.rs b/crates/engine/tests/it/measure_distance_snapping.rs index 0dcdb5b8f9..02056a9af1 100644 --- a/crates/engine/tests/it/measure_distance_snapping.rs +++ b/crates/engine/tests/it/measure_distance_snapping.rs @@ -449,3 +449,31 @@ fn nearest_takes_the_visible_part_of_a_curve_crossing_the_viewport_edge() { let model = hit.viewport.expect("seen through the viewport").point; assert!(model.y <= 20.0 + 1e-9 && model.dist(Vec2::new(15.0, 19.99)) <= 1.0, "{hit:?}"); } + +#[test] +fn a_twisted_viewport_offers_the_visible_perpendicular_when_a_nearer_one_is_off_the_sheet() { + // A viewport twisted 45°, 20 square at 0,0 on the sheet, scale 1. Through it, a line along + // y = 0 under the cursor and one along x = 9.3 (sheet coordinates). From the base 12,3 the + // foot on the first, 12,0, is inside the turned model box but off the viewport; the foot on + // the second, 9.3,3, is on it. + let mut d = Drawing::new_imperial(); + let paper = Space::Paper("Layout1".into()); + let vp = Viewport { + center: Vec3::ZERO, + width: 20.0, + height: 20.0, + view_center: Vec2::ZERO, + view_height: 20.0, + id: 2, + twist: std::f64::consts::FRAC_PI_4, + ..Viewport::default() + }; + for (a, b) in [(Vec2::new(-9.0, 0.0), Vec2::new(30.0, 0.0)), (Vec2::new(9.3, -9.0), Vec2::new(9.3, 9.0))] { + let (a, b) = (vp.paper_to_model(a), vp.paper_to_model(b)); + d.add(&Space::Model, Common::default(), EntityKind::Line(Line { a: a.to3(0.0), b: b.to3(0.0) })).unwrap(); + } + d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap(); + let hit = osnap(&d, &paper, Vec2::new(9.0, 0.0), 0.5, mode::PER, Some(Vec2::new(12.0, 3.0)), false).expect("the visible foot"); + assert_eq!(hit.mode, mode::PER); + assert!(hit.point.near(Vec2::new(9.3, 3.0), 1e-9), "{hit:?}"); +} From c647cb4eb9a6741c78f525034f86be390eb1ca66 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:31:37 -0700 Subject: [PATCH 24/30] Snap: a perpendicular from an arc's centre stays on the arc From the centre every point of an arc is perpendicular. The snap passed the base as the pick, so it fell back to a point of the arc's circle (10,0 for a 90-180 degree arc) outside the sweep. Take the point of the arc nearest the cursor. --- crates/engine/src/snap.rs | 11 ++++++++--- crates/engine/tests/it/snap_curves.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 064ca31663..a3e03b7c95 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -133,7 +133,11 @@ impl SnapCurve { SnapCurve::Circle { center, radius } | SnapCurve::Arc { center, radius, .. } => { let u = (p - *center).normalized(); if u == Vec2::ZERO { - vec![Circle::new(*center, *radius).closest(picked)] + // On an arc, the point within its sweep. + vec![match *self { + SnapCurve::Arc { center, radius, start, end } => cadcraft_geom::Arc::new(center, radius, start, end).closest(picked), + _ => Circle::new(*center, *radius).closest(picked), + }] } else { [*center + u * *radius, *center - u * *radius].into_iter().filter(|q| self.contains(*q)).collect() } @@ -725,9 +729,10 @@ fn base_snaps(near_prims: &[Prim], osmode: u32, base: Option, cursor: Vec2 let pts = match p { Prim::Seg(Segment::Line(l)) => vec![l.project(bp)], // Both antipodes, filtered to the arc's sweep: a perpendicular in the gap is - // not offered, and the far side is still found. + // not offered, and the far side is still found. From the centre, the point of + // the arc under the cursor. Prim::Seg(Segment::Arc { arc, .. }) => { - SnapCurve::Arc { center: arc.center, radius: arc.radius, start: arc.start, end: arc.end }.perpendiculars(bp, bp) + SnapCurve::Arc { center: arc.center, radius: arc.radius, start: arc.start, end: arc.end }.perpendiculars(bp, cursor) } // Both antipodes too, so a pick on the far side of the circle snaps there // rather than across it. From the centre every point is perpendicular: the diff --git a/crates/engine/tests/it/snap_curves.rs b/crates/engine/tests/it/snap_curves.rs index ec0d0b422b..0d04181389 100644 --- a/crates/engine/tests/it/snap_curves.rs +++ b/crates/engine/tests/it/snap_curves.rs @@ -122,3 +122,15 @@ fn spline_midpoint_perpendicular_and_tangent() { let d = (sp.eval(i + 1e-6) - sp.eval(i - 1e-6)).normalized(); assert!(d.cross((q - base).normalized()).abs() < 1e-3, "the line from the base runs along the curve at {q:?}"); } + +#[test] +fn perpendicular_from_an_arcs_center_stays_on_the_arc() { + // From the center of an arc every point is perpendicular: the one under the cursor, never a + // point of its circle outside the sweep. + let mut s = Session::new(); + s.execute("arc", &serde_json::json!({"center": [0, 0], "radius": 10, "start": 90, "end": 180})).unwrap(); + let hit = snap::osnap(s.doc().unwrap(), &Space::Model, Vec2::new(-6.0, 8.0), 0.3, mode::PER, Some(Vec2::ZERO), false); + let (p, m) = hit.map(|h| (h.point, h.mode)).expect("a perpendicular on the arc"); + assert_eq!(m, mode::PER); + assert!(p.near(Vec2::new(-6.0, 8.0), 1e-9), "{p:?}"); +} From 0b2cfae274543d3b9b8c0eed25317b45f2922aac Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:33:14 -0700 Subject: [PATCH 25/30] Snap: Perpendicular to a ray needs the cursor on the ray The 'cursor is over this object' distance measured a ray as a line both ways, so a cursor behind the ray's start snapped to the foot on it. Measure to the ray's own half; an xline stays two-sided. --- crates/engine/src/snap.rs | 4 ++++ crates/engine/tests/it/snap_curves.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index a3e03b7c95..5cca576758 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -844,6 +844,10 @@ fn from_base_on_objects( /// The distance from `cursor` to the nearest point of `p`, measured as Nearest measures it. fn distance_to_prim(p: &Prim, cursor: Vec2) -> f64 { + // A ray runs one way from its start (an xline both ways, as its segment does). + if let Prim::Infinite { base, dir, ray: true } = p { + return (*base + *dir * (cursor - *base).dot(*dir).max(0.0)).dist(cursor); + } prim_segments(p).iter().map(|s| fix_circle(s).closest(cursor).dist(cursor)).fold(f64::INFINITY, f64::min) } diff --git a/crates/engine/tests/it/snap_curves.rs b/crates/engine/tests/it/snap_curves.rs index 0d04181389..7a8fd0da82 100644 --- a/crates/engine/tests/it/snap_curves.rs +++ b/crates/engine/tests/it/snap_curves.rs @@ -134,3 +134,16 @@ fn perpendicular_from_an_arcs_center_stays_on_the_arc() { assert_eq!(m, mode::PER); assert!(p.near(Vec2::new(-6.0, 8.0), 1e-9), "{p:?}"); } + +#[test] +fn perpendicular_to_a_ray_needs_the_cursor_on_the_ray() { + // A ray along +X from the origin: behind its start the cursor is over nothing. + let mut s = Session::new(); + s.execute("ray", &serde_json::json!({"base": [0, 0], "through": [10, 0]})).unwrap(); + let d = s.doc().unwrap(); + let base = Some(Vec2::new(5.0, 3.0)); + assert_eq!(snap::osnap(d, &Space::Model, Vec2::new(-2.0, 0.0), 0.5, mode::PER, base, false), None); + // Over the ray, the foot is found. + let hit = snap::osnap(d, &Space::Model, Vec2::new(2.0, 0.0), 0.5, mode::PER, base, false).expect("the foot on the ray"); + assert!(hit.point.near(Vec2::new(5.0, 0.0), 1e-9), "{hit:?}"); +} From f8769d96501296dec1341362acc1c1a71f8ca8f7 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 23 Nov 2026 12:33:39 -0700 Subject: [PATCH 26/30] Snap: rustfmt --- crates/engine/src/snap.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 5cca576758..1f0402a201 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -299,8 +299,7 @@ pub(crate) fn osnap_with_neighborhood( if !model_cursor.is_finite() || !(model_aperture.is_finite() && model_aperture > 0.0) || model_base.is_some_and(|p| !p.is_finite()) { continue; } - let Some((cands, prims)) = collect_in(d, &model, &model_ix, model_cursor, model_aperture, osmode, &view.viewport.frozen_layers) - else { + let Some((cands, prims)) = collect_in(d, &model, &model_ix, model_cursor, model_aperture, osmode, &view.viewport.frozen_layers) else { continue; }; let clip = Some(view.model_clip); @@ -311,9 +310,8 @@ pub(crate) fn osnap_with_neighborhood( // viewport when it is twisted: a snap inside it can still fall off the viewport. Then the // best of the others that is on it, as Tab ranks them. let hit = first.and_then(|f| { - project(f).or_else(|| { - finish_all(cands, &prims, model_cursor, model_aperture, osmode, model_base, deferred, clip).into_iter().find_map(project) - }) + project(f) + .or_else(|| finish_all(cands, &prims, model_cursor, model_aperture, osmode, model_base, deferred, clip).into_iter().find_map(project)) }); if let Some((hit, rank)) = hit && best.as_ref().is_none_or(|(_, b)| rank.beats(b)) From 334bcc3dc08644376aeec68a9aa5fa64d6c517ef Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 30 Nov 2026 13:01:37 -0700 Subject: [PATCH 27/30] Tab snap tests: install the headless framework hook the app's frame now needs --- crates/ui-egui/tests/it/snap_tab_cycling.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/tests/it/snap_tab_cycling.rs b/crates/ui-egui/tests/it/snap_tab_cycling.rs index e4e636fedd..57d44c4020 100644 --- a/crates/ui-egui/tests/it/snap_tab_cycling.rs +++ b/crates/ui-egui/tests/it/snap_tab_cycling.rs @@ -21,7 +21,7 @@ fn tab_cycles_through_every_endpoint_under_the_aperture() { s.execute("view.set", &json!({ "center": [0, 0], "height": 20 })).unwrap(); let mut app = CadApp::new(s, Services::default()); app.canvas.zoom_pending = false; - let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + let mut h = Harness::builder().with_context_setup(cadcraft_ui_egui::framework::install_headless).with_size(vec2(1600.0, 1000.0)).build_ui_state( |ui, app: &mut CadApp| { app.logic(ui.ctx()); app.ui(ui); @@ -68,7 +68,7 @@ fn three_ends() -> Harness<'static, CadApp> { session.settings.orthomode = false; let mut app = CadApp::new(session, Services::default()); app.canvas.zoom_pending = false; - let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + let mut h = Harness::builder().with_context_setup(cadcraft_ui_egui::framework::install_headless).with_size(vec2(1600.0, 1000.0)).build_ui_state( |ui, app: &mut CadApp| { app.logic(ui.ctx()); app.ui(ui); From 7aaee292778e0cf0cacfb0cadd34b39169a6527a Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 30 Nov 2026 13:24:05 -0700 Subject: [PATCH 28/30] Tab snap tests: send Tab as the key press the command line reads now --- crates/ui-egui/tests/it/snap_tab_cycling.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/tests/it/snap_tab_cycling.rs b/crates/ui-egui/tests/it/snap_tab_cycling.rs index 57d44c4020..29b9d4567e 100644 --- a/crates/ui-egui/tests/it/snap_tab_cycling.rs +++ b/crates/ui-egui/tests/it/snap_tab_cycling.rs @@ -44,7 +44,7 @@ fn tab_cycles_through_every_endpoint_under_the_aperture() { assert!(seen.first().is_some_and(|q| q.near(p, 1e-9)), "the fourth Tab comes back round"); } seen.push(p); - h.event(Event::Text("\t".into())); + h.key_press(egui::Key::Tab); h.run_steps(2); } for want in [Vec2::new(0.0, 0.0), Vec2::new(0.06, 0.05), Vec2::new(0.03, -0.06)] { @@ -95,7 +95,7 @@ fn hover(h: &mut Harness<'_, CadApp>, p: Vec2) -> Pos2 { /// Tab, as the command line receives it (`cmdline::capture_tab`). fn tab(h: &mut Harness<'_, CadApp>) { - h.event(Event::Text("\t".into())); + h.key_press(egui::Key::Tab); h.run_steps(3); } From adca169651f4ac001047e55a7a2c389c2931ed60 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 3 Dec 2026 10:50:34 +0700 Subject: [PATCH 29/30] Snap test from main: count every Endpoint through osnap_all_with_frozen, this branch's form of osnap_in --- crates/engine/src/snap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 1f6e3618c6..3ed8977ef5 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -1603,7 +1603,7 @@ mod tests { let frozen = ["vp".to_string()]; let end = |x: f64, y: f64| { let at = Vec2::new(x, y); - osnap_in(&d, &Space::Model, &None, at + Vec2::new(0.02, -0.01), 0.5, mode::END, None, false, &frozen, None) + osnap_all_with_frozen(&d, &Space::Model, at + Vec2::new(0.02, -0.01), 0.5, mode::END, None, false, &frozen) .into_iter() .any(|h| h.point.dist(at) < 1e-9) }; From 17e0c819676fb1ec2a2d0e90065cb58985e1369f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 3 Dec 2026 05:01:04 +0100 Subject: [PATCH 30/30] Center snap test: the viewport takes main's new fields (UCS, extra data) from their defaults --- crates/engine/tests/it/snap_center_on_curve.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/engine/tests/it/snap_center_on_curve.rs b/crates/engine/tests/it/snap_center_on_curve.rs index cbb551b305..eaa4768da3 100644 --- a/crates/engine/tests/it/snap_center_on_curve.rs +++ b/crates/engine/tests/it/snap_center_on_curve.rs @@ -185,6 +185,7 @@ fn a_viewport_center_keeps_its_curve_distance_against_paper_space() { clip: None, on: true, twist: 0.0, + ..Default::default() }; d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap(); // A small paper-space circle whose curve passes 0.3 from the cursor and whose center is