Skip to content

Commit 50a618a

Browse files
authored
New node: Path is Closed (#3970)
Add the 'Path is Closed' node
1 parent 6388a32 commit 50a618a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,22 @@ async fn separate_subpaths(_: impl Ctx, content: Table<Vector>) -> Table<Vector>
11971197
.collect()
11981198
}
11991199

1200+
/// Determines if the subpath at the given index (across all vector element subpaths) is closed, meaning its ends are connected together forming a loop.
1201+
#[node_macro::node(name("Path is Closed"), category("Vector"), path(core_types::vector))]
1202+
async fn path_is_closed(
1203+
_: impl Ctx,
1204+
/// The vector content whose subpaths are inspected.
1205+
content: Table<Vector>,
1206+
/// The index of the subpath to check, counting across subpaths in all vector elements.
1207+
index: f64,
1208+
) -> bool {
1209+
content
1210+
.iter()
1211+
.flat_map(|row| row.element.stroke_bezpath_iter().map(|bezpath| bezpath.elements().last() == Some(&kurbo::PathEl::ClosePath)))
1212+
.nth(index.max(0.) as usize)
1213+
.unwrap_or(false)
1214+
}
1215+
12001216
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
12011217
async fn map_points(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table<Vector>, mapped: impl Node<Context<'static>, Output = DVec2>) -> Table<Vector> {
12021218
let mut content = content;

0 commit comments

Comments
 (0)