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 the new complex format (multiple polygons and contours). Arguments:
  • d dict - Dictionary containing polygon coordinates information.
Returns:
  • PolygonCoordinates - A PolygonCoordinates instance.
Examples: Legacy format (mapping of index -> point):
{
  "polygon": {
    "0": {"x": 12.3, "y": 45.6},
    "1": {"x": 78.9, "y": 12.3}
  }
}
Legacy format (list of points):
{
  "polygon": [
    {"x": 12.3, "y": 45.6},
    {"x": 78.9, "y": 12.3}
  ]
}
New format (polygons -> contours -> points):
{
  "polygons": [
    [
      [
        {"x": 12.3, "y": 45.6},
        {"x": 78.9, "y": 12.3}
      ]
    ]
  ]
}

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.