PolygonCoordinates Objects

class PolygonCoordinates()
Represents polygon coordinates

__init__

def __init__(values: list[PointCoordinate] | None = None,
             polygons: list[list[list[PointCoordinate]]] | None = None)
Arguments:
  • values List[PointCoordinate] - A list of PointCoordinate objects defining the polygon.
  • polygons List[List[List[PointCoordinate]]] - A list of polygons, where each polygon is a list of contours, where each contour is a list of points.

from_dict

@staticmethod
def from_dict(d: dict) -> "PolygonCoordinates"
Create a PolygonCoordinates instance from a dictionary. Supports both legacy format (single polygon with one contour) and new complex format. Arguments:
  • d dict - A dictionary containing polygon coordinates information.
    Legacy format:
    {"polygon": {str(idx): {"x": x, "y": y}} or {"polygon": [{"x": x, "y": y}]}
    
    New format:
    {"polygons": [[[{"x": x, "y": y}]]]}
    
Returns:
  • PolygonCoordinates - An instance of PolygonCoordinates.

to_dict

def to_dict(
    kind: PolygonCoordsToDict | str = PolygonCoordsToDict.single_polygon
) -> dict | list[list[list[float]]]
Convert the PolygonCoordinates instance to a dictionary. Returns:
  • dict - A dictionary representation of the polygon coordinates.