From 1b59873456b35fa79675541f3bdbcc8552aff439 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 21:30:33 -0800 Subject: [PATCH] Shape Builder: say the filled areas keep their own cap past the map's When the sweep cuts the paths into more than SHAPE_BUILDER_MAX_MAP_EDGES pieces, the Shape Builder falls back to the regions of the filled areas, which are capped separately. The docs said it then finds no regions. --- crates/pathops/README.md | 2 +- crates/pathops/src/planar/shape_builder.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/pathops/README.md b/crates/pathops/README.md index 54b39b1dc5..f41873333c 100644 --- a/crates/pathops/README.md +++ b/crates/pathops/README.md @@ -59,7 +59,7 @@ pub fn interior_point(path: &PathData) -> Option; Unlike `regions`, which splits the filled areas of closed shapes, `live_paint` treats every path as an edge, open paths included. Three crossing lines enclose a triangle, a line across a rectangle splits it in two, and an area enclosed by paths becomes a face even when nothing fills it. Each face lists the inputs whose fill covers it; the list is empty for an area that is only enclosed by paths. Each edge is a piece of a path, split wherever another path meets it, and keeps the key of the front-most input it lies on. -`shape_builder` gives the Shape Builder's regions. With closed paths only, they are the `regions`. Once an open path is among them, they are the `live_paint` faces, so a stroke-only line across a shape splits it and lines can enclose a region of their own. The second list holds the pieces of each path that has no closed subpath, keyed by its index, so the Shape Builder can delete them one by one. The caller closes any open path whose fill should count. Inputs with more than `SHAPE_BUILDER_MAX_SEGMENTS` segments fall back to the filled areas. When the paths cross each other so often that the sweep cuts them into more than `SHAPE_BUILDER_MAX_MAP_EDGES` pieces, it returns no regions. +`shape_builder` gives the Shape Builder's regions. With closed paths only, they are the `regions`. Once an open path is among them, they are the `live_paint` faces, so a stroke-only line across a shape splits it and lines can enclose a region of their own. The second list holds the pieces of each path that has no closed subpath, keyed by its index, so the Shape Builder can delete them one by one. The caller closes any open path whose fill should count. Inputs with more than `SHAPE_BUILDER_MAX_SEGMENTS` segments fall back to the filled areas. When the paths cross each other so often that the sweep cuts them into more than `SHAPE_BUILDER_MAX_MAP_EDGES` pieces, it skips the full map and returns only the regions of the filled areas, which are capped on their own: a filled shape apart from open paths that cross too often still has its region. ```rust pub struct Adjacency { pub faces: Vec, pub edges: Vec, pub slivers: Vec, pub outlines: Vec } diff --git a/crates/pathops/src/planar/shape_builder.rs b/crates/pathops/src/planar/shape_builder.rs index b1f8520c23..8dca6f752d 100644 --- a/crates/pathops/src/planar/shape_builder.rs +++ b/crates/pathops/src/planar/shape_builder.rs @@ -14,7 +14,9 @@ pub const SHAPE_BUILDER_MAX_SEGMENTS: usize = 65_536; /// paths that cross nothing make at that cap. Paths that cross many times make far more pieces /// than they have segments (400 circles stacked nearly on top of each other, 1,600 segments, make /// about 320,000), and the regions and edges built from them took minutes and gigabytes of memory. -/// Past this the Shape Builder finds no regions. +/// Past this the Shape Builder skips the full map and keeps only the regions of the filled areas, +/// which are capped on their own: when the open paths alone cross too often, a filled shape apart +/// from them still has its region. pub const SHAPE_BUILDER_MAX_MAP_EDGES: usize = 2 * SHAPE_BUILDER_MAX_SEGMENTS; /// The Shape Builder's arrangement: see [`shape_builder`]. @@ -48,8 +50,9 @@ pub fn has_open_path(shapes: &[Shape]) -> bool { /// nothing fills, and each path with no closed subpath comes back cut wherever another path meets /// it, as pieces keyed by its index in `shapes`. Outlines are cut the same way. With more than /// [`SHAPE_BUILDER_MAX_SEGMENTS`] segments or a map that can't be built, only the filled areas -/// count and there are no pieces. When the sweep cuts the paths into more than -/// [`SHAPE_BUILDER_MAX_MAP_EDGES`] pieces, there are no regions either. +/// count and there are no pieces. The same happens when the sweep cuts the paths into more than +/// [`SHAPE_BUILDER_MAX_MAP_EDGES`] pieces; the filled areas are then capped on their own, so they +/// have no regions only when they alone are cut into more pieces than that. pub fn shape_builder(shapes: &[Shape], edges: bool) -> BuilderArrangement { shape_builder_with_gap(shapes, edges, 0.0) }