From 23594a00076244fa95148d7251c81eeada2e6daa Mon Sep 17 00:00:00 2001 From: hm-thinkbook14p Date: Fri, 30 Oct 2026 00:22:03 +0800 Subject: [PATCH] fix(python): alias Point3D and Vector3D type --- python/src/bind_core.cpp | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/python/src/bind_core.cpp b/python/src/bind_core.cpp index bf6aae6a8..203feb071 100644 --- a/python/src/bind_core.cpp +++ b/python/src/bind_core.cpp @@ -75,42 +75,10 @@ Construct with ``Point3D(x, y, z)``. Supports arithmetic +, -, *scalar, /scalar. return distance(a, b); }, py::arg("other"), "Euclidean distance to another point"); - // ── Vector3D ───────────────────────────────────── - py::class_(core, "Vector3D", - R"pbdoc( -3D vector with double precision (Eigen::Vector3d). - -Construct with ``Vector3D(x, y, z)``. Supports arithmetic +, -, *scalar, /scalar. -)pbdoc") - .def(py::init(), - py::arg("x") = 0.0, py::arg("y") = 0.0, py::arg("z") = 0.0) - .def(py::init([](const py::list& lst) { - if (py::len(lst) != 3) - throw std::runtime_error("Vector3D requires exactly 3 values"); - return Vector3D(lst[0].cast(), - lst[1].cast(), - lst[2].cast()); - }), - py::arg("coords")) - .def_property_readonly("x", [](const Vector3D& v) -> double { return v.x(); }) - .def_property_readonly("y", [](const Vector3D& v) -> double { return v.y(); }) - .def_property_readonly("z", [](const Vector3D& v) -> double { return v.z(); }) - .def("__repr__", &vector3d_repr) - .def("__len__", [](const Vector3D&) { return 3; }) - .def("__getitem__", [](const Vector3D& v, int i) { - if (i < 0 || i > 2) throw py::index_error(); - return v(i); - }) - .def("__add__", [](const Vector3D& a, const Vector3D& b) { return a + b; }) - .def("__sub__", [](const Vector3D& a, const Vector3D& b) { return a - b; }) - .def("__mul__", [](const Vector3D& v, double s) { return v * s; }) - .def("__truediv__", [](const Vector3D& v, double s) { return v / s; }) - .def("__neg__", [](const Vector3D& v) { return -v; }) - .def("norm", [](const Vector3D& v) { return v.norm(); }) - .def("squared_norm", [](const Vector3D& v) { return v.squaredNorm(); }) - .def("dot", [](const Vector3D& a, const Vector3D& b) { return a.dot(b); }) - .def("cross", [](const Vector3D& a, const Vector3D& b) { return a.cross(b); }) - .def("normalized", [](const Vector3D& v) { return v.normalized(); }); + // Point3D and Vector3D are the same Eigen::Matrix type; + // register once and expose the second name as an alias to avoid duplicate + // pybind11 generic_type registration. + core.attr("Vector3D") = core.attr("Point3D"); // ── Point2D ────────────────────────────────────── py::class_(core, "Point2D")