We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 75a4ff1 + 1b95d1d commit f60d89fCopy full SHA for f60d89f
1 file changed
supervision/geometry/utils.py
@@ -16,6 +16,9 @@ def get_polygon_center(polygon: np.ndarray) -> Point:
16
Point: The center of the polygon, represented as a
17
Point object with x and y attributes.
18
19
+ Raises:
20
+ ValueError: If the polygon has no vertices.
21
+
22
Examples:
23
```python
24
import numpy as np
@@ -30,6 +33,9 @@ def get_polygon_center(polygon: np.ndarray) -> Point:
30
33
# This is one of the 3 candidate algorithms considered for centroid calculation.
31
34
# For a more detailed discussion, see PR #1084 and commit eb33176
32
35
36
+ if len(polygon) == 0:
37
+ raise ValueError("Polygon must have at least one vertex.")
38
39
shift_polygon = np.roll(polygon, -1, axis=0)
40
signed_areas = np.cross(polygon, shift_polygon) / 2
41
if signed_areas.sum() == 0:
0 commit comments