feat(tdcgal/plane/objects.py:IsoRectangle2D): class IsoRectangle2D

BREAKING CHANGE:
This commit is contained in:
songsenand 2024-03-11 21:44:29 +08:00
parent 42a8bd72eb
commit c703017487
1 changed files with 46 additions and 1 deletions

View File

@ -435,4 +435,49 @@ class Triangle2D(Shape2D, Triangle_2):
def __repr__(self) -> str:
return f"Triangle2D(points: {[self.vertex(i) for i in range(3)]})"
# Iso-rectangle类
class IsoRectangle2D(Shape2D, Iso_rectangle_2):
def __init__(
self,
opposite_vertices: Tuple[
Union[Point2D, Tuple[float, float]],
Union[Point2D, Tuple[float, float]],
] = None,
points: Tuple[
Union[Point2D, Tuple[float, float]],
Union[Point2D, Tuple[float, float]],
Union[Point2D, Tuple[float, float]],
Union[Point2D, Tuple[float, float]],
] = None,
homogenizing_coordinate: Tuple[float, float, float, float, float,float] = None,
**kwargs,
):
"""
Iso-rectangle2D的初始化方法
Args:
opposite_vertices: 两个对角顶点
points: 四个点分别为p1p2p3p4, 则其最小x坐标为p1的x坐标,最大x坐标为p2的x坐标, 最小y坐标为p3的y坐标, 最大y坐标为p4的y坐标
homogenizing_coordinate: 引入一个等向矩形r其对角线方向的顶点为(min_hx/hw, min_hy/hw)(max_hx/hw, max_hy/hw). 其中`hw != 0`
"""
Shape2D.__init__(self, **kwargs)
if opposite_vertices is not None:
v1 = point_maker(opposite_vertices[0])
v2 = point_maker(opposite_vertices[1])
Iso_rectangle_2.__init__(self, v1, v2)
elif points is not None:
points = [point_maker(p) for p in points]
Iso_rectangle_2.__init__(self, *points)
elif homogenizing_coordinate is not None:
Iso_rectangle_2.__init__(self, *homogenizing_coordinate)
else:
raise ValueError("Invalid input for IsoRectangle2D")
# 重载`repr`方法返回IsoRectangle2D的字符串表示
def __repr__(self) -> str:
return f"IsoRectangle2D(vertices: {[self.vertex(i) for i in range(4)]})"
# 返回第index个顶点
def __getitem__(self, index: int) -> Point2D:
return self.vertex(index)