tensorbay.geometry.polygon¶
PointList2D, Polygon2D.
PointList2D
contains a list of 2D points.
Polygon
contains the coordinates of the vertexes of the polygon
and provides Polygon2D.area()
to calculate the area of the polygon.
- class tensorbay.geometry.polygon.PointList2D(points: Optional[Iterable[Iterable[float]]] = None)[source]¶
Bases:
tensorbay.utility.user.UserMutableSequence
[tensorbay.geometry.polygon._T
]This class defines the concept of PointList2D.
PointList2D
contains a list of 2D points.- Parameters
points – A list of 2D points.
- classmethod loads(contents: List[Dict[str, float]]) tensorbay.geometry.polygon._P [source]¶
Load a
PointList2D
from a list of dictionaries.- Parameters
contents –
A list of dictionaries containing the coordinates of the vertexes of the polygon:
[ { "x": ... "y": ... }, ... ]
- Returns
The loaded
PointList2D
object.
- dumps() List[Dict[str, float]] [source]¶
Dumps a
PointList2D
into a point list.- Returns
A list of dictionaries containing the coordinates of the vertexes of the polygon within the point list.
- bounds() tensorbay.geometry.box.Box2D [source]¶
Calculate the bounds of point list.
- Returns
The bounds of point list.
- class tensorbay.geometry.polygon.Polygon2D(points: Optional[Iterable[Iterable[float]]] = None)[source]¶
Bases:
tensorbay.geometry.polygon.PointList2D
[tensorbay.geometry.vector.Vector2D
]This class defines the concept of Polygon2D.
Polygon2D
contains the coordinates of the vertexes of the polygon and providesPolygon2D.area()
to calculate the area of the polygon.Examples
>>> Polygon2D([[1, 2], [2, 3], [2, 2]]) Polygon2D [ Vector2D(1, 2), Vector2D(2, 3), Vector2D(2, 2) ]
- classmethod loads(contents: List[Dict[str, float]]) tensorbay.geometry.polygon._P [source]¶
Load a
Polygon2D
from a list of dictionaries.- Parameters
contents – A list of dictionaries containing the coordinates of the vertexes of the polygon.
- Returns
The loaded
Polygon2D
object.
Examples
>>> contents = [{"x": 1.0, "y": 1.0}, {"x": 2.0, "y": 2.0}, {"x": 2.0, "y": 3.0}] >>> Polygon2D.loads(contents) Polygon2D [ Vector2D(1.0, 1.0), Vector2D(2.0, 2.0), Vector2D(2.0, 3.0) ]