Distinct_pts v3.5
Attached is an update to my distinct_pts node.
UPDATE - I updated this update! See below for the latest version.. You can disregard this note.
Distinct_pts removes duplicate points within a specified sensitivity range. When determining whether two points were the same, the original version only looked at the points' locations.
But points have another property: type. Polyline paths consist only of type 1 points. But curves have type 3 control points and type 2 end points.
Sometimes you can have a type 1 and a type 2 point at the same location. One familiar example is the beginning and end of a circle. If you feed a circle into my original distinct_pts node and reconnect the points, the end point would be removed, resulting in a deflated circle.
The improved version of distinct_pts makes two changes:
- It always leaves the first point alone.
- For all other points, if a type 2 point shares the same location as a type 1 point, the type 2 point will be preferred.
The improved node should behave similarly in most situations, but should do less damage to curved paths.
The demo shows a scatter of 10,000 dots with one black dot remaining in each clump and blue dots, within a radius of 8, removed. This is the same result as my original demo but with one additional black dot (because the first dot was left alone). To the right I show a circle with duplicate points removed (sensitivity 0); but if you render the reconnected circle you will see that no points were removed in this case and the circle remains intact.
One situation where this change might matter is when dealing with the output of a compound node. The compound node sometimes does strange things to a shape, changing direction, adding bits of dust, and sometimes adding duplicate points of varying types. I sometimes use distinct_pts to repair some of this damage, but the original version could do more harm than good. This improved version should do better. But if anyone runs into trouble with it, please let me know!
- distinct_points_screenshot.png 1.81 MB
- distinct_points_3.5.ndbx.zip 2.42 KB
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by john on 05 Sep, 2024 02:21 AM
UPDATE
After much thought and further experimentation, I decided that the approach I took to improving this node was overly complicated and needed a redo.
The fundamental issue I was trying to address is: "What happens if two points are in the same place, but of a different type? Are they distinct or not?
All the extra work assigning preferences and treating the first point differently was overkill and still failed to prevent problems in special cases. I should have just answered that question and kept things simple.
I now think the answer is: "NO, points in the same place but of different types are NOT the same and should not be consolidated - no exceptions."
Situations in which all points are type 1, as in my example above, go back to the way the node originally worked - no exceptions for the first point. As you can see in the attached screenshot, the total count of points is now back to 1415.
I also added a few more test cases to the demo: a circle, a pentagon with a duplicate type 1 point, and a capital P text path.
The circle with points drawn appears to the right of the blob. If you zoom in you can see that distinct_pts leaves points 0 and 12 in place; they are in the same location but different types so are not judged discreet.
If you open the demo you can render the other two test cases. The duplicate dot in the pentagon is removed because both overlapping dots are type 1. In the capital P, points 0 and 29 are in the same spot, as are points 30 and 57, but none are removed because each pair is of differing types.
Reconnecting the points in the modified P causes a loss of the second contour resulting in a new line connecting 29 and 30. I did this to show that multi-type overlaps can occur anywhere in a complex path. If the two pairs were not treated as discrete, as happened in the previous version, mayhem would have ensued. To remove duplicate points in a complex path, you should use my contours node to remove duplicates separately for each contour then recombine them using my new pair_contour node.
Sorry for the arcane update to my update. These nodes are tricky and require clear thinking to get right.
If you need to use distinct_pts before the next rev of my library comes out, use the one in the demo attached to this note.