Skip to content
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

New node: Merge by Distance #2307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richard-uk1
Copy link

@richard-uk1 richard-uk1 commented Feb 19, 2025

Here's a patch that adds a new node to collapse segments with chord shorter than a distance (parameter to the node). It's not finished but this version works - I tried it out by drawing freehand then watching the segments collapse as the distance increases.

Things still to do:

  • Also move bezier control points (I left this until after the first version because it is fairly orthogonal to finding and collapsing the short segments)
  • Updating faces if the end segments were removed
  • General tidy up (I've used petgraph for the clustering algo but unless you want to take the dep, I assume I'll need to figure it out myself and replace it with hand-written code.)
    • If you did want to take the dep, I'd need to look at minimal features to get what is needed, to avoid bloating build time

I do think you should consider using a graph library though, because the relationship between points, segments and faces is inherantly graph-like, and one might as well take advantage of all the experties that's been developed for graphs.

EDIT I measured binary size before/after this PR:

  • with master size is 15.93M
  • with PR, size is 15.98M

@richard-uk1 richard-uk1 force-pushed the merge_by_distance branch 2 times, most recently from 7cd11f3 to 26c5460 Compare February 19, 2025 16:48
Footprint -> VectorDataTable,
)]
source: impl Node<F, Output = VectorDataTable>,
#[default(10.)] distance: Length,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a different default would be better.

@Keavon Keavon changed the title Add merge by difference node New node: Merge by Distance Feb 19, 2025
@richard-uk1 richard-uk1 force-pushed the merge_by_distance branch 2 times, most recently from 5131957 to 2f32d59 Compare February 21, 2025 13:19
@richard-uk1 richard-uk1 marked this pull request as ready for review February 21, 2025 13:26
@Keavon
Copy link
Member

Keavon commented Feb 21, 2025

For the 0.05 MB I think we can accept the dependency. There's a chance we use it in the future for other graph data structures, too.

@richard-uk1
Copy link
Author

It's probably overkill for just this 1 problem, but I can see it being useful in a number of situations. It might even be the most efficient way to store path info.

@Keavon
Copy link
Member

Keavon commented Feb 26, 2025

!build

Copy link

📦 Build Complete for 23a5e56
https://281a17fb.graphite.pages.dev

@richard-uk1
Copy link
Author

I'll get back on this.

@Keavon
Copy link
Member

Keavon commented Mar 1, 2025

Just a reminder since it's the weekend and you might have some time to fix this up for the merge.


// Now group connected segments - all will be collapsed to a single point.
// Note: there are a few algos for this - perhaps test empirically to find fastest
let collapse: Vec<FxHashSet<PointId>> = petgraph::algo::tarjan_scc(&short_edges).into_iter().map(|connected| connected.into_iter().collect()).collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tarjan will almost certainly be faster than Kosaraju because it only requires a single graph traversal

@Keavon
Copy link
Member

Keavon commented Mar 9, 2025

Hi, just one more friendly reminder, it'd be awesome to get this landed. Thanks for your work so far on it!

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