feat(tdcgal/plane/objects.py:IsoRectangle2D): class IsoRectangle2D
BREAKING CHANGE:
This commit is contained in:
parent
42a8bd72eb
commit
c703017487
|
|
@ -436,3 +436,48 @@ class Triangle2D(Shape2D, Triangle_2):
|
||||||
return f"Triangle2D(points: {[self.vertex(i) for i in range(3)]})"
|
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: 四个点分别为p1、p2、p3、p4, 则其最小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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue