Fix Poisson-disk sampling with negative space from nested subpaths (#2569)

* Fix poisson disk sampling with nested subpaths

Previously all subpaths were considered independently for the poisson disk sampling evaluation. We now check agains all subpaths which might contain the point to fix shapes with holes such as fonts with letters with holes in them

* Fix wasm demo

* Fix counting overlapping areas twice

* Rename shape variables to subpath variants
This commit is contained in:
Dennis Kobert
2025-04-15 15:37:20 +02:00
committed by GitHub
parent 98558c74f4
commit 9a62c1c089
4 changed files with 32 additions and 8 deletions

View File

@@ -67,7 +67,7 @@ serde = { workspace = true, optional = true, features = ["derive"] }
ctor = { workspace = true, optional = true }
log = { workspace = true, optional = true }
rand_chacha = { workspace = true, optional = true }
bezier-rs = { workspace = true, optional = true }
bezier-rs = { workspace = true, optional = true, features = ["log"] }
kurbo = { workspace = true, optional = true }
base64 = { workspace = true, optional = true }
vello = { workspace = true, optional = true }

View File

@@ -1245,17 +1245,23 @@ async fn poisson_disk_points(
if separation_disk_diameter <= 0.01 {
return VectorDataTable::new(result);
}
let path_with_bounding_boxes: Vec<_> = vector_data
.stroke_bezier_paths()
.filter_map(|mut subpath| {
// TODO: apply transform to points instead of modifying the paths
subpath.apply_transform(vector_data_transform);
subpath.loose_bounding_box().map(|bb| (subpath, bb))
})
.collect();
for mut subpath in vector_data.stroke_bezier_paths() {
for (i, (subpath, _)) in path_with_bounding_boxes.iter().enumerate() {
if subpath.manipulator_groups().len() < 3 {
continue;
}
subpath.apply_transform(vector_data_transform);
let mut previous_point_index: Option<usize> = None;
for point in subpath.poisson_disk_points(separation_disk_diameter, || rng.random::<f64>()) {
for point in subpath.poisson_disk_points(separation_disk_diameter, || rng.random::<f64>(), &path_with_bounding_boxes, i) {
let point_id = PointId::generate();
result.point_domain.push(point_id, point);