From 3a32a8c600dc69c12b7f5d3fd2cda45cc5439fcf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 13:27:15 -0800 Subject: [PATCH] Smooth Bridge: count the bridge limit after thin necks are dropped Bridging many circles refused a selection with more than 8000 pairs within reach before the necks too thin for the shape's precision were dropped, so a selection that leaves fewer than 8000 bridges was refused. The 8000 limit now counts the pairs that are left; the bound on the candidate pairs to check stays. The progress doc no longer says two circles are bridged at any distance: Reach does not limit them, but the radius can still be too small to bridge them. --- crates/pathops/src/addons/pathtools/bridge.rs | 28 +++++++++++++++---- docs/target-app-parity.md | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/pathops/src/addons/pathtools/bridge.rs b/crates/pathops/src/addons/pathtools/bridge.rs index f0afa31dc8..2b2fd9512e 100644 --- a/crates/pathops/src/addons/pathtools/bridge.rs +++ b/crates/pathops/src/addons/pathtools/bridge.rs @@ -217,7 +217,9 @@ pub struct Bridged { pub enum ManyError { /// More than [`MAX_BRIDGED_CIRCLES`] circles. TooManyCircles, - /// More than [`MAX_BRIDGES`] pairs of circles within reach that the arcs can bridge. + /// More than [`MAX_BRIDGES`] pairs of circles to bridge: within reach, near enough for the + /// arcs and with a neck wide enough for the shape's precision. Also more than nine times as many + /// pairs within reach to check. TooManyBridges, /// No two circles are within reach of each other. NoneInReach, @@ -324,6 +326,9 @@ fn bridgeable(circles: &[Circle], arc: ArcRadius, reach: f64) -> Result MAX_BRIDGES { + return Err(ManyError::TooManyBridges); + } Ok((pairs, too_far, roots, precision)) } @@ -377,16 +382,15 @@ fn pairs_within(circles: &[Circle], reach: f64, arc: ArcRadius) -> Result 9 * MAX_BRIDGES { return Err(ManyError::TooManyBridges); } } + // Saturated cells can list a pair twice. pairs.sort_unstable_by_key(|&(pair, _)| pair); pairs.dedup_by_key(|&mut (pair, _)| pair); - if pairs.len() > MAX_BRIDGES { - return Err(ManyError::TooManyBridges); - } Ok((pairs, too_far)) } @@ -793,6 +797,20 @@ mod tests { assert_eq!(bridge_many(&[circle(f64::INFINITY, 0.0, 1.0), far[0]], ArcRadius::Share(1.0), 1.0), Err(ManyError::Bad)); } + #[test] + fn the_bridge_limit_counts_the_necks_left_after_thin_ones_are_dropped() { + // Two columns of 65 nearly coincident circles: 8,385 pairs within reach that the arcs can + // bridge, but the 4,225 between the columns are thinner than the precision allows. + let column = |x: f64| (0..65).map(move |k| circle(x, 0.001 * k as f64, 10.0)); + let circles: Vec = column(0.0).chain(column(34.6409)).collect(); + let (pairs, too_far) = pairs_within(&circles, 15.0, ArcRadius::Share(1.0)).unwrap(); + assert_eq!((pairs.len(), too_far), (8385, None)); + let (pairs, ..) = bridgeable(&circles, ArcRadius::Share(1.0), 15.0).unwrap(); + assert_eq!(pairs.len(), 4160); + assert!(pairs.iter().all(|&((i, j), _)| (i < 65) == (j < 65))); + assert!(bridges_any(&circles, ArcRadius::Share(1.0), 15.0)); + } + #[test] fn huge_circles_bridge_with_finite_anchors_or_are_refused() { // Squaring these lengths overflows f64. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 641d87bdcc..08b7f615bf 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2847,7 +2847,7 @@ A trim reads the selection through a set and changes it once at the end, instead A VectorCraft addition, so no area score moves. Object › Plug-ins › Path Precision Tools › Smooth Bridge… (`addon.pathtools.bridge`) joins two selected circles into one closed outline, like two drops of liquid pulling apart: the outline goes around each circle on its side away from the other and along two concave arcs, one on each side, each touching both circles from outside, so the outline runs on smoothly from each circle into the bridge and every anchor is smooth. The arcs' radius is a percentage of the smaller circle's radius (1 to 1000%, 100% by default); a larger radius makes a wider, gentler bridge, and circles farther apart make a narrower one. Overlapping and touching circles are joined at every radius; one circle inside the other, or circles too far apart for the radius (the arcs would not reach both circles, or would cross), is refused with a message, which suggests a larger radius only when one up to 1000% would bridge them. The outline replaces the two circles, painted as the upper one, or with Keep Originals goes directly above the upper circle and the circles stay. One undo step; the dialog previews on the canvas. Tests: `bridge::tests` in `vectorcraft-pathops` (equal and unequal circles, overlapping and touching ones, unequal ones at large radii, the neck's width, the arcs tangent to both circles at every anchor, far apart and nested circles refused, circles told from other paths), `bridge::tests` in `cmd::addons::pathtools` in `vectorcraft-engine` (the outline in place of the circles or above them, one undo step, the radius, unequal overlapping circles up to the largest radius, refused selections and parameters with and without a larger radius suggested, locked and hidden circles), `smooth_bridge_opens_its_dialog_previews_and_runs_on_ok` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Path Precision Tools add-on. -Constant Gap sets the arcs' radius to the smaller circle's radius plus a gap in points (`gap`), so each arc stays that gap from a circle of the smaller circle's size about the arc's center: in a triangular grid of equal circles that gap apart, the channels around an empty place are one width. With three or more circles selected, every two whose outlines are within Reach (`reach`, 10 pt by default) are bridged, the bridges that connect are united into one shape each (holes included, except those smaller than 1% of the smallest circle's area), a pair too far apart for the radius gets no bridge, and a circle bridged to no other stays as it is; at most 2000 circles and 8000 bridges, found through a grid of cells so each circle is compared only with its near neighbors. Reach is unavailable in the dialog with two circles selected, which are bridged at any distance. Tests: `bridge::tests` in `vectorcraft-pathops` (a 3 × 3 grid joined by side neighbors only or with the diagonal ones, a ring of six around an empty place leaving a round hole the gap wider than a circle, each pair's shape the two-circle outline for overlapping, touching and unequal circles, a circle out of reach left alone, a pair too far apart for the arcs left unbridged, the gap form against the percentage form, too many circles or bridges and pairs that can't be bridged refused), `bridge::tests` in `cmd::addons::pathtools` in `vectorcraft-engine` (the grid as one shape in the topmost circle's place with its holes, one undo step, a circle left alone, small circles at the default reach, an id given twice, Keep Originals for several shapes, the gap form, refusals and their messages) and `constant_gap_shows_the_gap_and_bridges_many_circles_within_reach` in `vectorcraft-ui-egui`. +Constant Gap sets the arcs' radius to the smaller circle's radius plus a gap in points (`gap`), so each arc stays that gap from a circle of the smaller circle's size about the arc's center: in a triangular grid of equal circles that gap apart, the channels around an empty place are one width. With three or more circles selected, every two whose outlines are within Reach (`reach`, 10 pt by default) are bridged, the bridges that connect are united into one shape each (holes included, except those smaller than 1% of the smallest circle's area), a pair too far apart for the radius gets no bridge, and a circle bridged to no other stays as it is; at most 2000 circles and 8000 bridges, found through a grid of cells so each circle is compared only with its near neighbors. Reach is unavailable in the dialog with two circles selected, which Reach does not limit; the radius can still be too small to bridge them. Tests: `bridge::tests` in `vectorcraft-pathops` (a 3 × 3 grid joined by side neighbors only or with the diagonal ones, a ring of six around an empty place leaving a round hole the gap wider than a circle, each pair's shape the two-circle outline for overlapping, touching and unequal circles, a circle out of reach left alone, a pair too far apart for the arcs left unbridged, the gap form against the percentage form, too many circles or bridges and pairs that can't be bridged refused, the bridge limit counting only the necks left after those too thin for the precision are dropped), `bridge::tests` in `cmd::addons::pathtools` in `vectorcraft-engine` (the grid as one shape in the topmost circle's place with its holes, one undo step, a circle left alone, small circles at the default reach, an id given twice, Keep Originals for several shapes, the gap form, refusals and their messages) and `constant_gap_shows_the_gap_and_bridges_many_circles_within_reach` in `vectorcraft-ui-egui`. ## Document Tools add-on: Save a Timestamped Copy (2026-11-01)