Skip to content

Commit c384175

Browse files
indierustyKeavon
andauthored
Improve stability of the 'Sample Points' node (#3119)
improve perimeter calculation of the path bezier segments when it is very close to linear bezier curve Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent cf2e525 commit c384175

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

node-graph/gcore/src/vector/vector_nodes.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,14 @@ async fn poisson_disk_points(
13311331

13321332
#[node_macro::node(category(""), path(graphene_core::vector))]
13331333
async fn subpath_segment_lengths(_: impl Ctx, content: Table<Vector>) -> Vec<f64> {
1334+
let pathseg_perimeter = |segment: PathSeg| {
1335+
if is_linear(segment) {
1336+
Line::new(segment.start(), segment.end()).perimeter(DEFAULT_ACCURACY)
1337+
} else {
1338+
segment.perimeter(DEFAULT_ACCURACY)
1339+
}
1340+
};
1341+
13341342
content
13351343
.into_iter()
13361344
.flat_map(|vector| {
@@ -1340,7 +1348,7 @@ async fn subpath_segment_lengths(_: impl Ctx, content: Table<Vector>) -> Vec<f64
13401348
.stroke_bezpath_iter()
13411349
.flat_map(|mut bezpath| {
13421350
bezpath.apply_affine(Affine::new(transform.to_cols_array()));
1343-
bezpath.segments().map(|segment| segment.perimeter(DEFAULT_ACCURACY)).collect::<Vec<f64>>()
1351+
bezpath.segments().map(pathseg_perimeter).collect::<Vec<f64>>()
13441352
})
13451353
.collect::<Vec<f64>>()
13461354
})

0 commit comments

Comments
 (0)