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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement