Skip to content

Commit 9987112

Browse files
indierustyKeavon
andauthored
New node: 'Separate Subpaths' to break subpaths into individual vector table rows (#3069)
* impl separate paths node * rename * refactor * Rename nodes 'Split Segments' -> 'Cut Segments' and 'Split Path' -> 'Cut Path' --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent ad59e1c commit 9987112

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

editor/src/messages/portfolio/document_migration.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
230230
"graphene_math_nodes::CoordinateValueNode",
231231
],
232232
},
233+
NodeReplacement {
234+
node: graphene_std::vector::cut_segments::IDENTIFIER,
235+
aliases: &["graphene_core::vector::SplitSegmentsNode"],
236+
},
237+
NodeReplacement {
238+
node: graphene_std::vector::cut_path::IDENTIFIER,
239+
aliases: &["graphene_core::vector::SplitPathNode"],
240+
},
233241
NodeReplacement {
234242
node: graphene_std::vector::vec_2_to_point::IDENTIFIER,
235243
aliases: &["graphene_core::vector::PositionToPointNode"],

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,35 @@ async fn solidify_stroke(_: impl Ctx, content: Table<Vector>) -> Table<Vector> {
942942
.collect()
943943
}
944944

945+
#[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))]
946+
async fn separate_subpaths(_: impl Ctx, content: Table<Vector>) -> Table<Vector> {
947+
content
948+
.into_iter()
949+
.flat_map(|row| {
950+
let style = row.element.style.clone();
951+
let transform = row.transform;
952+
let alpha_blending = row.alpha_blending;
953+
let source_node_id = row.source_node_id;
954+
955+
row.element
956+
.stroke_bezpath_iter()
957+
.map(move |bezpath| {
958+
let mut vector = Vector::default();
959+
vector.append_bezpath(bezpath);
960+
vector.style = style.clone();
961+
962+
TableRow {
963+
element: vector,
964+
transform,
965+
alpha_blending,
966+
source_node_id,
967+
}
968+
})
969+
.collect::<Vec<TableRow<Vector>>>()
970+
})
971+
.collect()
972+
}
973+
945974
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
946975
async fn flatten_path<I: 'n + Send>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>)] content: Table<I>) -> Table<Vector>
947976
where
@@ -1065,11 +1094,11 @@ async fn sample_polyline(
10651094
.collect()
10661095
}
10671096

1068-
/// Splits a path at a given progress from 0 to 1 along the path, creating two new subpaths from the original one (if the path is initially open) or one open subpath (if the path is initially closed).
1097+
/// Cuts a path at a given progress from 0 to 1 along the path, creating two new subpaths from the original one (if the path is initially open) or one open subpath (if the path is initially closed).
10691098
///
10701099
/// If multiple subpaths make up the path, the whole number part of the progress value selects the subpath and the decimal part determines the position along it.
10711100
#[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))]
1072-
async fn split_path(_: impl Ctx, mut content: Table<Vector>, progress: Fraction, parameterized_distance: bool, reverse: bool) -> Table<Vector> {
1101+
async fn cut_path(_: impl Ctx, mut content: Table<Vector>, progress: Fraction, parameterized_distance: bool, reverse: bool) -> Table<Vector> {
10731102
let euclidian = !parameterized_distance;
10741103

10751104
let bezpaths = content
@@ -1108,9 +1137,9 @@ async fn split_path(_: impl Ctx, mut content: Table<Vector>, progress: Fraction,
11081137
content
11091138
}
11101139

1111-
/// Splits path segments into separate disconnected pieces where each is a distinct subpath.
1140+
/// Cuts path segments into separate disconnected pieces where each is a distinct subpath.
11121141
#[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))]
1113-
async fn split_segments(_: impl Ctx, mut content: Table<Vector>) -> Table<Vector> {
1142+
async fn cut_segments(_: impl Ctx, mut content: Table<Vector>) -> Table<Vector> {
11141143
// Iterate through every segment and make a copy of each of its endpoints, then reassign each segment's endpoints to its own unique point copy
11151144
for row in content.iter_mut() {
11161145
let points_count = row.element.point_domain.ids().len();

0 commit comments

Comments
 (0)