From 6199c7f66b0777a05f79a117c6875598af11138c Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 5 Nov 2020 14:59:58 +0100 Subject: [PATCH] csg2d interface --- libsrc/geom2d/csg2d.cpp | 15 +++++++++------ libsrc/geom2d/csg2d.hpp | 5 +++-- libsrc/geom2d/python_geom2d.cpp | 13 +++---------- libsrc/meshing/python_mesh.cpp | 6 ++++++ 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/libsrc/geom2d/csg2d.cpp b/libsrc/geom2d/csg2d.cpp index 01e20981..fe0c8bd0 100644 --- a/libsrc/geom2d/csg2d.cpp +++ b/libsrc/geom2d/csg2d.cpp @@ -1703,11 +1703,14 @@ Solid2d & Solid2d :: Move( Vec<2> v ) return Transform( [v](Point<2> p) -> Point<2> { return p+v; } ); } -Solid2d & Solid2d :: Scale( double sx, double sy ) +Solid2d & Solid2d :: Scale( double s ) { - if(sy==0.0) - sy=sx; - return Transform( [sx,sy](Point<2> p) -> Point<2> { return{p[0]*sx, p[1]*sy}; } ); + return Transform( [s](Point<2> p) -> Point<2> { return{p[0]*s, p[1]*s}; } ); +} + +Solid2d & Solid2d :: Scale( Vec<2> s ) +{ + return Transform( [s](Point<2> p) -> Point<2> { return{p[0]*s[0], p[1]*s[1]}; } ); } Solid2d & Solid2d :: RotateRad( double ang, Point<2> center ) @@ -1720,8 +1723,8 @@ Solid2d & Solid2d :: RotateRad( double ang, Point<2> center ) p -= c; double x = p[0]; double y = p[1]; - p[0] = cosa*x+sina*y; - p[1] = -sina*x+cosa*y; + p[0] = cosa*x-sina*y; + p[1] = sina*x+cosa*y; p += c; return p; } ); diff --git a/libsrc/geom2d/csg2d.hpp b/libsrc/geom2d/csg2d.hpp index 42c44a89..afc1e654 100644 --- a/libsrc/geom2d/csg2d.hpp +++ b/libsrc/geom2d/csg2d.hpp @@ -678,11 +678,12 @@ struct Solid2d } Solid2d & Move( Vec<2> v ); - Solid2d & Scale( double sx, double sy=0.0 ); + Solid2d & Scale( double s ); + Solid2d & Scale( Vec<2> s ); Solid2d & RotateRad( double ang, Point<2> center = {0,0} ); Solid2d & RotateDeg( double ang, Point<2> center = {0,0} ) { - return RotateRad( ang/180.*M_PI ); + return RotateRad( ang/180.*M_PI, center ); } Solid2d & BC(string bc) diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index b8f5a871..03f57398 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -414,16 +414,9 @@ DLL_HEADER void ExportGeom2d(py::module &m) .def("Copy", [](Solid2d & self) -> Solid2d { return self; }) .def("Move", &Solid2d::Move) - .def("Scale", &Solid2d::Scale) - .def("Rotate", [](Solid2d & self, optional rad, optional deg, Point<2> center ) - { - if(rad) - self.RotateRad(*rad, center); - if(deg) - self.RotateDeg(*deg, center); - return self; - }, py::arg("rad")=nullopt, py::arg("deg")=nullopt, py::arg("center")=Point<2>{0,0}) - + .def("Scale", static_cast(&Solid2d::Scale)) + .def("Scale", static_cast)>(&Solid2d::Scale)) + .def("Rotate", &Solid2d::RotateDeg, py::arg("angle"), py::arg("center")=Point<2>{0,0}) ; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index c1cbb0c5..968c4cd7 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -211,6 +211,10 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::class_> (m, "Vec2d") .def(py::init()) + .def(py::init( [] (std::pair xy) + { + return Vec<2>{xy.first, xy.second}; + })) .def ("__str__", &ToString>) .def(py::self==py::self) .def(py::self+py::self) @@ -223,6 +227,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def("__len__", [](Vec<2>& /*unused*/) { return 2; }) ; + py::implicitly_convertible>(); + py::class_> (m, "Vec3d") .def(py::init()) .def(py::init([](py::tuple v)