Hi,
I am trying to compare the points of a face with other points I have sorted in an array, to check if the sorted points actually is the face I am looking for.
What I have tried to do is:
face_points = face.mesh.points
which as far as I can tell returns an array of point 3D objects.
The array of points I want to check is edge.start.position
points =
points.push(edge.start.position)
which also should return an array of point 3D objects, right?
However, what I thought should be a simple thing, does not seem to work as intended.
For the record, the points array does contain some duplicates, so I tried to use uniq! to filter these out, but this didn’t work either.
So my question is, do you know how I should go about to check weather the uniq values of the points array are qual to the values of the face_points array? I am guessing maybe I am trying to compare apples and oranges or something and maybe I have to convert the arrays?
Would be highly appreciated if anyone knows the answer to this question, which I though should be more or less straight forward!
From all edge loops:
face_pts = face.vertices.map{|v| v.position }
… from just the outer edge loop:
face_pts = face.outer_loop.vertices.map{|v| v.position }
Test one of the face’s points:
mypoints.include?(face_pts[0])
Test using nested for
loops of face’s points. This makes sure to leverage the API’s custom ==
comparison method for the Geom::Point3d
class:
def test_my_points(mypoints,face)
retval = false
for pt in mypoints
for v in face.vertices
if pt == v.position
retval = true
break
end
end
break if retval
end
return retval
end
Test all of them using the block form iterators (that class Array
inherits from the mixed in Enumerable
library module.):
face_pts.all? {|pt| mypoints.any?{|mp| mp == pt } }
… similar but use the SketchUp API’s Sketchup::Face#classify_point()
method.
my_points.all? {|pt|
face.classify_point(pt) == Sketchup::Face::PointOnVertex
}
(This last one does not need to create an array object of point3d representations of the face’s vertices.)
Dear DanRathbun,
Thanks for a great answer, your solution seems to work as intended! Now I just need to sort out a few other issued with the code before it hopefully can get it to work.
Thank you again and have a great day