From 70347a6d3c1768a6cbd9b41b6a69be3968388176 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Tue, 29 Sep 2020 18:57:56 +0200 Subject: [PATCH] tuple implicitly convertible to Pnt and Vec --- libsrc/meshing/python_mesh.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 5b2ea5c1..c1cbb0c5 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -179,6 +179,11 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::class_> (m, "Point3d") .def(py::init()) + .def(py::init([](py::tuple p) + { + return Point<3> { p[0].cast(), p[1].cast(), + p[2].cast() }; + })) .def ("__str__", &ToString>) .def(py::self-py::self) .def(py::self+Vec<3>()) @@ -186,6 +191,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def("__getitem__", [](Point<2>& self, int index) { return self[index]; }) ; + py::implicitly_convertible>(); + m.def("Pnt", [](double x, double y, double z) { return global_trafo(Point<3>(x,y,z)); }); m.def("Pnt", [](double x, double y) { return Point<2>(x,y); }); @@ -218,6 +225,11 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::class_> (m, "Vec3d") .def(py::init()) + .def(py::init([](py::tuple v) + { + return Vec<3> { v[0].cast(), v[1].cast(), + v[2].cast() }; + })) .def ("__str__", &ToString>) .def(py::self==py::self) .def(py::self+py::self) @@ -230,6 +242,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def("__len__", [](Vec<3>& /*unused*/) { return 3; }) ; + py::implicitly_convertible>(); + m.def ("Vec", FunctionPointer ([] (double x, double y, double z) { return global_trafo(Vec<3>(x,y,z)); })); m.def("Vec", [](py::array_t np_array)