Path Precision Tools: Smooth Bridge suggests a larger radius only when it bridges among the other circles

With three or more circles and no pair that can be bridged, the error
suggested a larger radius or gap when the largest one bridged a single
pair on its own, even when that pair's neck was still too thin to unite
among the other circles. The suggestion now uses the same rules as the
many-circle bridge (`bridges_any` in `vectorcraft-pathops`).

The command's params text, `docs/mcp.md` and `docs/ui-parity.md` now say
that a pair within reach also gets no bridge when its neck would be
thinner than the precision its shape is united at.
This commit is contained in:
dotCooCoo
2026-11-15 21:50:20 -08:00
parent 3050baff96
commit 4781fac16e
6 changed files with 82 additions and 47 deletions
@@ -34,7 +34,7 @@ pub(super) fn specs() -> Vec<CommandSpec> {
"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)} 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 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)} 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",
has_selection,
bridge
)]
@@ -80,7 +80,7 @@ fn bridge(s: &mut Session, p: &Value) -> Result<Value> {
let (shapes, alone): (Vec<(Vec<NodeId>, PathData)>, Vec<NodeId>) = match only.as_slice() {
[a, b] => match pt::smooth_bridge(*a, *b, arc.between(*a, *b)) {
Ok(sp) => (vec![(roots_of(&circles, &[0, 1]), PathData::single(sp))], vec![]),
Err(e) => return Err(refusal(e, arc, *a, *b)),
Err(e) => return Err(refusal(e, arc, |largest| pt::smooth_bridge(*a, *b, largest.between(*a, *b)).is_ok())),
},
_ => {
let made = pt::bridge_many(&only, arc, reach).map_err(|e| match e {
@@ -88,10 +88,9 @@ fn bridge(s: &mut Session, p: &Value) -> Result<Value> {
pt::ManyError::TooManyBridges => bad(C, "that makes too many bridges (at most 8000): lower the reach"),
pt::ManyError::NoneInReach => bad(C, "no two circles are within reach: raise the reach"),
pt::ManyError::TooComplex => bad(C, "the bridged circles are too complex to unite"),
pt::ManyError::Pair(i, j, e) => match (only.get(i), only.get(j)) {
(Some(a), Some(b)) => refusal(e, arc, *a, *b),
_ => bad(C, "select two or more circles to bridge"),
},
// Under the many-circle rules: a pair the largest radius or gap bridges on its own
// can still have a neck too thin to unite among the others.
pt::ManyError::Pair(_, _, e) => refusal(e, arc, |largest| pt::bridges_any(&only, largest, reach)),
pt::ManyError::Bad => bad(C, "select two or more circles to bridge"),
})?;
let shapes = made.joined.into_iter().map(|j| (roots_of(&circles, &j.members), j.outline)).collect();
@@ -146,14 +145,14 @@ fn roots_of(circles: &[(NodeId, pt::Circle)], at: &[usize]) -> Vec<NodeId> {
at.iter().filter_map(|&i| circles.get(i)).map(|(id, _)| *id).collect()
}
/// The error for circles `a` and `b` that arcs of `arc` can't bridge. A larger radius or gap
/// bridges circles a smaller one cannot, so it suggests one only when the largest allowed would.
fn refusal(e: pt::BridgeError, arc: pt::ArcRadius, a: pt::Circle, b: pt::Circle) -> EngineError {
/// The error for circles that arcs of `arc` can't bridge. A larger radius or gap bridges circles a
/// smaller one cannot, so it suggests one only when `bridges` says the largest allowed would.
fn refusal(e: pt::BridgeError, arc: pt::ArcRadius, bridges: impl FnOnce(pt::ArcRadius) -> bool) -> EngineError {
let largest = match arc {
pt::ArcRadius::Share(_) => pt::ArcRadius::Share(RADII.1 / 100.0),
pt::ArcRadius::Gap(_) => pt::ArcRadius::Gap(GAPS.1),
};
let would = pt::smooth_bridge(a, b, largest.between(a, b)).is_ok();
let would = e == pt::BridgeError::TooFar && bridges(largest);
match (e, arc, would) {
(pt::BridgeError::Inside, ..) => bad(C, "one circle is inside the other"),
(pt::BridgeError::TooFar, pt::ArcRadius::Share(_), true) => bad(C, "the circles are too far apart for this radius: raise the radius"),
@@ -292,6 +292,23 @@ fn many_circle_and_gap_refusals() {
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "nothing changed, no undo step");
}
#[test]
fn a_larger_radius_is_suggested_only_when_it_bridges_among_the_other_circles() {
let mut s = session();
// Centers 91.65 apart: the largest radius (1000%, 100 pt) bridges these two on their own, but
// with a neck about 0.0007 pt wide, too thin to unite among three or more circles.
let a = circle(&mut s, 20.0, 100.0, 10.0);
let b = circle(&mut s, 111.65, 100.0, 10.0);
let far = circle(&mut s, 380.0, 100.0, 10.0);
assert!(s.execute(BRIDGE, &json!({"ids": [a.0, b.0], "radius": 1000})).is_ok());
s.execute("edit.undo", &json!({})).unwrap();
assert!(err(&mut s, json!({"ids": [a.0, b.0]})).ends_with("too far apart for this radius: raise the radius"));
for radius in [100, 1000] {
let e = err(&mut s, json!({"ids": [a.0, b.0, far.0], "radius": radius, "reach": 100}));
assert!(e.ends_with("the circles are too far apart for this radius"), "{e}");
}
}
#[test]
fn too_many_circles_or_bridges_are_refused() {
let mut s = session();
+1 -1
View File
@@ -28,7 +28,7 @@ use kurbo::{CubicBez, ParamCurve, ParamCurveArclen, ParamCurveNearest, Point, Ve
use vectorcraft_geom::{Anchor, AnchorKind, PathData, SubPath};
pub use bridge::{
ArcRadius, BridgeError, Bridged, Circle, Joined, MAX_BRIDGED_CIRCLES, MAX_BRIDGES, ManyError, bridge_many, circle_of, smooth_bridge,
ArcRadius, BridgeError, Bridged, Circle, Joined, MAX_BRIDGED_CIRCLES, MAX_BRIDGES, ManyError, bridge_many, bridges_any, circle_of, smooth_bridge,
};
pub use crossings::{MAX_CROSSED_BY_SEGMENTS, MAX_CROSSING_SEGMENTS, Place, Work, crossings, crossings_on, crossings_on_within, insert_at};
pub use dashes::{DashSpec, Piece, divide_dashes};
+50 -32
View File
@@ -232,38 +232,7 @@ pub enum ManyError {
/// too far apart for the arcs gets no bridge; a circle bridged to no other is left alone. One
/// circle inside another is an error, and so is no pair that the arcs can join.
pub fn bridge_many(circles: &[Circle], arc: ArcRadius, reach: f64) -> Result<Bridged, ManyError> {
if circles.len() > MAX_BRIDGED_CIRCLES {
return Err(ManyError::TooManyCircles);
}
let fine = |c: &Circle| c.center.x.is_finite() && c.center.y.is_finite() && c.radius.is_finite() && c.radius > 0.0;
if !(reach.is_finite() && reach >= 0.0) || !circles.iter().all(fine) {
return Err(ManyError::Bad);
}
let (mut pairs, mut too_far) = pairs_within(circles, reach, arc)?;
// Each set of connected circles, under its lowest index, is united at a precision fine enough
// for its smallest circle. A neck narrower than twice that would not survive the union, so its
// pair gets no bridge; that can split a set and make its precision coarser, so the sets are
// found again until no neck is dropped.
let (roots, precision) = loop {
let mut parent: Vec<usize> = (0..circles.len()).collect();
for &((i, j), _) in &pairs {
let (ri, rj) = (root(&mut parent, i), root(&mut parent, j));
parent[ri.max(rj)] = ri.min(rj);
}
let roots: Vec<usize> = (0..circles.len()).map(|i| root(&mut parent, i)).collect();
let mut precision = vec![DEFAULT_PRECISION; circles.len()];
for (&r, c) in roots.iter().zip(circles) {
precision[r] = precision[r].min(c.radius * 1e-3);
}
let thin = |&((i, _), waist): &(Pair, f64)| waist < 2.0 * precision[roots[i]];
if !pairs.iter().any(thin) {
break (roots, precision);
}
for &(pair, _) in pairs.iter().filter(|&p| thin(p)) {
too_far = Some(too_far.map_or(pair, |t| t.min(pair)));
}
pairs.retain(|p| !thin(p));
};
let (pairs, too_far, roots, precision) = bridgeable(circles, arc, reach)?;
match (pairs.is_empty(), too_far) {
(true, Some((i, j))) => return Err(ManyError::Pair(i, j, BridgeError::TooFar)),
(true, None) => return Err(ManyError::NoneInReach),
@@ -305,6 +274,55 @@ pub fn bridge_many(circles: &[Circle], arc: ArcRadius, reach: f64) -> Result<Bri
Ok(out)
}
/// Whether [`bridge_many`] would bridge at least one pair of `circles` with arcs of `arc` and
/// `reach`, under the same rules (a neck too thin for its shape's precision included), without
/// making the bridges or uniting them.
pub fn bridges_any(circles: &[Circle], arc: ArcRadius, reach: f64) -> bool {
bridgeable(circles, arc, reach).is_ok_and(|(pairs, ..)| !pairs.is_empty())
}
/// What [`bridgeable`] finds: the pairs [`bridge_many`] bridges with their necks' widths, the
/// lowest pair within reach that it can't bridge, each circle's set (its lowest index) and each
/// set's precision, under its lowest index.
type Bridgeable = (Vec<(Pair, f64)>, Option<Pair>, Vec<usize>, Vec<f64>);
/// The pairs of `circles` that [`bridge_many`] bridges, and how it sorts them into sets.
fn bridgeable(circles: &[Circle], arc: ArcRadius, reach: f64) -> Result<Bridgeable, ManyError> {
if circles.len() > MAX_BRIDGED_CIRCLES {
return Err(ManyError::TooManyCircles);
}
let fine = |c: &Circle| c.center.x.is_finite() && c.center.y.is_finite() && c.radius.is_finite() && c.radius > 0.0;
if !(reach.is_finite() && reach >= 0.0) || !circles.iter().all(fine) {
return Err(ManyError::Bad);
}
let (mut pairs, mut too_far) = pairs_within(circles, reach, arc)?;
// Each set of connected circles, under its lowest index, is united at a precision fine enough
// for its smallest circle. A neck narrower than twice that would not survive the union, so its
// pair gets no bridge; that can split a set and make its precision coarser, so the sets are
// found again until no neck is dropped.
let (roots, precision) = loop {
let mut parent: Vec<usize> = (0..circles.len()).collect();
for &((i, j), _) in &pairs {
let (ri, rj) = (root(&mut parent, i), root(&mut parent, j));
parent[ri.max(rj)] = ri.min(rj);
}
let roots: Vec<usize> = (0..circles.len()).map(|i| root(&mut parent, i)).collect();
let mut precision = vec![DEFAULT_PRECISION; circles.len()];
for (&r, c) in roots.iter().zip(circles) {
precision[r] = precision[r].min(c.radius * 1e-3);
}
let thin = |&((i, _), waist): &(Pair, f64)| waist < 2.0 * precision[roots[i]];
if !pairs.iter().any(thin) {
break (roots, precision);
}
for &(pair, _) in pairs.iter().filter(|&p| thin(p)) {
too_far = Some(too_far.map_or(pair, |t| t.min(pair)));
}
pairs.retain(|p| !thin(p));
};
Ok((pairs, too_far, roots, precision))
}
/// Two circles' indices, the lower first.
type Pair = (usize, usize);
/// What [`pairs_within`] finds: the pairs the arcs can bridge, each with its neck's width, and the
+4 -3
View File
@@ -12324,11 +12324,12 @@ Commands:
With three or more circles, every two whose outlines are at most `reach` apart (0 to 10,000 pt, 10 by default;
overlapping ones included) are bridged the same way, and the bridges that connect are united into one shape each,
which can have holes where bridges enclose space; holes smaller than 1% of the smallest circle's area are filled. A
pair within reach but too far apart for the radius or gap gets no bridge. Each shape replaces its circles, painted as
pair within reach but too far apart for the radius or gap gets no bridge, and so does a pair whose neck would be
thinner than the precision its shape is united at. Each shape replaces its circles, painted as
the topmost of them and in its place, or with `keepOriginals` goes directly above that circle. A circle bridged to no
other stays as it is. The shapes and the circles left as they are are selected. It is an error when any pair within
reach has one circle inside the other, when no pair within reach can be bridged (with the same suggestion of a larger
radius or gap), when no two circles are within reach, and above 2,000 circles or 8,000 bridges. → `{ids, alone}`:
reach has one circle inside the other, when no pair within reach can be bridged (suggesting a larger radius or gap
only when the largest would bridge a pair of them under these rules), when no two circles are within reach, and above 2,000 circles or 8,000 bridges. → `{ids, alone}`:
the shapes and the circles left as they are, with `id` as well for two circles. Smooth Bridge… opens a dialog
(`ui.menuDialog {command}`, kind `smoothBridge`) with Constant Gap (a Gap field in place of the Radius field in
percent), Reach (unavailable with two circles selected), Keep Originals and Preview.
+1 -1
View File
@@ -487,7 +487,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Set Corners… (also a button in the Anchor Inspector's Corners section: Radius in any unit, Corner kind, Anchors: All, Odd-Numbered or Even-Numbered, counted from each path's first anchor; Angle: from … to …°, only the corners whose sides meet at an angle in that range; Preview) cuts corners on the chosen anchors of every selected path, one undo step | done | #5546, #5545; `addon.pathtools.cornerSet` (`every`, `minAngle`, `maxAngle`), `crates/ui-egui/src/addons/pathtools/set_corners.rs` and their tests; not a feature of the reference app, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Trim at Crossings Tool (in the All Tools drawer under the add-on's heading, in neither toolbar as shipped, no shortcut) removes stretches of paths between the places where they are crossed, on any editable path, selected or not: a click removes the stretch under the pointer, a drag every stretch its rectangle touches, an Alt-drag every stretch its freehand line crosses; one undo step each; Escape during a drag removes nothing; hovering shows in red the stretch a click would remove, and a drag that reaches few paths shows what its release would remove | done | `addon.pathtools.trim` (in `crates/engine/src/cmd/addons/pathtools/trim.rs`), `crates/tools/src/addons/trim.rs` and their tests; not a feature of the reference app, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Expand Dashes into Paths turns each selected path's dashed stroke into separate open paths, one per dash, laid out as the stroke draws them (pattern, offset, Align Dashes to Corners and Path Ends), each keeping the stroke with the dashes off; one undo step | done | #4922; `addon.pathtools.expandDashes` (in `crates/engine/src/cmd/addons/pathtools.rs`, using the renderer's dash layout) and its tests; not a feature of the reference app, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Smooth Bridge… (Radius as a percentage of the smaller circle's radius, or with Constant Gap that radius plus a gap; Reach; Keep Originals; Preview) joins two selected circles into one outline with two concave arcs that touch both circles, or three or more each to the others within reach, united where the bridges connect, in place of the circles or above them; one undo step | done | `addon.pathtools.bridge`, `crates/pathops/src/addons/pathtools/bridge.rs`, `crates/ui-egui/src/addons/pathtools/bridge.rs` and their tests; a VectorCraft addition, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Smooth Bridge… (Radius as a percentage of the smaller circle's radius, or with Constant Gap that radius plus a gap; Reach; Keep Originals; Preview) joins two selected circles into one outline with two concave arcs that touch both circles, or three or more each to the others within reach, united where the bridges connect, in place of the circles or above them (a pair within reach gets no bridge when its arcs would not reach both circles or would cross, or when its neck would be thinner than the precision its shape is united at; a circle bridged to no other stays as it is); one undo step | done | `addon.pathtools.bridge`, `crates/pathops/src/addons/pathtools/bridge.rs`, `crates/ui-egui/src/addons/pathtools/bridge.rs` and their tests; a VectorCraft addition, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Tangent Circle… draws the circles that touch two selected paths or compound paths at a radius, or three of them, each touching the outlines without crossing them; Radius (two shapes), a Circle menu (All or one by number) and Preview; one undo step | done | `addon.pathtools.tangentCircle` (in `crates/engine/src/cmd/addons/pathtools/tangent_circle.rs`, geometry in `crates/pathops/src/addons/pathtools/tangent_circle.rs`) and its tests; a VectorCraft addition, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Effect › Path Effects lists its live effects (Dashes to Geometry, Add Anchors, Extend Path, Close Path, Smooth Anchors, Retract Handles, Reverse Direction, Simplify Anchors, Split at Anchors), each with the effect dialog's live Preview except Reverse Direction, which has no options, and listed in the Appearance panel like any effect | done | `addon.path.*`, `crates/effects/src/addons/path.rs`, `crates/ui-egui/src/addons/pathtools.rs` and their tests; not a feature of the reference app, so it is not scored |
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools selects its four tools (Anchor Eraser Brush, Extend Path, Measure & Inspect, Parametric Shape), which the All Tools drawer lists under their own heading but neither toolbar shows as shipped, opens the Anchor Inspector panel (the selected anchor's X/Y and handle lengths and angles as fields; Make Smooth, Make Corner, Equalize Handles, Remove Points Keep Shape, Add Points, the three ways to close) and the Parametric Shape panel (kind, count, W/H, rotation, the kind's own values and corner radius of the selected parametric shape, or of the tool's next one), and runs Add Points at / Split at Crossings and Convert to Parametric Shape; the Parametric Shape Tool draws ten re-editable kinds from the centre (↑/↓ and ←/→ change their numbers while dragging) and edits a selected one with handles; a double-click on the brush or Extend Path tool opens its options | done | `addon.pathtools.*`, `crates/tools/src/addons/`, `crates/ui-egui/src/addons/pathtools.rs`, `crates/ui-egui/src/addons/pathtools/shape.rs` and their tests; not a feature of the reference app, so it is not scored |