Skip to content

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Moustafaa91
Copy link

Adding a new node "Decimate" which uses the Ramer-Douglas-Peucker algorithm

Copy link
Member

@0HyperCube 0HyperCube left a 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.

Comment on lines +2016 to +2022
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()
},
Copy link
Member

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?

Comment on lines +2029 to +2034
DocumentNode {
inputs: vec![NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode")),
manual_composition: Some(generic!(T)),
..Default::default()
},
Copy link
Member

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))]
Copy link
Member

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();
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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) };
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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 {
Copy link
Member

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.

@Keavon Keavon force-pushed the master branch 4 times, most recently from ec51271 to e025103 Compare July 10, 2025 05:48
@Keavon
Copy link
Member

Keavon commented Jul 10, 2025

Hi, checking in on the latest status. This currently doesn't compile. Thanks!

@Keavon Keavon marked this pull request as draft July 10, 2025 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants