implicit conversion from py::tuple to Point<2>

This commit is contained in:
Matthias Hochsteger 2020-08-20 18:28:03 +02:00
parent ceb57a7c5c
commit e2768981f1

View File

@ -163,6 +163,10 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
py::class_<Point<2>> (m, "Point2d") py::class_<Point<2>> (m, "Point2d")
.def(py::init<double,double>()) .def(py::init<double,double>())
.def(py::init( [] (std::pair<double,double> xy)
{
return Point<2>{xy.first, xy.second};
}))
.def ("__str__", &ToString<Point<2>>) .def ("__str__", &ToString<Point<2>>)
.def(py::self-py::self) .def(py::self-py::self)
.def(py::self+Vec<2>()) .def(py::self+Vec<2>())
@ -170,6 +174,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def("__getitem__", [](Point<2>& self, int index) { return self[index]; }) .def("__getitem__", [](Point<2>& self, int index) { return self[index]; })
; ;
py::implicitly_convertible<py::tuple, Point<2>>();
py::class_<Point<3>> (m, "Point3d") py::class_<Point<3>> (m, "Point3d")
.def(py::init<double,double,double>()) .def(py::init<double,double,double>())
.def ("__str__", &ToString<Point<3>>) .def ("__str__", &ToString<Point<3>>)