Update to include points on face
Now correctly returns True for points on boundary surface of solid. Updated tests to verify this. Remove check that isInside() is run on solid since it is now part of Mixin3D which implies that self is a solid. Improved doc string.
This commit is contained in:
@ -1115,18 +1115,20 @@ class Mixin3D(object):
|
||||
def isInside(self, point, tolerance=1.0e-6):
|
||||
"""
|
||||
Returns whether or not the point is inside a solid or compound
|
||||
object within supplied tolerance.
|
||||
"""
|
||||
if shape_LUT[self.wrapped.ShapeType()] not in {'Solid', 'Compound'}:
|
||||
raise ValueError('Solid or Compound shape required.')
|
||||
object within the specified tolerance.
|
||||
|
||||
:param point: tuple or Vector representing 3D point to be tested
|
||||
:param tolerance: tolerence for inside determination, default=1.0e-6
|
||||
:return: bool indicating whether or not point is within solid
|
||||
"""
|
||||
if isinstance(point, Vector):
|
||||
point = point.toTuple()
|
||||
|
||||
solid_classifier = BRepClass3d_SolidClassifier(self.wrapped)
|
||||
solid_classifier.Perform(gp_Pnt(*point), tolerance)
|
||||
|
||||
return (solid_classifier.State() == ta.TopAbs_IN)
|
||||
return (solid_classifier.State() == ta.TopAbs_IN or
|
||||
solid_classifier.IsOnAFace())
|
||||
|
||||
|
||||
class Solid(Shape, Mixin3D):
|
||||
|
@ -1911,16 +1911,19 @@ class TestCadQuery(BaseTest):
|
||||
self.assertTrue(solid.isInside((Vector(3,3,3))))
|
||||
self.assertFalse(solid.isInside((Vector(30.0,30.0,30.0))))
|
||||
|
||||
self.assertTrue(solid.isInside((4.9,4.9,4.9), tolerance=0.01))
|
||||
self.assertFalse(solid.isInside((5.1,5.1,5.1), tolerance=0.01))
|
||||
self.assertTrue(solid.isInside((0,0,4.99), tolerance=0.1))
|
||||
self.assertTrue(solid.isInside((0,0,5))) # check point on surface
|
||||
self.assertTrue(solid.isInside((0,0,5.01), tolerance=0.1))
|
||||
self.assertFalse(solid.isInside((0,0,5.1), tolerance=0.1))
|
||||
|
||||
# test compound solid
|
||||
model = Workplane('XY').box(10,10,10)
|
||||
model = model.moveTo(50,50).box(10,10,10)
|
||||
solid = model.val()
|
||||
|
||||
self.assertTrue(solid.isInside((0,0,0)))
|
||||
self.assertTrue(solid.isInside((50,50,0)))
|
||||
self.assertFalse(solid.isInside((50,55,0)))
|
||||
self.assertFalse(solid.isInside((50,56,0)))
|
||||
|
||||
# make sure raises on non solid
|
||||
model = Workplane('XY').rect(10,10)
|
||||
|
Reference in New Issue
Block a user