Using .uniq! in a plugin
-
In the Ruby console, if I create a series of 3d points and save them in an pts array then enter pts.uniq!, the duplicates are removed. But if I do the same thing in a plugin and execute the plugin nothing is removed. There is no indication of an error.
-
If the points are the same Point3d these are uniq'd; they are the same point.
If the points are different Point3ds they are not uniq'd.
If the points are as arrays then they will be seen as different and uniq'd........... -
The statements that created the points are exactly the same in the plugin as was used to create the points in the Ruby Console.
pts=[] pts.push Geom::Point3d.new(1,1,1) pts.push Geom::Point3d.new(2,2,2) pts.push Geom::Point3d.new(1,1,1) pts.push Geom::Point3d.new(3,3,3) pts.push Geom::Point3d.new(2,2,2) pts.push Geom::Point3d.new(1,1,1) pts.uniq!
In the plugin nothing is removed as pts.length is 6 before and after the uniq! statement.
In the Ruby Console the 3 duplicates are removed. -
The API result is correct... even if two points are identical in their x/y/z they are different Point3d's.
Either compare them as arrays to find it they ARE 'equivalent'... or use the 'set' functions...
Advertisement