Skip to content

Commit f60d89f

Browse files
authored
Merge pull request #1602 from ablazejuk/patch-1
Validate that polygon has at least 3 vertices in geometry utils.py
2 parents 75a4ff1 + 1b95d1d commit f60d89f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

supervision/geometry/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def get_polygon_center(polygon: np.ndarray) -> Point:
1616
Point: The center of the polygon, represented as a
1717
Point object with x and y attributes.
1818
19+
Raises:
20+
ValueError: If the polygon has no vertices.
21+
1922
Examples:
2023
```python
2124
import numpy as np
@@ -30,6 +33,9 @@ def get_polygon_center(polygon: np.ndarray) -> Point:
3033
# This is one of the 3 candidate algorithms considered for centroid calculation.
3134
# For a more detailed discussion, see PR #1084 and commit eb33176
3235

36+
if len(polygon) == 0:
37+
raise ValueError("Polygon must have at least one vertex.")
38+
3339
shift_polygon = np.roll(polygon, -1, axis=0)
3440
signed_areas = np.cross(polygon, shift_polygon) / 2
3541
if signed_areas.sum() == 0:

0 commit comments

Comments
 (0)