From b58c35831dac6a4f92955073aa90450e19020b9e Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Tue, 26 Jan 2021 11:27:46 +0100 Subject: [PATCH] Don't need to specify string description of spline type in 2d geom --- libsrc/geom2d/python_geom2d.cpp | 49 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index 03f57398..7fc88d19 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -67,24 +67,45 @@ DLL_HEADER void ExportGeom2d(py::module &m) optional> bc, optional copy, double maxh, double hpref, double hprefleft, double hprefright) { - auto segtype = py::cast(segment[0]); - SplineSegExt * seg; - if (segtype == "line") + if(py::isinstance(segment[0])) { - LineSeg<2> * l = new LineSeg<2>(self.GetPoint(py::cast(segment[1])), - self.GetPoint(py::cast(segment[2]))); - seg = new SplineSegExt(*l); - } - else if (segtype == "spline3") - { - SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(py::cast(segment[1])), - self.GetPoint(py::cast(segment[2])), - self.GetPoint(py::cast(segment[3]))); - seg = new SplineSegExt(*seg3); + auto segtype = py::cast(segment[0]); + + if (segtype == "line") + { + LineSeg<2> * l = new LineSeg<2>(self.GetPoint(py::cast(segment[1])), + self.GetPoint(py::cast(segment[2]))); + seg = new SplineSegExt(*l); + } + else if (segtype == "spline3") + { + SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(py::cast(segment[1])), + self.GetPoint(py::cast(segment[2])), + self.GetPoint(py::cast(segment[3]))); + seg = new SplineSegExt(*seg3); + } + else + throw Exception("Appended segment is not a line or a spline3"); } else - throw Exception("Appended segment is not a line or a spline3"); + { + if(py::len(segment) == 2) + { + auto l = new LineSeg<2>(self.GetPoint(py::cast(segment[0])), + self.GetPoint(py::cast(segment[1]))); + seg = new SplineSegExt(*l); + } + else if(py::len(segment) == 3) + { + SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(py::cast(segment[0])), + self.GetPoint(py::cast(segment[1])), + self.GetPoint(py::cast(segment[2]))); + seg = new SplineSegExt(*seg3); + } + else + throw Exception("Appended segment must either have 2 or 3 points"); + } seg->leftdom = leftdomain; seg->rightdom = rightdomain; seg->hmax = maxh;