polygon2contour: avoid overflow

This commit is contained in:
Robert Sachunsky 2025-08-29 12:16:56 +02:00
parent fd6a6495a2
commit 698f38e461

View file

@ -353,7 +353,8 @@ def contour2polygon(contour: Union[np.ndarray, Sequence[Sequence[Sequence[Number
return make_valid(polygon)
def polygon2contour(polygon: Polygon) -> np.ndarray:
return np.array(polygon.exterior.coords[:-1], dtype=np.uint)[:, np.newaxis]
polygon = np.array(polygon.exterior.coords[:-1], dtype=np.int)
return np.maximum(0, polygon).astype(np.uint)[:, np.newaxis]
def make_valid(polygon: Polygon) -> Polygon:
"""Ensures shapely.geometry.Polygon object is valid by repeated rearrangement/simplification/enlargement."""