|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING, Any, List, Literal, Optional, TypedDict, Union |
| 3 | +from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, TypedDict, Union |
4 | 4 |
|
5 | 5 | if TYPE_CHECKING: |
6 | 6 | from encord.objects import Shape |
7 | | - from encord.objects.coordinates import ( |
8 | | - BoundingBoxDict, |
9 | | - BoundingBoxFrameCoordinatesDict, |
10 | | - LegacyPolygonDict, |
11 | | - Point3DFrameCoordinatesDict, |
12 | | - PointDict, |
13 | | - PointDict3D, |
14 | | - PointFrameCoordinatesDict, |
15 | | - PolygonDict, |
16 | | - PolygonFrameCoordinatesDict, |
17 | | - PolylineDict, |
18 | | - PolylineFrameCoordinatesDict, |
19 | | - RotatableBoundingBoxDict, |
20 | | - RotatableBoundingBoxFrameCoordinatesDict, |
21 | | - ) |
| 7 | + |
| 8 | +""" Typed Dicts for Shape Coordinates """ |
| 9 | + |
| 10 | + |
| 11 | +class BoundingBoxDict(TypedDict): |
| 12 | + h: float |
| 13 | + w: float |
| 14 | + x: float |
| 15 | + y: float |
| 16 | + |
| 17 | + |
| 18 | +class BoundingBoxFrameCoordinatesDict(TypedDict): |
| 19 | + boundingBox: BoundingBoxDict |
| 20 | + |
| 21 | + |
| 22 | +class PointDict(TypedDict): |
| 23 | + x: float |
| 24 | + y: float |
| 25 | + |
| 26 | + |
| 27 | +class PointFrameCoordinatesDict(TypedDict): |
| 28 | + point: dict[str, PointDict] # Actually the key here is always '0', but no way to type that. |
| 29 | + |
| 30 | + |
| 31 | +class PointDict3D(PointDict): |
| 32 | + z: float |
| 33 | + |
| 34 | + |
| 35 | +class Point3DFrameCoordinatesDict(TypedDict): |
| 36 | + point: dict[str, PointDict3D] # Actually the key here is always '0', but no way to type that. |
| 37 | + |
| 38 | + |
| 39 | +class RotatableBoundingBoxDict(BoundingBoxDict): |
| 40 | + theta: float |
| 41 | + |
| 42 | + |
| 43 | +class RotatableBoundingBoxFrameCoordinatesDict(TypedDict): |
| 44 | + rotatableBoundingBox: RotatableBoundingBoxDict |
| 45 | + |
| 46 | + |
| 47 | +PolylineDict = Union[Dict[str, PointDict], list[PointDict], Dict[str, PointDict3D], list[PointDict3D]] |
| 48 | + |
| 49 | + |
| 50 | +class PolylineFrameCoordinatesDict(TypedDict): |
| 51 | + polyline: PolylineDict |
| 52 | + |
| 53 | + |
| 54 | +LegacyPolygonDict = Union[Dict[str, PointDict], list[PointDict]] |
| 55 | +PolygonDict = List[List[List[float]]] # Introduced to support complex polygons |
| 56 | + |
| 57 | + |
| 58 | +class PolygonFrameCoordinatesDictRequired(TypedDict): |
| 59 | + polygon: LegacyPolygonDict |
| 60 | + |
| 61 | + |
| 62 | +class PolygonFrameCoordinatesDict(PolygonFrameCoordinatesDictRequired, total=False): |
| 63 | + polygons: Optional[PolygonDict] # This was introduced to support complex polygons. |
22 | 64 |
|
23 | 65 |
|
24 | 66 | class AnswerDict(TypedDict): |
|
0 commit comments