diff --git a/crates/engine/src/cmd/addons/pathtools/tangents.rs b/crates/engine/src/cmd/addons/pathtools/tangents.rs index e45e736109..e47c009062 100644 --- a/crates/engine/src/cmd/addons/pathtools/tangents.rs +++ b/crates/engine/src/cmd/addons/pathtools/tangents.rs @@ -31,7 +31,7 @@ pub(super) fn specs() -> Vec { "Common Tangents", ["Object", "Plug-ins", "Path Precision Tools"], None, - "{tangents?: \"external\" (both paths on the same side of each line) | \"internal\" (the lines that run between them) | \"all\" (\"all\"), centerline?: bool (false: true also adds the line joining the two centers, an ellipse's center or a path's center of area), ids?: [id, id] (default: the selection)} add the common tangent lines of two convex closed paths as separate open paths, each from where it touches the first path to where it touches the second (the whole stretch where a straight side lies along it), stroked with the current stroke color and weight (black when the stroke is None) and unfilled, directly above the upper of the two, as one undo step; the new lines are selected. An ellipse drawn with the Ellipse tool, turned or scaled, is measured as an exact ellipse; any other path must be closed, have one outline, bend the same way all around and have at most 10000 segments. Separate paths have two external and two internal tangents; overlapping paths only external ones; one path inside the other has none. Paths that touch, from outside or from inside, share one tangent there instead: a line centered on the point where they touch and as long as the narrower path is wide along it; paths that meet at a corner or along a shared stretch of outline get one such line, at the middle of the directions that touch both. Paths count as touching when the gap between them is less than a billionth of the larger of their sizes and the distance between their centers. One of the two may be a point (a path of one anchor): the lines then run from the point to where they touch the path, two when the point lies outside it (one that lies along a straight side covers the whole side), one when the point lies on its outline, that is, less than the touching tolerance from it, with the point's distance from the path's center in place of the distance between centers (centered on the point and as long as the path is wide along it, or the whole straight side the point lies on), none when it lies inside; every `tangents` value gives the same lines, counted as internal when `tangents` is \"internal\" and as external otherwise, and the centerline runs from the point to the path's center; two points are refused. When there is no tangent of the kind asked for, nothing changes and the result has a `warning` → {ids, external, internal, centerline (its id or null), warning?}", + "{tangents?: \"external\" (both paths on the same side of each line) | \"internal\" (the lines that run between them) | \"all\" (\"all\"), centerline?: bool (false: true also adds the line joining the two centers, an ellipse's center or a path's center of area), ids?: [id, id] (default: the selection)} add the common tangent lines of two convex closed paths as separate open paths, each from where it touches the first path to where it touches the second (the whole stretch where a straight side lies along it), stroked with the current stroke color and weight (black when the stroke is None) and unfilled, directly above the upper of the two, as one undo step; the new lines are selected. An ellipse drawn with the Ellipse tool, turned or scaled, is measured as an exact ellipse; any other path must be closed, have one outline, bend the same way all around and have at most 10000 segments. Separate paths have two external and two internal tangents; overlapping paths only external ones; one path inside the other has none. Paths that touch, from outside or from inside, share one tangent there instead: a line centered on the point where they touch and as long as the narrower path is wide along it; paths that meet at a corner or along a shared stretch of outline get one such line, at the middle of the directions that touch both. Paths count as touching when the gap between them is at most a billionth of the larger of their sizes and the distance between their centers. One of the two may be a point (a path of one anchor): the lines then run from the point to where they touch the path, two when the point lies outside it (one that lies along a straight side covers the whole side), one when the point lies on its outline, that is, at most the touching tolerance from it, with the point's distance from the path's center in place of the distance between centers (centered on the point and as long as the path is wide along it, or the whole straight side the point lies on), none when it lies inside; every `tangents` value gives the same lines, counted as internal when `tangents` is \"internal\" and as external otherwise, and the centerline runs from the point to the path's center; two points are refused. When there is no tangent of the kind asked for, nothing changes and the result has a `warning` → {ids, external, internal, centerline (its id or null), warning?}", has_selection, common_tangents )] diff --git a/crates/ui-egui/src/addons/pathtools/tests.rs b/crates/ui-egui/src/addons/pathtools/tests.rs index e714b85aa2..2506797f85 100644 --- a/crates/ui-egui/src/addons/pathtools/tests.rs +++ b/crates/ui-egui/src/addons/pathtools/tests.rs @@ -343,6 +343,24 @@ fn common_tangents_on_a_point_gives_the_same_lines_for_every_choice() { app.run("select.set", json!({"ids": [oval, dot]})).unwrap(); let steps = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len(); let count = |app: &VectorcraftApp| app.session.doc().unwrap().doc.node_count(); + // The end points of every two-anchor path in the document, rounded and sorted. + let lines = |app: &VectorcraftApp| { + let mut ends = Vec::new(); + app.session.doc().unwrap().doc.walk(|node| { + if let Some(path) = node.path_data() { + for sub in &path.subpaths { + if sub.anchors.len() == 2 { + let mut pair: Vec<(i64, i64)> = + sub.anchors.iter().map(|a| ((a.p.x * 1e6).round() as i64, (a.p.y * 1e6).round() as i64)).collect(); + pair.sort(); + ends.push(pair); + } + } + } + }); + ends.sort(); + ends + }; let (n, nodes) = (steps(&app), count(&app)); let open = |app: &mut VectorcraftApp| { let entries = menus::menu_entries(app); @@ -352,15 +370,26 @@ fn common_tangents_on_a_point_gives_the_same_lines_for_every_choice() { menus::invoke(app, &cmd, p); }; - open(&mut app); - crate::dialogs::set_field(app.ui.dialog.as_mut().unwrap(), "preview".into(), json!(true)); + // Each choice previews the same two lines, and OK with that choice keeps them as one step. + let mut first: Option>> = None; for (_, kind) in super::TANGENT_KINDS { - crate::dialogs::set_field(app.ui.dialog.as_mut().unwrap(), "tangents".into(), json!(kind)); + open(&mut app); + let d = app.ui.dialog.as_mut().unwrap(); + crate::dialogs::set_field(d, "preview".into(), json!(true)); + crate::dialogs::set_field(d, "tangents".into(), json!(kind)); painted_text(&mut app, |app, ui| crate::dialogs::show(app, ui.ctx())); assert_eq!(count(&app), nodes + 2, "{kind}: the two lines from the point"); + let previewed = lines(&app); + assert_eq!(previewed.len(), 2, "{kind}"); + let first = first.get_or_insert_with(|| previewed.clone()); + assert_eq!(&previewed, first, "{kind}: the same lines as the first choice"); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!((steps(&app), count(&app)), (n + 1, nodes + 2), "{kind}: one undo step"); + assert_eq!(&lines(&app), first, "{kind}: OK keeps the previewed lines"); + app.run("edit.undo", json!({})).unwrap(); + app.run("select.set", json!({"ids": [oval, dot]})).unwrap(); + assert_eq!((steps(&app), count(&app)), (n, nodes), "{kind}: undone"); } - crate::dialogs::confirm(&mut app).unwrap(); - assert_eq!((steps(&app), count(&app)), (n + 1, nodes + 2), "one undo step"); // A point inside the ellipse: nothing changes, and a message says why. let inside = point(&mut app, 220.0, 150.0); diff --git a/docs/mcp.md b/docs/mcp.md index 8fbc770ca7..7798170779 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -13417,12 +13417,12 @@ Commands: only. A path inside the other has none. Paths that touch, from outside or from inside, share one tangent there instead: a line centered on the point where they touch and as long as the narrower path is wide along it. Paths that meet at a corner or along a shared stretch of outline get one such line, at the middle of the directions that - touch both. Paths count as touching when the gap between them is less than the tolerance, a billionth of the larger + touch both. Paths count as touching when the gap between them is at most the tolerance, a billionth of the larger of their sizes and the distance between their centers. One of the two may be a point instead, a path of one anchor: the lines then run from the point to where they touch the path, two when the point lies outside it (one that lies along a straight side covers the whole side), one when the point lies on its outline (centered on the point and as long as the path is wide along it, or the whole straight side the point lies on), and none when it - lies inside. The point counts as on the outline when it is less than the touching tolerance from it, with the + lies inside. The point counts as on the outline when it is at most the touching tolerance from it, with the point's distance from the path's center in place of the distance between centers. Every `tangents` value gives the same lines, counted in `internal` when `tangents` is `internal` and in `external` otherwise; the centerline runs from the point to the path's center. Two points are refused with "select two closed paths". The lines are diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index cdcdc27ca8..8ef5dba907 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2778,7 +2778,7 @@ A VectorCraft addition, so no area score moves. Object › Plug-ins › Cutting ## Path Precision Tools add-on: Common Tangents (2026-11-15) -A VectorCraft addition, so no area score moves. Object › Plug-ins › Path Precision Tools › Common Tangents… (`addon.pathtools.commonTangents`) adds the common tangent lines of two convex closed paths ([tangent lines to circles](https://en.wikipedia.org/wiki/Tangent_lines_to_circles)) as separate open paths: external, internal or all, with the line joining the two centers if asked. The rest is VectorCraft's own: an ellipse drawn with the Ellipse tool, turned or scaled, is measured as an exact ellipse, and any other path must be closed, have one outline and bend the same way all around. Each line runs between the points where it touches the two paths. Separate paths have four tangents, overlapping paths only external ones (two for ellipses), and a path inside the other has none, in which case nothing changes and a message says why. Paths that touch, from outside or from inside, share one tangent there instead: a line centered on the point where they touch and as long as the narrower path is wide along it. Since 2026-11-18 one of the two may be a point (a path of one anchor): the lines run from the point to where they touch the path, two from a point outside it, one at a point on its outline or less than the touching tolerance from it (centered on the point, or covering the straight side it lies on), and none from a point inside, with a message; the centerline runs from the point to the path's center, and every Tangents choice gives the same lines. The lines take the current stroke and no fill; one undo step. The dialog has Preview. Tests: `addons::pathtools::tangents::tests` in `vectorcraft-pathops` (circles against the closed form, turned ellipses against a brute-force scan, nested, overlapping and touching circles, a convex Bézier path, flat sides, squares meeting at a corner, a curve touched beside an anchor, a point outside a turned ellipse, on a circle, inside it, beside a square and at its corner, on a turned outline, within the touching tolerance, refused outlines), `cmd::addons::pathtools::tangents::tests` in `vectorcraft-engine`, `common_tangents_previews_cancels_and_runs_on_ok` and `common_tangents_on_a_point_gives_the_same_lines_for_every_choice` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Path Precision Tools add-on. +A VectorCraft addition, so no area score moves. Object › Plug-ins › Path Precision Tools › Common Tangents… (`addon.pathtools.commonTangents`) adds the common tangent lines of two convex closed paths ([tangent lines to circles](https://en.wikipedia.org/wiki/Tangent_lines_to_circles)) as separate open paths: external, internal or all, with the line joining the two centers if asked. The rest is VectorCraft's own: an ellipse drawn with the Ellipse tool, turned or scaled, is measured as an exact ellipse, and any other path must be closed, have one outline and bend the same way all around. Each line runs between the points where it touches the two paths. Separate paths have four tangents, overlapping paths only external ones (two for ellipses), and a path inside the other has none, in which case nothing changes and a message says why. Paths that touch, from outside or from inside, share one tangent there instead: a line centered on the point where they touch and as long as the narrower path is wide along it. Since 2026-11-18 one of the two may be a point (a path of one anchor): the lines run from the point to where they touch the path, two from a point outside it, one at a point on its outline, or at most a billionth of the larger of the path's size and the point's distance from its center away from it (centered on the point, or covering the straight side it lies on), and none from a point inside, with a message; the centerline runs from the point to the path's center, and every Tangents choice gives the same lines. The lines take the current stroke and no fill; one undo step. The dialog has Preview. Tests: `addons::pathtools::tangents::tests` in `vectorcraft-pathops` (circles against the closed form, turned ellipses against a brute-force scan, nested, overlapping and touching circles, a convex Bézier path, flat sides, squares meeting at a corner, a curve touched beside an anchor, a point outside a turned ellipse, on a circle, inside it, beside a square and at its corner, on a turned outline, within the touching tolerance, refused outlines), `cmd::addons::pathtools::tangents::tests` in `vectorcraft-engine`, `common_tangents_previews_cancels_and_runs_on_ok` and `common_tangents_on_a_point_gives_the_same_lines_for_every_choice` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Path Precision Tools add-on. ## Path Precision Tools add-on: Divide into Dashes (2026-11-01)