From 53ec5af6c866e9201b88a583762f31144e7597bb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 10:28:37 -0800 Subject: [PATCH 1/3] Smooth Bridge: a refusal says why an object is not a circle Smooth Bridge only joins circles. Anything else in the selection gave "select two or more circles to bridge", the same message as for one circle. An ellipse drawn by dragging without Shift is a few tenths of a point off a circle and was refused with that message, which did not say which object was at fault or why. The refusal now names the first object that is not a circle and why: an ellipse whose width and height differ (draw it with Shift held, or give it equal width and height), a compound path (release it first), an object that is hidden or locked, or another object. The message shows on the status line while the dialog previews and after OK. --- .../engine/src/cmd/addons/pathtools/bridge.rs | 47 +++++++++++++++---- .../src/cmd/addons/pathtools/bridge/tests.rs | 34 ++++++++++++++ crates/ui-egui/src/addons/pathtools/bridge.rs | 23 +++++++++ docs/mcp.md | 4 +- 4 files changed, 99 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/cmd/addons/pathtools/bridge.rs b/crates/engine/src/cmd/addons/pathtools/bridge.rs index 457114f820..449853d683 100644 --- a/crates/engine/src/cmd/addons/pathtools/bridge.rs +++ b/crates/engine/src/cmd/addons/pathtools/bridge.rs @@ -3,7 +3,7 @@ //! the bridges connect, replacing the circles or added above them. use serde_json::{Value, json}; -use vectorcraft_doc::{Document, Node, NodeId, NodeKind}; +use vectorcraft_doc::{Document, LiveShape, Node, NodeId, NodeKind}; use vectorcraft_geom::PathData; use vectorcraft_pathops::addons::pathtools as pt; @@ -34,7 +34,7 @@ pub(super) fn specs() -> Vec { "Smooth Bridge", ["Object", "Plug-ins", "Path Precision Tools"], None, - "{radius?: % 1..1000 (100; the radius of each bridge's two arcs as a percentage of the smaller circle's radius: larger makes a wider, gentler bridge), gap?: pt 0..1000 (instead of radius: the arcs' radius is the smaller circle's radius plus this gap, so each arc stays this gap away from a circle of the smaller circle's size about the arc's center; for equal circles this gap apart that is where a third circle this gap from both sits, as in a triangular grid, so the channels around an empty place in such a grid are one width; giving both is an error), reach?: pt 0..10000 (10; with three or more circles: how far apart two circles' outlines may be for a bridge between them, overlapping ones included; two circles are bridged at any distance), keepOriginals?: bool (false: each outline replaces its circles, painted as the topmost of them; true: it goes directly above that circle and the circles stay), ids?: [id] (default: the selection; a group, other than a clipping group, gives the objects inside it)} join circles (paths whose outline is a circle, not hidden or locked) into metaball (aka meatball) shapes. Two circles become one closed outline: around each circle on its side away from the other, and along two concave arcs, one on each side, that touch both circles so the outline runs on smoothly into them. With three or more, every two circles within reach are bridged the same way, and the bridges that connect are united into one shape each (holes smaller than 1% of the smallest circle's area are filled); a pair within reach but too far apart for the radius gets no bridge, and so does one whose neck would be thinner than the precision its shape is united at, and a circle bridged to no other is left as it is. Overlapping and touching circles are joined too. One circle inside another (among three or more, any such pair within reach) is an error; so are two circles too far apart for the radius (the arcs would not reach both, or would cross), or three or more with no pair the arcs can join, which suggests a larger radius or gap when the largest one would bridge them; so are no two circles within reach, more than 2000 circles and more than 8000 bridges. One undo step; the outlines (and the circles left as they are) are selected → {ids, alone}, with {id} too for two circles", + "{radius?: % 1..1000 (100; the radius of each bridge's two arcs as a percentage of the smaller circle's radius: larger makes a wider, gentler bridge), gap?: pt 0..1000 (instead of radius: the arcs' radius is the smaller circle's radius plus this gap, so each arc stays this gap away from a circle of the smaller circle's size about the arc's center; for equal circles this gap apart that is where a third circle this gap from both sits, as in a triangular grid, so the channels around an empty place in such a grid are one width; giving both is an error), reach?: pt 0..10000 (10; with three or more circles: how far apart two circles' outlines may be for a bridge between them, overlapping ones included; two circles are bridged at any distance), keepOriginals?: bool (false: each outline replaces its circles, painted as the topmost of them; true: it goes directly above that circle and the circles stay), ids?: [id] (default: the selection; a group, other than a clipping group, gives the objects inside it)} join circles (paths whose outline is a circle, not hidden or locked) into metaball (aka meatball) shapes. Two circles become one closed outline: around each circle on its side away from the other, and along two concave arcs, one on each side, that touch both circles so the outline runs on smoothly into them. With three or more, every two circles within reach are bridged the same way, and the bridges that connect are united into one shape each (holes smaller than 1% of the smallest circle's area are filled); a pair within reach but too far apart for the radius gets no bridge, and so does one whose neck would be thinner than the precision its shape is united at, and a circle bridged to no other is left as it is. Overlapping and touching circles are joined too. An object that is not a circle is an error that says why (an ellipse whose width and height differ, a compound path, a hidden or locked object, or another object). One circle inside another (among three or more, any such pair within reach) is an error; so are two circles too far apart for the radius (the arcs would not reach both, or would cross), or three or more with no pair the arcs can join, which suggests a larger radius or gap when the largest one would bridge them; so are no two circles within reach, more than 2000 circles and more than 8000 bridges. One undo step; the outlines (and the circles left as they are) are selected → {ids, alone}, with {id} too for two circles", has_selection, bridge )] @@ -61,17 +61,30 @@ fn bridge(s: &mut Session, p: &Value) -> Result { if roots.len() > pt::MAX_BRIDGED_CIRCLES { return Err(bad(C, "select at most 2000 circles to bridge")); } - let circles: Vec<(NodeId, pt::Circle)> = { + // The circles, and why the first object that is not one is refused. + let (circles, why): (Vec<(NodeId, pt::Circle)>, Option<&str>) = { let d = &s.doc()?.doc; let editable = d.editable(); - d.paint_order(roots.iter().copied()) + let mut why = None; + let circles = d + .paint_order(roots.iter().copied()) .into_iter() - .filter_map(|id| match &d.node(id)?.kind { - NodeKind::Path { path, guide: false, clipping: false, .. } if editable(id) => Some((id, pt::circle_of(path)?)), - _ => None, + .filter_map(|id| { + let found = match &d.node(id)?.kind { + NodeKind::Path { path, guide: false, clipping: false, .. } if editable(id) => pt::circle_of(path).map(|c| (id, c)), + _ => None, + }; + if found.is_none() && why.is_none() { + why = Some(not_a_circle(d, id, editable(id))); + } + found }) - .collect() + .collect(); + (circles, why) }; + if let Some(why) = why { + return Err(bad(C, format!("select two or more circles to bridge: {why}"))); + } if circles.len() != roots.len() || circles.len() < 2 { return Err(bad(C, "select two or more circles to bridge")); } @@ -156,6 +169,24 @@ fn members(d: &Document, ids: &[NodeId]) -> Vec { out } +/// Why object `id`, which is not a circle the command bridges, is refused; `editable` says whether it can be +/// edited (not hidden or locked). +fn not_a_circle(d: &Document, id: NodeId, editable: bool) -> &'static str { + // A pie spanning the whole turn, or none of it, is the whole ellipse. + let whole = |(start, end): (f64, f64)| { + let span = (end - start).rem_euclid(360.0); + span < 1e-9 || 360.0 - span < 1e-9 + }; + match d.node(id).map(|n| &n.kind) { + _ if !editable => "a selected object is hidden or locked", + Some(NodeKind::Path { live: Some(live), guide: false, clipping: false, .. }) if matches!(**live, LiveShape::Ellipse { pie, .. } if whole(pie)) => { + "an ellipse whose width and height differ is not a circle: draw it with Shift held, or give it equal width and height" + } + Some(NodeKind::Compound { .. }) => "a compound path is not a circle: release it first", + _ => "a selected object is not a circle", + } +} + /// The ids of `circles` at indices `at`, in paint order (the circles are listed in paint order). fn roots_of(circles: &[(NodeId, pt::Circle)], at: &[usize]) -> Vec { at.iter().filter_map(|&i| circles.get(i)).map(|(id, _)| *id).collect() diff --git a/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs b/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs index 8409ac2be6..caaa0b1b42 100644 --- a/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs +++ b/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs @@ -173,6 +173,40 @@ fn far_apart_nested_and_other_objects_are_refused() { assert_eq!(s.doc().unwrap().history.undo.len(), steps, "nothing changed, no undo step"); } +#[test] +fn a_refusal_says_why_an_object_is_not_a_circle() { + let mut s = session(); + let a = circle(&mut s, 100.0, 100.0, 20.0); + let b = circle(&mut s, 160.0, 100.0, 20.0); + // A hand-drawn ellipse 1 pt taller than wide. + let oval = NodeId(s.execute("shape.ellipse", &json!({"x": 200, "y": 80, "width": 40, "height": 41})).unwrap()["id"].as_u64().unwrap()); + let square = NodeId(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap()); + let steps = s.doc().unwrap().history.undo.len(); + let e = err(&mut s, json!({"ids": [a.0, oval.0]})); + assert!( + e.ends_with( + "select two or more circles to bridge: an ellipse whose width and height differ is not a circle: draw it with Shift held, or give it equal width and height" + ), + "{e}" + ); + let e = err(&mut s, json!({"ids": [a.0, square.0]})); + assert!(e.ends_with("select two or more circles to bridge: a selected object is not a circle"), "{e}"); + let e = err(&mut s, json!({"ids": [a.0]})); + assert!(e.ends_with("select two or more circles to bridge"), "one circle: {e}"); + select(&mut s, &[b]); + s.execute("object.hide", &json!({})).unwrap(); + let e = err(&mut s, json!({"ids": [a.0, b.0]})); + assert!(e.ends_with("select two or more circles to bridge: a selected object is hidden or locked"), "{e}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(s.doc().unwrap().history.undo.len(), steps, "no undo step for a refusal"); + + select(&mut s, &[a, b]); + let compound = NodeId(s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap()); + let c = circle(&mut s, 300.0, 200.0, 20.0); + let e = err(&mut s, json!({"ids": [compound.0, c.0]})); + assert!(e.ends_with("select two or more circles to bridge: a compound path is not a circle: release it first"), "{e}"); +} + /// A 3 × 3 grid of circles of radius 10, 4 apart (centers 24 apart), in rows from (100, 100). fn grid(s: &mut Session) -> Vec { (0..9).map(|k| circle(s, 100.0 + 24.0 * (k % 3) as f64, 100.0 + 24.0 * (k / 3) as f64, 10.0)).collect() diff --git a/crates/ui-egui/src/addons/pathtools/bridge.rs b/crates/ui-egui/src/addons/pathtools/bridge.rs index 9cdf738b18..5ddeee621b 100644 --- a/crates/ui-egui/src/addons/pathtools/bridge.rs +++ b/crates/ui-egui/src/addons/pathtools/bridge.rs @@ -228,4 +228,27 @@ mod tests { let top: Vec = app.session.doc().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.id.0).collect(); assert_eq!(top, [ids[2], ids[3]], "one shape in the topmost joined circle's place, and the far circle"); } + + #[test] + fn the_status_line_says_why_an_ellipse_is_refused() { + use crate::tests::panel_harness::Panel; + + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + let a = circle(&mut app, 100.0, 10.0); + let oval = app.run("shape.ellipse", json!({"x": 130, "y": 90, "width": 20, "height": 21})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [a, oval]})).unwrap(); + let original = geometry(&app); + let mut panel = Panel::new(app, crate::tests::picks::dialogs); + let before = panel.app().session.doc().unwrap().history.undo.len(); + menus::invoke(&mut panel.app(), super::COMMAND, Value::Null); + panel.frame(); + let why = "an ellipse whose width and height differ is not a circle"; + assert!(panel.app().ui.status.contains(why), "the preview's refusal: {}", panel.app().ui.status); + panel.click("OK"); + panel.frame(); + assert!(panel.app().ui.status.contains(why), "OK's refusal: {}", panel.app().ui.status); + assert_eq!(geometry(&panel.app()), original); + assert_eq!(panel.app().session.doc().unwrap().history.undo.len(), before, "no undo step"); + } } diff --git a/docs/mcp.md b/docs/mcp.md index 7d8a3743ed..88a10b3ad0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -16854,7 +16854,9 @@ Commands: circle of the smaller circle's size about the arc's center. For equal circles that gap apart, that center is where a third circle the gap from both would sit, as in a triangular grid, so the channels around an empty place in such a grid are one width; in a square grid they are not. Giving both `radius` and `gap` is an error. Overlapping and - touching circles are joined at every radius. One circle inside the other is an error, and so are circles too far apart + touching circles are joined at every radius. An object that is not a circle is an error that says why: an ellipse whose + width and height differ, a compound path, an object that is hidden or locked, or another object. One circle inside the + other is an error, and so are circles too far apart for the radius or gap: the arcs would not reach both circles, or would cross before they do. The error suggests a larger radius or gap only when the largest (1,000% or 1,000 pt) would bridge the circles. The outline replaces the two circles, painted as the upper one (a plain path), unless `keepOriginals` is true: then it goes directly above the From 9a060cfbf7e5dfa9fb06e98aa8a66b873e65411d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 11:17:57 -0800 Subject: [PATCH 2/3] Smooth Bridge: a stretched circle is not called an ellipse of unequal width and height A transform that stretches an ellipse keeps its stored width and height, so a circle stretched into an oval still stores equal ones. The refusal now names unequal width and height only when the stored values differ, and gives the general message otherwise. docs/mcp.md notes that more than 2,000 objects are refused by the circle limit before any object is checked. --- crates/engine/src/cmd/addons/pathtools/bridge.rs | 4 +++- .../engine/src/cmd/addons/pathtools/bridge/tests.rs | 12 +++++++++++- docs/mcp.md | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/addons/pathtools/bridge.rs b/crates/engine/src/cmd/addons/pathtools/bridge.rs index 449853d683..ea4f940ab9 100644 --- a/crates/engine/src/cmd/addons/pathtools/bridge.rs +++ b/crates/engine/src/cmd/addons/pathtools/bridge.rs @@ -179,7 +179,9 @@ fn not_a_circle(d: &Document, id: NodeId, editable: bool) -> &'static str { }; match d.node(id).map(|n| &n.kind) { _ if !editable => "a selected object is hidden or locked", - Some(NodeKind::Path { live: Some(live), guide: false, clipping: false, .. }) if matches!(**live, LiveShape::Ellipse { pie, .. } if whole(pie)) => { + // A transform that stretches an ellipse leaves its stored width and height as they were, so one stored with + // equal width and height gets the general message. + Some(NodeKind::Path { live: Some(live), guide: false, clipping: false, .. }) if matches!(**live, LiveShape::Ellipse { w, h, pie, .. } if whole(pie) && w != h) => { "an ellipse whose width and height differ is not a circle: draw it with Shift held, or give it equal width and height" } Some(NodeKind::Compound { .. }) => "a compound path is not a circle: release it first", diff --git a/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs b/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs index caaa0b1b42..f9b9ea23ef 100644 --- a/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs +++ b/crates/engine/src/cmd/addons/pathtools/bridge/tests.rs @@ -2,7 +2,7 @@ //! gap, many circles joined to their neighbors within reach, and what it refuses. use serde_json::{Value, json}; -use vectorcraft_doc::{NodeId, NodeKind}; +use vectorcraft_doc::{LiveShape, NodeId, NodeKind}; use vectorcraft_geom::kurbo::Shape; use crate::Session; @@ -181,6 +181,8 @@ fn a_refusal_says_why_an_object_is_not_a_circle() { // A hand-drawn ellipse 1 pt taller than wide. let oval = NodeId(s.execute("shape.ellipse", &json!({"x": 200, "y": 80, "width": 40, "height": 41})).unwrap()["id"].as_u64().unwrap()); let square = NodeId(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap()); + let stretched = circle(&mut s, 300.0, 100.0, 20.0); + s.execute("object.transform", &json!({"ids": [stretched.0], "matrix": [2.0, 0.0, 0.0, 1.0, 0.0, 0.0]})).unwrap(); let steps = s.doc().unwrap().history.undo.len(); let e = err(&mut s, json!({"ids": [a.0, oval.0]})); assert!( @@ -191,6 +193,14 @@ fn a_refusal_says_why_an_object_is_not_a_circle() { ); let e = err(&mut s, json!({"ids": [a.0, square.0]})); assert!(e.ends_with("select two or more circles to bridge: a selected object is not a circle"), "{e}"); + // A circle stretched by a transform keeps its equal stored width and height, so it is not called unequal. + let equal = match s.doc().unwrap().doc.node(stretched).map(|n| &n.kind) { + Some(NodeKind::Path { live: Some(live), .. }) => matches!(**live, LiveShape::Ellipse { w, h, .. } if w == h), + _ => false, + }; + assert!(equal, "the stretched circle keeps a live ellipse of equal width and height"); + let e = err(&mut s, json!({"ids": [a.0, stretched.0]})); + assert!(e.ends_with("select two or more circles to bridge: a selected object is not a circle"), "{e}"); let e = err(&mut s, json!({"ids": [a.0]})); assert!(e.ends_with("select two or more circles to bridge"), "one circle: {e}"); select(&mut s, &[b]); diff --git a/docs/mcp.md b/docs/mcp.md index 88a10b3ad0..3797b2b3f6 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -16855,7 +16855,9 @@ Commands: third circle the gap from both would sit, as in a triangular grid, so the channels around an empty place in such a grid are one width; in a square grid they are not. Giving both `radius` and `gap` is an error. Overlapping and touching circles are joined at every radius. An object that is not a circle is an error that says why: an ellipse whose - width and height differ, a compound path, an object that is hidden or locked, or another object. One circle inside the + width and height differ, a compound path, an object that is hidden or locked, or another object. More than 2,000 + objects (with groups counted as the objects inside them) are refused as more than 2,000 circles before any of them is + checked, so that error does not say which object is not a circle. One circle inside the other is an error, and so are circles too far apart for the radius or gap: the arcs would not reach both circles, or would cross before they do. The error suggests a larger radius or gap only when the largest (1,000% or 1,000 pt) would bridge the circles. The outline replaces the two From 0c722fbf2a6b9561a7597be6697242951797b5c4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 11:53:03 -0800 Subject: [PATCH 3/3] Docs: a clipping group counts as one object toward the Smooth Bridge limit docs/mcp.md said every group counts as the objects inside it toward the 2,000-object limit. The command expands only groups other than clipping groups (bridge.rs, the clip: false arm), so a clipping group counts as one object, which is not a circle. --- docs/mcp.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/mcp.md b/docs/mcp.md index 32e0a0617b..033bdf6bc5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -16867,7 +16867,8 @@ Commands: grid are one width; in a square grid they are not. Giving both `radius` and `gap` is an error. Overlapping and touching circles are joined at every radius. An object that is not a circle is an error that says why: an ellipse whose width and height differ, a compound path, an object that is hidden or locked, or another object. More than 2,000 - objects (with groups counted as the objects inside them) are refused as more than 2,000 circles before any of them is + objects (with each group other than a clipping group counted as the objects inside it, and a clipping group as one + object, which is not a circle) are refused as more than 2,000 circles before any of them is checked, so that error does not say which object is not a circle. One circle inside the other is an error, and so are circles too far apart for the radius or gap: the arcs would not reach both circles, or would cross before they do. The error suggests a