def get_bounds(cls, area):
"""Return the rectangular bounds of the area.
Args:
area (list): A list of positions.
Returns:
list: [x1, y1, x2, y2] where (x1, y1) is the top-left point and (x2, y2)
is the bottom-right point.
"""
x1 = math.inf
y1 = math.inf
x2 = (-math.inf)
y2 = (-math.inf)
for pos in area:
if pos[0] < x1:
x1 = pos[0]
if pos[1] < y1:
y1 = pos[1]
if pos[0] > x2:
x2 = pos[0]
if pos[1] > y2:
y2 = pos[1]
return [x1, y1, x2, y2]
评论列表
文章目录