diff --git a/pyalphashape/AlphaShape.py b/pyalphashape/AlphaShape.py index e3f8c4f..6d88c89 100644 --- a/pyalphashape/AlphaShape.py +++ b/pyalphashape/AlphaShape.py @@ -238,9 +238,9 @@ def contains_point(self, pt: np.ndarray, tol: float = 1e-8) -> bool: True if the point lies inside or on the alpha shape; False otherwise. """ - assert ( - self._delaunay is not None - ), "Delaunay triangulation must be performed first" + if self._delaunay is None or self.perimeter_points is None: + return False + # fast hull‐check simplex_idx = self._delaunay.find_simplex(pt) if simplex_idx < 0: diff --git a/unit_tests/test_AlphaShape.py b/unit_tests/test_AlphaShape.py index fdf4084..de76d5d 100644 --- a/unit_tests/test_AlphaShape.py +++ b/unit_tests/test_AlphaShape.py @@ -32,6 +32,10 @@ def test_alpha_shape_basic_perimeter(): assert len(alpha_shape.perimeter_points) > 0 assert isinstance(alpha_shape.perimeter_edges, list) +def test_contains_point_incomplete(): + points = np.array([[0, 0], [1, 0]]) + shape = AlphaShape(points, alpha=0.0) + assert not shape.contains_point(np.array([0.5, 0.5])) def test_contains_point_inside(): points = np.array([[0, 0], [1, 0], [0.5, 1]])