44
55Point = Tuple [float , float ]
66Polygon = Sequence [Point ]
7- BoundingBox = Tuple [float , float , float , float ]
7+ BBox = Tuple [float , float , float , float ]
88Quadrilateral = Tuple [Point , Point , Point , Point ]
99
1010
11- def get_bbox_as_polygon (polygon : Polygon ) -> Quadrilateral :
11+ def get_bounding_box (polygon : Polygon ) -> Quadrilateral :
1212 """
1313 Given a sequence of points, calculate a polygon that encompasses all points.
1414
@@ -19,7 +19,7 @@ def get_bbox_as_polygon(polygon: Polygon) -> Quadrilateral:
1919 return (x_min , y_min ), (x_max , y_min ), (x_max , y_max ), (x_min , y_max )
2020
2121
22- def get_bbox (polygon : Polygon ) -> BoundingBox :
22+ def get_bbox (polygon : Polygon ) -> BBox :
2323 """
2424 Given a list of points, calculate a bounding box that encompasses all points.
2525
@@ -33,6 +33,20 @@ def get_bbox(polygon: Polygon) -> BoundingBox:
3333 return x_min , y_min , x_max , y_max
3434
3535
36+ def get_bounding_box_for_polygons (vertices : Sequence [Polygon ]) -> Quadrilateral :
37+ """
38+ Given a list of polygons, calculate a polygon that encompasses all polygons.
39+
40+ :param vertices: List of polygons
41+ :return: Quadrilateral
42+ """
43+ y_min = min (y for v in vertices for _ , y in v )
44+ y_max = max (y for v in vertices for _ , y in v )
45+ x_min = min (x for v in vertices for x , _ in v )
46+ x_max = max (x for v in vertices for x , _ in v )
47+ return (x_min , y_min ), (x_max , y_min ), (x_max , y_max ), (x_min , y_max )
48+
49+
3650def get_centroid (polygon : Polygon ) -> Point :
3751 """
3852 Get the central point (centroid) given a list of points.
0 commit comments