Skip to content

Commit

Permalink
fix(polygon): Add an extra check for degenerate geometry
Browse files Browse the repository at this point in the history
This will prevent the pole_of_inaccessibility() function from looping endlessly.
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jun 7, 2023
1 parent d62e66b commit 9af6a03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ladybug_geometry/geometry2d/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,10 @@ def pole_of_inaccessibility(self, tolerance):
height = max_y - min_y
cell_size = min(width, height)
h = cell_size / 2.0
if cell_size == 0: # degenerate polygon; just return the minimum
return self.min
max_dim = max(width, height)
if cell_size == 0 or self.area < max_dim * tolerance:
# degenerate polygon; just return the center
return self.center

# get an array representation of the polygon and set up the priority queue
_polygon = tuple(pt.to_array() for pt in self.vertices)
Expand Down
7 changes: 7 additions & 0 deletions tests/face3d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def test_face3d_pole_of_inaccessibility():
assert pole.y == pytest.approx(1.0, rel=1e-3)
assert pole.z == pytest.approx(2.0, rel=1e-3)

deg_pts = (Point3D(0, 0, 2), Point3D(0, 0.0001, 2),
Point3D(2, 0.0001, 2), Point3D(2, 0, 2))
plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
deg_face = Face3D(deg_pts, plane)
deg_pole = deg_face.pole_of_inaccessibility(0.01)
assert isinstance(deg_pole, Point3D)


def test_equality():
"""Test the equality of Face3D objects."""
Expand Down

0 comments on commit 9af6a03

Please sign in to comment.