55 lines
2.0 KiB
C++
55 lines
2.0 KiB
C++
#include <pybind11/operators.h>
|
|
#include <pybind11/pybind11.h>
|
|
|
|
#include <CGAL/Simple_cartesian.h>
|
|
|
|
#include "../cgal.hpp"
|
|
|
|
typedef CGAL::Simple_cartesian<double> Kernel;
|
|
typedef Kernel::Point_2 Point_2;
|
|
typedef Kernel::Segment_2 Segment_2;
|
|
typedef Kernel::Line_2 Line_2;
|
|
|
|
namespace py = pybind11;
|
|
|
|
double squared_distance(const Point_2 &a, const Point_2 &b) {
|
|
return CGAL::squared_distance(a, b);
|
|
}
|
|
|
|
void init_plane(py::module_ &m) {
|
|
py::class_<Point_2>(m, "Point_2")
|
|
.def(py::init<double, double>())
|
|
.def("x", &Point_2::x)
|
|
.def("y", &Point_2::y)
|
|
.def("hx", &Point_2::hx)
|
|
.def("hy", &Point_2::hy)
|
|
.def("hw", &Point_2::hw)
|
|
.def(py::self == py::self)
|
|
.def("__repr__", [](const Point_2 &a) {
|
|
return "<Point_2 x=" + std::to_string(a.x()) +
|
|
" y=" + std::to_string(a.y()) + ">";
|
|
});
|
|
py::class_<Segment_2>(m, "Segment_2")
|
|
.def(py::init<Point_2, Point_2>())
|
|
.def("_source", &Segment_2::source)
|
|
.def("_target", &Segment_2::target)
|
|
.def("min", &Segment_2::min, "返回线段的端点中较小的那个")
|
|
.def("max", &Segment_2::max, "返回线段的端点中较大的那个")
|
|
.def("squared_length", &Segment_2::squared_length, "返回线段的平方长度")
|
|
.def("opposite", &Segment_2::opposite, "返回反向的线段")
|
|
.def("has_on", &Segment_2::collinear_has_on, "判断点是否在线段上")
|
|
.def("supporting_line", &Segment_2::supporting_line, "返回与线段共线的直线")
|
|
.def("is_degenerate", &Segment_2::is_degenerate, "判断线段端点是否重合")
|
|
.def("is_horizontal", &Segment_2::is_horizontal, "判断线段是否水平")
|
|
.def("is_vertical", &Segment_2::is_vertical, "判断线段是否垂直")
|
|
.def(py::self == py::self)
|
|
.def(py::self != py::self);
|
|
py::class_<Line_2>(m, "Line_2")
|
|
.def(py::init<Point_2, Point_2>())
|
|
.def("a", &Line_2::a)
|
|
.def("b", &Line_2::b)
|
|
.def("c", &Line_2::c)
|
|
.def(py::self == py::self);
|
|
m.def("squared_distance", &squared_distance);
|
|
};
|