Skip to content

Commit ea02291

Browse files
committed
fix(polygon): Ensure degenerate geometry cannot cause exceptions
1 parent 5313c2c commit ea02291

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ladybug_geometry/geometry2d/polygon.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,11 @@ def offset(self, distance, check_intersection=False):
804804
return self
805805

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

0 commit comments

Comments
 (0)