feat(tdcgal/plane/plane.cpp-tdcgal/plane/objects.py): add Vector_2 Direction_2 Direction2D etc
This commit is contained in:
parent
6f012976d0
commit
b82011ef76
|
|
@ -114,7 +114,7 @@ class Ray2D(Shape2D, Ray_2):
|
||||||
@property
|
@property
|
||||||
def source(self) -> Point2D:
|
def source(self) -> Point2D:
|
||||||
return self._source()
|
return self._source()
|
||||||
|
|
||||||
# 返回射线方向
|
# 返回射线方向
|
||||||
@property
|
@property
|
||||||
def direction(self) -> Direction2D:
|
def direction(self) -> Direction2D:
|
||||||
|
|
@ -131,7 +131,51 @@ class Ray2D(Shape2D, Ray_2):
|
||||||
|
|
||||||
|
|
||||||
class Direction2D(Shape2D, Direction_2):
|
class Direction2D(Shape2D, Direction_2):
|
||||||
pass
|
def __init__(
|
||||||
|
self,
|
||||||
|
vec: Vector2D = None,
|
||||||
|
line: Line2D = None,
|
||||||
|
ray: Ray2D = None,
|
||||||
|
seg: Segment2D = None,
|
||||||
|
coor: Tuple[float, float] = None,
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
|
"""`Direction2D`构造函数
|
||||||
|
|
||||||
|
Args:
|
||||||
|
vec (Vector2D, optional): _description_. Defaults to None.
|
||||||
|
line (Line2D, optional): _description_. Defaults to None.
|
||||||
|
ray (Ray2D, optional): _description_. Defaults to None.
|
||||||
|
seg (Segment2D, optional): _description_. Defaults to None.
|
||||||
|
coor (Tuple[float, float], optional): _description_. Defaults to None.
|
||||||
|
|
||||||
|
> 需要提供`vec`, `line`, `ray`, `seg`, `coor`中的一个参数。
|
||||||
|
"""
|
||||||
|
Shape2D.__init__(self, **kwargs)
|
||||||
|
if vec is not None:
|
||||||
|
Direction_2.__init__(self, vec)
|
||||||
|
elif line is not None:
|
||||||
|
Direction_2.__init__(self, line)
|
||||||
|
elif ray is not None:
|
||||||
|
Direction_2.__init__(self, ray)
|
||||||
|
elif seg is not None:
|
||||||
|
Direction_2.__init__(self, seg)
|
||||||
|
elif coor is not None:
|
||||||
|
Direction_2.__init__(self, coor)
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid input for Direction2D")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dx(self) -> float:
|
||||||
|
return self._dx()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dy(self) -> float:
|
||||||
|
return self._dy()
|
||||||
|
|
||||||
|
# 重载`repr`方法,返回Direction2D的字符串表示
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Direction2D({self.dx}, {self.dy})"
|
||||||
|
|
||||||
|
|
||||||
class Vector2D(Shape2D, Vector_2):
|
class Vector2D(Shape2D, Vector_2):
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ typedef Kernel::Direction_2 Direction_2;
|
||||||
typedef Kernel::Vector_2 Vector_2;
|
typedef Kernel::Vector_2 Vector_2;
|
||||||
typedef Kernel::Ray_2 Ray_2;
|
typedef Kernel::Ray_2 Ray_2;
|
||||||
typedef Kernel::FT FT;
|
typedef Kernel::FT FT;
|
||||||
|
typedef Kernel::RT RT;
|
||||||
|
|
||||||
template <typename T, typename U> FT squared_distance(const T &a, const U &b) {
|
template <typename T, typename U> FT squared_distance(const T &a, const U &b) {
|
||||||
return CGAL::squared_distance(a, b);
|
return CGAL::squared_distance(a, b);
|
||||||
|
|
@ -51,6 +52,7 @@ void init_plane(py::module_ &m) {
|
||||||
.def("is_vertical", &Segment_2::is_vertical, "判断线段是否垂直")
|
.def("is_vertical", &Segment_2::is_vertical, "判断线段是否垂直")
|
||||||
.def(py::self == py::self)
|
.def(py::self == py::self)
|
||||||
.def(py::self != py::self);
|
.def(py::self != py::self);
|
||||||
|
|
||||||
py::class_<Ray_2>(m, "Ray_2")
|
py::class_<Ray_2>(m, "Ray_2")
|
||||||
.def(py::init<Point_2, Point_2>())
|
.def(py::init<Point_2, Point_2>())
|
||||||
.def(py::init<Point_2, Vector_2>())
|
.def(py::init<Point_2, Vector_2>())
|
||||||
|
|
@ -70,6 +72,70 @@ void init_plane(py::module_ &m) {
|
||||||
.def("is_vertical", &Ray_2::is_vertical, "判断射线是否垂直")
|
.def("is_vertical", &Ray_2::is_vertical, "判断射线是否垂直")
|
||||||
.def(py::self == py::self)
|
.def(py::self == py::self)
|
||||||
.def(py::self != py::self);
|
.def(py::self != py::self);
|
||||||
|
|
||||||
|
py::class_<Direction_2>(m, "Direction_2")
|
||||||
|
.def(py::init<Vector_2>())
|
||||||
|
.def(py::init<Line_2>())
|
||||||
|
.def(py::init<Ray_2>())
|
||||||
|
.def(py::init<Segment_2>())
|
||||||
|
.def(py::init<RT, RT>(), "构造一个经过原点和(x,y)坐标的d")
|
||||||
|
.def("_dx", &Direction_2::dx)
|
||||||
|
.def("_dy", &Direction_2::dy)
|
||||||
|
.def("delta", &Direction_2::delta, "返回d的???, 参数`i`〔筆畫〕需满足`0<=i<=1`")
|
||||||
|
.def("vector", &Direction_2::vector, "返回与d同向的向量")
|
||||||
|
.def("transform", &Direction_2::transform, "返回经过变换后的方向")
|
||||||
|
.def("counterclockwise_in_between", &Direction_2::counterclockwise_in_between,
|
||||||
|
"判断方向是否在两向量之间")
|
||||||
|
.def(py::self == py::self)
|
||||||
|
.def(py::self != py::self)
|
||||||
|
.def(py::self >= py::self)
|
||||||
|
.def(py::self <= py::self)
|
||||||
|
.def(py::self > py::self)
|
||||||
|
.def(py::self < py::self)
|
||||||
|
.def(-py::self, "返回反向的方向");
|
||||||
|
|
||||||
|
py::class_<Vector_2>(m, "Vector_2")
|
||||||
|
.def(py::init<Point_2, Point_2>())
|
||||||
|
.def(py::init<Segment_2>())
|
||||||
|
.def(py::init<Ray_2>())
|
||||||
|
.def(py::init<Line_2>())
|
||||||
|
.def(py::init([](){
|
||||||
|
return new Vector_2(CGAL::NULL_VECTOR);
|
||||||
|
}))
|
||||||
|
.def(py::init<int, int>())
|
||||||
|
.def(py::init<double, double>())
|
||||||
|
.def(py::init<RT, RT, RT>())
|
||||||
|
.def(py::init<FT, FT>())
|
||||||
|
.def("_x", &Vector_2::x)
|
||||||
|
.def("_y", &Vector_2::y)
|
||||||
|
.def("_hx", &Vector_2::hx)
|
||||||
|
.def("_hy", &Vector_2::hy)
|
||||||
|
.def("_hw", &Vector_2::hw)
|
||||||
|
.def("homogeneous", &Vector_2::homogeneous, "返回向量的齐次坐标")
|
||||||
|
.def("cartesian", &Vector_2::cartesian, "返回向量第`i`个笛卡尔坐标, `i`是参数")
|
||||||
|
.def("cartesian_begin", &Vector_2::cartesian_begin, "返回向量的笛卡尔坐标的起始迭代器")
|
||||||
|
.def("cartesian_end", &Vector_2::cartesian_end, "返回向量的笛卡尔坐标的终止迭代器")
|
||||||
|
.def("dimension", &Vector_2::dimension, "返回向量的维数")
|
||||||
|
.def("direction", &Vector_2::direction, "返回向量的方向")
|
||||||
|
.def("transform", &Vector_2::transform, "返回经过变换后的向量")
|
||||||
|
// TODO .def("perpendicular", &Vector_2::perpendicular, "返回与向量垂直的向量, 参数`o`")
|
||||||
|
|
||||||
|
.def("squared_length", &Vector_2::squared_length, "返回向量的平方长度")
|
||||||
|
.def("transform", &Vector_2::transform, "返回经过变换后的向量")
|
||||||
|
.def("direction", &Vector_2::direction, "返回向量的方向")
|
||||||
|
.def("to_direction", &Vector_2::to_direction, "返回向量的方向")
|
||||||
|
.def("angle", &Vector_2::angle, "返回向量与x轴的夹角")
|
||||||
|
.def("normalize", &Vector_2::normalize, "返回单位向量")
|
||||||
|
.def("perpendicular", &Vector_2::perpendicular, "返回与向量垂直的向量")
|
||||||
|
.def("transform", &Vector_2::transform, "返回经过变换后的向量")
|
||||||
|
.def(py::self == py::self)
|
||||||
|
.def(py::self != py::self)
|
||||||
|
.def(py::self + py::self)
|
||||||
|
.def(py::self - py::self)
|
||||||
|
.def(py::self * py::self)
|
||||||
|
.def(py::self / py::self)
|
||||||
|
.def(-py::self, "返回反向的向量");
|
||||||
|
|
||||||
py::class_<Line_2>(m, "Line_2")
|
py::class_<Line_2>(m, "Line_2")
|
||||||
.def(py::init<double, double, double>())
|
.def(py::init<double, double, double>())
|
||||||
.def(py::init<Point_2, Point_2>())
|
.def(py::init<Point_2, Point_2>())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue