Skip to content

Commit ada1d00

Browse files
authored
Handle empty polygons in inflate_polygon (#328)
1 parent e3f30bd commit ada1d00

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

pyrobosim/pyrobosim/utils/polygon.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def inflate_polygon(poly, radius):
9595
inflated_poly = poly.buffer(
9696
radius, cap_style=CAP_STYLE.flat, join_style=JOIN_STYLE.mitre
9797
)
98+
if inflated_poly.is_empty:
99+
return inflated_poly
98100
return orient(inflated_poly)
99101

100102

pyrobosim/test/utils/test_polygon_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ def test_get_polygon_centroid():
7575

7676

7777
def test_inflate_polygon():
78+
empty_poly = Polygon()
7879
square_poly = Polygon(square_coords)
7980

81+
# Empty polygon
82+
inflated_poly = inflate_polygon(empty_poly, 0.0)
83+
assert inflated_poly == empty_poly
84+
8085
# Zero inflation radius
8186
inflated_poly = inflate_polygon(square_poly, 0.0)
8287
inflated_poly_coords = list(inflated_poly.exterior.coords)
@@ -108,8 +113,13 @@ def test_inflate_polygon():
108113

109114

110115
def test_transform_polygon():
116+
empty_poly = Polygon()
111117
square_poly = Polygon(box_to_coords(dims=[1.0, 2.0]))
112118

119+
# Empty polygon
120+
transformed_poly = transform_polygon(empty_poly, None)
121+
assert transformed_poly == empty_poly
122+
113123
# No transformation, using None as pose
114124
transformed_poly = transform_polygon(square_poly, None)
115125
assert transformed_poly == square_poly

0 commit comments

Comments
 (0)