From ba1061df7d2c75c9cc1e167623b3ca574a40487c Mon Sep 17 00:00:00 2001 From: Michael Greminger Date: Mon, 24 Jun 2019 13:56:13 -0500 Subject: [PATCH] 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. --- cadquery/occ_impl/shapes.py | 12 +++++++----- tests/TestCadQuery.py | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 554de35a..16f283dc 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -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): diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index 9c3f1e06..b2be1179 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -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)