-
-
Notifications
You must be signed in to change notification settings - Fork 789
Add new node "Decimate" #2823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add new node "Decimate" #2823
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work well; thanks for the contribution.
DocumentNode { | ||
inputs: vec![NodeInput::network(concrete!(graphene_std::vector::VectorDataTable), 0)], | ||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::memo::MonitorNode")), | ||
manual_composition: Some(generic!(T)), | ||
skip_deduplication: true, | ||
..Default::default() | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a monitor node?
DocumentNode { | ||
inputs: vec![NodeInput::node(NodeId(1), 0)], | ||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode")), | ||
manual_composition: Some(generic!(T)), | ||
..Default::default() | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a memo node?
@@ -1138,6 +1138,97 @@ where | |||
output_table | |||
} | |||
|
|||
/// Simplifies a polyline using the Ramer–Douglas–Peucker algorithm. | |||
#[node_macro::node(category("Vector: Modifier"), name("Decimate"), path(graphene_core::vector))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to specify the name here.
|
||
/// Calculates the perpendicular distance from a point to a line defined by two points. | ||
fn perpendicular_distance(point: DVec2, line_start: DVec2, line_end: DVec2) -> f64 { | ||
let num = ((line_end.y - line_start.y) * point.x - (line_end.x - line_start.x) * point.y + line_end.x * line_start.y - line_end.y * line_start.x).abs(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified with project onto
.
return points.to_vec(); | ||
} | ||
|
||
let (_first, _lastt) = (0, points.len() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastt
-> last
return points.to_vec(); | ||
} | ||
|
||
let (_first, _lastt) = (0, points.len() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't prefix local variables with an underscore. That usually signifies that they are unused.
let (_first, _lastt) = (0, points.len() - 1); | ||
|
||
// For closed paths, treat as open for simplification, then close at the end | ||
let (_first, _last, _is_closed) = if closed && points.len() > 2 { (0, points.len() - 1, true) } else { (0, points.len() - 1, false) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line could be simplified to
let is_closed = closed && points.len() > 2;
Since the other variables don't change and were already defined.
} | ||
|
||
if dmax > epsilon { | ||
let mut rec_results1 = douglas_peucker(&points[_first..=index], epsilon, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since first is always zero, this could just be points[..=index]
|
||
if dmax > epsilon { | ||
let mut rec_results1 = douglas_peucker(&points[_first..=index], epsilon, false); | ||
let mut rec_results2 = douglas_peucker(&points[index..=_last], epsilon, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since last
is always the last index, this could just be points[index..]
@@ -2005,6 +2005,103 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> { | |||
description: Cow::Borrowed("Convert vector geometry into a polyline composed of evenly spaced points."), | |||
properties: Some("sample_polyline_properties"), | |||
}, | |||
DocumentNodeDefinition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't usually need to manually define the document node definition as it can be automagically generated.
ec51271
to
e025103
Compare
Hi, checking in on the latest status. This currently doesn't compile. Thanks! |
Adding a new node "Decimate" which uses the Ramer-Douglas-Peucker algorithm