From e60afb9ea365c7b6844a5cc53a3d6d16976d486e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 15:28:58 -0800 Subject: [PATCH] Path Precision Tools: the Tangent Circle Tool leaves out a circle that would reach past the canvas A circle tangent to two segments near the canvas edge could show in the preview and then fail on release, because `shape.circleThroughPoints` refuses a circle that reaches more than 4,000,000 pt from the origin. The tool's check of the three points now goes through `circle::circle_of`, which applies the same bounds, so such a circle counts as no circle: the note shows, a click draws nothing and the first segment stays picked. --- crates/tools/src/addons/tangent_circle.rs | 43 +++++++++++++++++++++-- docs/mcp.md | 4 +-- docs/target-app-parity.md | 2 +- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/crates/tools/src/addons/tangent_circle.rs b/crates/tools/src/addons/tangent_circle.rs index a8d24d8853..1870d20b3b 100644 --- a/crates/tools/src/addons/tangent_circle.rs +++ b/crates/tools/src/addons/tangent_circle.rs @@ -155,7 +155,8 @@ fn round_step(least: f64) -> f64 { /// Draw circle `c`: through three points spread around it, with `shape.circleThroughPoints`, which /// leaves it where it is with Align New Objects to Pixel Grid on, so that it stays tangent. None /// when the three points do not give the circle back to within `tol` (a circle too small for its -/// distance from the origin, or too large, in floating point). +/// distance from the origin, or too large, in floating point), or when the circle would reach past +/// the canvas ([`crate::circle::circle_of`]), which the command refuses. fn draw(c: &SegmentCircle, tol: f64) -> Option { let (at, r) = (c.circle.center, c.circle.radius); let points: Vec = [90.0f64, 210.0, 330.0] @@ -165,7 +166,7 @@ fn draw(c: &SegmentCircle, tol: f64) -> Option { Point::new(at.x + r * k, at.y + r * s) }) .collect(); - let (back, rb) = vectorcraft_geom::shapes::circle_through(points[0], points[1], points[2])?; + let (back, rb) = crate::circle::circle_of(&points)?; if !(back.distance(at) <= tol && (rb - r).abs() <= tol) { return None; } @@ -425,7 +426,7 @@ impl Tool for TangentCircleTool { mod tests { use super::*; use crate::testutil::*; - use vectorcraft_doc::{Appearance, Document, Node, Selection}; + use vectorcraft_doc::{Appearance, Document, MAX_COORD, Node, Selection}; use vectorcraft_geom::{PathData, SubPath}; /// Two open lines, (100, 100)–(300, 100) and (100, 140)–(300, 140), and an L from (100, 300) @@ -717,4 +718,40 @@ mod tests { .collect(); assert!(matches!(segments[..], [n] if n < 100), "{segments:?}"); } + + #[test] + fn a_circle_that_would_reach_past_the_canvas_is_not_offered() { + // Two lines 40 pt apart ending at the canvas edge, x = 4,000,000: a click at x the first gives + // the circle of radius 20 around (x, 120), whose right side is at x + 20. + let mut d = Document::new(500.0, 500.0); + let l = d.layers[0].id; + for y in [100.0, 140.0] { + let id = d.alloc_id(); + let pts = [Point::new(MAX_COORD - 100.0, y), Point::new(MAX_COORD, y)]; + d.insert(Some(l), 0, Node::path(id, PathData::single(SubPath::polyline(&pts, false)), Appearance::default_art())).unwrap(); + } + let (sel, p) = (Selection::default(), paint()); + let cx = cx(&d, &sel, &p); + let mut t = TangentCircleTool::default(); + // Past the edge by 5 pt: the note shows, and a click draws nothing. + let x = MAX_COORD - 15.0; + t.pointer(&cx, &ev(PointerKind::Down, x, 100.0)); + t.pointer(&cx, &ev(PointerKind::Up, x, 100.0)); + t.pointer(&cx, &ev(PointerKind::Move, x, 140.0)); + assert!(t.found.is_none() && t.looked, "{:?}", t.found); + assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == NO_CIRCLE))); + t.pointer(&cx, &ev(PointerKind::Down, x, 140.0)); + assert!(t.pointer(&cx, &ev(PointerKind::Up, x, 140.0)).is_empty(), "nothing drawn"); + assert!(t.first.is_some(), "the first segment stays for another try"); + // Its right side 1 pt inside the edge: drawn. + let x = MAX_COORD - 21.0; + t.key(&cx, ToolKey::Escape, Mods::default()); + t.pointer(&cx, &ev(PointerKind::Down, x, 100.0)); + t.pointer(&cx, &ev(PointerKind::Up, x, 100.0)); + t.pointer(&cx, &ev(PointerKind::Down, x, 140.0)); + let released = up(&mut t, &cx, &ev(PointerKind::Up, x, 140.0)); + let (bx, by, w, h) = drawn(&released); + assert!((bx - (x - 20.0)).abs() < 1e-3 && (by - 100.0).abs() < 1e-3 && (w - 40.0).abs() < 1e-3 && (h - 40.0).abs() < 1e-3, "{released:?}"); + assert!(bx + w <= MAX_COORD, "{released:?}"); + } } diff --git a/docs/mcp.md b/docs/mcp.md index e7abf476a9..3b62792440 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14493,8 +14493,8 @@ Tools: outside it with a point on it (within a millionth of its radius); it never crosses the first segment, and it touches the two segments at different points. The circle is a new ellipse with the current paint, drawn through three of its points with `shape.circleThroughPoints` so that Align New Objects to Pixel Grid leaves it in place, one - undo step. A circle too small or too large for its three points to give it back in floating point counts as no - circle. Shift pressed or let go during a click counts at the release. With no circle the note shows, a click draws + undo step. A circle too small or too large for its three points to give it back in floating point, or one that + would reach past the canvas (4,000,000 pt from the origin), counts as no circle. Shift pressed or let go during a click counts at the release. With no circle the note shows, a click draws nothing and the first segment stays picked; it also stays when drawing the circle fails or the press on the second segment is canceled (a canceled touch). Escape, an edit, Undo or Redo outside the tool, or another document forgets the first segment. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 57ac87a396..a244132592 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2990,7 +2990,7 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov ## Path Precision Tools add-on: Tangent Circle Tool (2026-11-17) -A VectorCraft addition, so no area score moves. The Tangent Circle Tool (`tangentCircle`; Object › Plug-ins › Path Precision Tools and the All Tools drawer) draws a circle on two clicked path segments: tangent to the first at the point clicked (its center on the normal there) and touching the second segment or one beside it on its subpath, the touch nearest the pointer winning. Shift gives the circle the tool's radius, and a drag from the second segment sets the radius to the drag's length (Shift: steps of 1, 2 or 5 times a power of 10 pt, at least 4 screen pixels; Cmd/Ctrl: a tenth of the movement); with a radius the circle may touch the first segment anywhere along it. Before the click the circle shows with its center, radii and radius, or a note says there is none. The circles are found by sampling the distance to the second segments along the first segment's normal (or along the first segment, for a radius) and taking the places where it equals the radius (samples, bisection where it crosses, and a search where it only touches). Left out are circles whose nearest point of the second segments is not on the circle (within a millionth of the radius: where the first segment turns back on itself the distance jumps past the radius without a touch), circles that cross the first segment, circles that touch both segments at one point, circles without a finite radius above 0, and circles too small or too large for three of their points to give them back in floating point; a circle found twice (the same center, touching the first segment at the same point) is kept once. The circle is a new ellipse with the current paint, one undo step; the first segment stays picked until it is drawn, also when drawing fails or the press is canceled. Tests: `tangent_circle::tests` in `vectorcraft-pathops` (parallel and crossing lines, a curved second segment, a corner's fillet, lines twice the radius apart, a touch between the places tried, the ends of a line with its handles on its anchors, a circle that crosses the first segment, a first segment that turns back, no circle), `addons::tangent_circle::tests` in `vectorcraft-tools` (two clicks, Shift and the radius option, a drag with Shift and Cmd/Ctrl, no circle and Escape, a canceled press, a circle its three points cannot draw), the session test for a failed draw in `vectorcraft-engine` and the Path Precision Tools menu, options, drawer and catalog tests in `vectorcraft-ui-egui`. Commands: `docs/mcp.md` › Path Precision Tools add-on. +A VectorCraft addition, so no area score moves. The Tangent Circle Tool (`tangentCircle`; Object › Plug-ins › Path Precision Tools and the All Tools drawer) draws a circle on two clicked path segments: tangent to the first at the point clicked (its center on the normal there) and touching the second segment or one beside it on its subpath, the touch nearest the pointer winning. Shift gives the circle the tool's radius, and a drag from the second segment sets the radius to the drag's length (Shift: steps of 1, 2 or 5 times a power of 10 pt, at least 4 screen pixels; Cmd/Ctrl: a tenth of the movement); with a radius the circle may touch the first segment anywhere along it. Before the click the circle shows with its center, radii and radius, or a note says there is none. The circles are found by sampling the distance to the second segments along the first segment's normal (or along the first segment, for a radius) and taking the places where it equals the radius (samples, bisection where it crosses, and a search where it only touches). Left out are circles whose nearest point of the second segments is not on the circle (within a millionth of the radius: where the first segment turns back on itself the distance jumps past the radius without a touch), circles that cross the first segment, circles that touch both segments at one point, circles without a finite radius above 0, circles too small or too large for three of their points to give them back in floating point, and circles that would reach past the canvas; a circle found twice (the same center, touching the first segment at the same point) is kept once. The circle is a new ellipse with the current paint, one undo step; the first segment stays picked until it is drawn, also when drawing fails or the press is canceled. Tests: `tangent_circle::tests` in `vectorcraft-pathops` (parallel and crossing lines, a curved second segment, a corner's fillet, lines twice the radius apart, a touch between the places tried, the ends of a line with its handles on its anchors, a circle that crosses the first segment, a first segment that turns back, no circle), `addons::tangent_circle::tests` in `vectorcraft-tools` (two clicks, Shift and the radius option, a drag with Shift and Cmd/Ctrl, no circle and Escape, a canceled press, a circle its three points cannot draw, a circle past the canvas), the session test for a failed draw in `vectorcraft-engine` and the Path Precision Tools menu, options, drawer and catalog tests in `vectorcraft-ui-egui`. Commands: `docs/mcp.md` › Path Precision Tools add-on. ## Path Precision Tools add-on: Trim at Crossings (2026-11-13)