Skip to content

Commit 25652c1

Browse files
committed
New nodes: 'Voronoi Cells', 'Tesselate', and 'Relax Points'
1 parent a770448 commit 25652c1

7 files changed

Lines changed: 779 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ syn = { version = "2.0", default-features = false, features = [
209209
"proc-macro",
210210
] }
211211
lyon_geom = "1.0"
212+
delaunator = "1.0"
212213
petgraph = { version = "0.7", default-features = false, features = ["graphmap"] }
213214
half = { version = "2.4", default-features = false, features = ["bytemuck"] }
214215
tinyvec = { version = "1", features = ["std"] }

node-graph/libraries/vector-types/src/vector/vector_modification.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ where
629629
deserializer.deserialize_seq(visitor)
630630
}
631631

632+
/// Distance below which a path's closing point is treated as coincident with its start point.
633+
/// Matches Kurbo's default path accuracy, so points within an offset operation's own precision are not split into separate anchors.
634+
const CLOSE_POINT_TOLERANCE: f64 = 1e-6;
635+
632636
pub struct AppendBezpath<'a> {
633637
first_point: Option<Point>,
634638
last_point: Option<Point>,
@@ -657,7 +661,11 @@ impl<'a> AppendBezpath<'a> {
657661
}
658662

659663
fn append_segment_and_close_path(&mut self, point: Point, handle: BezierHandles) {
660-
let handle = if self.first_point.unwrap() != point {
664+
// A path's final point may return to approximately (but not bit-exactly) its start before closing, e.g. a contour
665+
// produced by Kurbo's path offsetting. Treat a near-coincident final point as already on the start so we don't
666+
// introduce a redundant duplicate anchor and a zero-length closing segment.
667+
let endpoints_coincide = (self.first_point.unwrap() - point).hypot2() <= CLOSE_POINT_TOLERANCE * CLOSE_POINT_TOLERANCE;
668+
let handle = if !endpoints_coincide {
661669
// If the first point is not the same as the last point of the path then we append the segment
662670
// with given handle and point and then close the path with linear handle.
663671
self.append_segment(point, handle);

node-graph/nodes/vector/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ repeat-nodes = { workspace = true }
2424
dyn-any = { workspace = true }
2525
glam = { workspace = true }
2626
kurbo = { workspace = true }
27+
delaunator = { workspace = true }
2728
rand = { workspace = true }
2829
rustc-hash = { workspace = true }
2930
log = { workspace = true }

node-graph/nodes/vector/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod generator_nodes;
22
pub mod merge_qr_squares;
33
pub mod vector_modification_nodes;
44
mod vector_nodes;
5+
mod voronoi;
56

67
#[macro_use]
78
extern crate log;

0 commit comments

Comments
 (0)