Skip to content

Commit

Permalink
fix(polygon): Ensure degenerate geometry cannot cause exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Dec 9, 2024
1 parent 5313c2c commit ea02291
Showing 1 changed file with 4 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 @@ -804,9 +804,11 @@ def offset(self, distance, check_intersection=False):
return self

# loop through the vertices and get the new offset vectors
init_verts = self._vertices if not self.is_clockwise \
base_verts = self._vertices if not self.is_clockwise \
else list(reversed(self._vertices))
init_verts = [pt for i, pt in enumerate(init_verts) if pt != init_verts[i - 1]]
init_verts = [pt for i, pt in enumerate(base_verts) if pt != base_verts[i - 1]]
if len(init_verts) < 3: # degenerate polygon
return self # cannot be offset into a valid shape
move_vecs, max_i = [], len(init_verts) - 1
for i, pt in enumerate(init_verts):
v1 = init_verts[i - 1] - pt
Expand Down

0 comments on commit ea02291

Please sign in to comment.