Distinct() method to remove duplicate points

Using the distinct() method to remove duplicate points is not successful. What is the reason?

# Point3d.CullDuplicates Method ,It seems to work

There are probably rounding errors why you see seemingly same points with Distinct(). Panel does some rounding and then it looks like the points are the same. In all likelihood there are more digits after the decimal separator that aren’t show, but that are different from each other. CullDuplicates does a ‘fuzzy’ compare, using an epsilon, to weed out the duplicates.

You can find many posts on this forum about floating point arithmetic and accuracy.

You need to supply a custom IEqualityComparer<Point3d> to eliminate tolerance-related issues. It’s better to use RhinoCommon methods because of the optimization involved. If you’d like to implement it on your own, sorting X,Y,Z coordinates accordingly would reduce searching time significantly.

2 Likes