Note that will have be O(n^2) - it’ll quickly become very slow.
As of SU2021.1 you could potentially use Geom::PolygonMesh
to collect the point in O(log(n)) time. That will collapse the points within SketchUp’s tolerances.
A quick and dirty alternative would be to create a Point3d subclass (or mix-in) with its own hash and eql function:
points1 = [
Geom::Point3d.new(1, 2, 3),
Geom::Point3d.new(4, 5, 6),
Geom::Point3d.new(1, 2, 3),
Geom::Point3d.new(3, 2, 1),
]
puts "Geom::Point3d"
p Set.new(points1).to_a
module Point3dEx
def hash
to_a.hash
end
def eql?(other)
self == other
end
end
puts "Point3dEx"
points1.each { |pt| pt.extend(Point3dEx) }
p Set.new(points1).to_a
points2 = [
Geom::Point3d.new(1, 2, 3),
Geom::Point3d.new(4, 5, 6),
Geom::Point3d.new(1, 2.00001, 3),
Geom::Point3d.new(3, 2, 1),
]
puts "Point3dEx (tolerance test)"
points1.each { |pt| pt.extend(Point3dEx) }
p Set.new(points1).to_a
nil
Output:
Geom::Point3d
[Point3d(1, 2, 3), Point3d(4, 5, 6), Point3d(1, 2, 3), Point3d(3, 2, 1)]
Point3dEx
[Point3d(1, 2, 3), Point3d(4, 5, 6), Point3d(3, 2, 1)]
Point3dEx (tolerance test)
[Point3d(1, 2, 3), Point3d(4, 5, 6), Point3d(3, 2, 1)]