From ad0f1147f74d8e010d47cfca2bb08033e0f3b4ae Mon Sep 17 00:00:00 2001 From: marioalexis Date: Tue, 17 May 2022 16:31:06 -0300 Subject: [PATCH] Part: Use PyObject_IsTrue in combination with conditional ternary operator --- src/Mod/Part/App/AppPartPy.cpp | 14 ++++++++------ src/Mod/Part/App/BSplineCurvePyImp.cpp | 10 +++++----- src/Mod/Part/App/BSplineSurfacePyImp.cpp | 10 +++++----- src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp | 10 +++++----- src/Mod/Part/App/TopoShapePyImp.cpp | 16 ++++++++-------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 1606738ebd..527394730e 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1362,7 +1362,7 @@ private: Standard_Failure::Raise("Cannot create polygon because less than two vertices are given"); // if the polygon should be closed - if (PyObject_IsTrue(pclosed)) { + if (PyObject_IsTrue(pclosed) ? true : false) { if (!mkPoly.FirstVertex().IsSame(mkPoly.LastVertex())) { mkPoly.Add(mkPoly.FirstVertex()); } @@ -2287,9 +2287,10 @@ private: short retType = 0; static char* kwd_list[] = {"obj", "subname", "mat", "needSubElement","transform","retType","noElementMap","refine",nullptr}; - if(!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|sO!OOhOO", kwd_list, + if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|sO!O!O!hO!O!", kwd_list, &App::DocumentObjectPy::Type, &pObj, &subname, &Base::MatrixPy::Type, &pyMat, - &needSubElement,&transform,&retType,&noElementMap,&refine)) + &PyBool_Type,&needSubElement,&PyBool_Type,&transform,&retType, + &PyBool_Type,&noElementMap,&PyBool_Type,&refine)) throw Py::Exception(); App::DocumentObject *obj = @@ -2298,9 +2299,10 @@ private: Base::Matrix4D mat; if(pyMat) mat = *static_cast(pyMat)->getMatrixPtr(); - auto shape = Feature::getTopoShape(obj,subname,PyObject_IsTrue(needSubElement), - &mat,&subObj,retType==2,PyObject_IsTrue(transform),PyObject_IsTrue(noElementMap)); - if(PyObject_IsTrue(refine)) { + auto shape = Feature::getTopoShape(obj,subname,PyObject_IsTrue(needSubElement) ? true : false, + &mat,&subObj,retType==2,PyObject_IsTrue(transform) ? true : false, + PyObject_IsTrue(noElementMap) ? true : false); + if (PyObject_IsTrue(refine) ? true : false) { // shape = TopoShape(0,shape.Hasher).makERefine(shape); BRepBuilderAPI_RefineModel mkRefine(shape.getShape()); shape.setShape(mkRefine.Shape()); diff --git a/src/Mod/Part/App/BSplineCurvePyImp.cpp b/src/Mod/Part/App/BSplineCurvePyImp.cpp index 9e4a7f3386..fcc7c87500 100644 --- a/src/Mod/Part/App/BSplineCurvePyImp.cpp +++ b/src/Mod/Part/App/BSplineCurvePyImp.cpp @@ -1124,10 +1124,10 @@ PyObject* BSplineCurvePy::buildFromPoles(PyObject *args) if (poles.Length() <= degree) degree = poles.Length()-1; - if (PyObject_IsTrue(periodic)) { + if (PyObject_IsTrue(periodic) ? true : false) { int mult; int len; - if (PyObject_IsTrue(interpolate)) { + if (PyObject_IsTrue(interpolate) ? true : false) { mult = degree; len = poles.Length() - mult + 2; } @@ -1231,7 +1231,7 @@ PyObject* BSplineCurvePy::buildFromPolesMultsKnots(PyObject *args, PyObject *key else { if (knots != Py_None) { number_of_knots = PyObject_Length(knots); } else { //guess number of knots - if (PyObject_IsTrue(periodic)) { + if (PyObject_IsTrue(periodic) ? true : false) { if (number_of_poles < degree) {degree = number_of_poles+1;} number_of_knots = number_of_poles+1; } @@ -1306,8 +1306,8 @@ PyObject* BSplineCurvePy::buildFromPolesMultsKnots(PyObject *args, PyObject *key } } // check if the number of poles matches the sum of mults - if ((PyObject_IsTrue(periodic) && sum_of_mults != number_of_poles) || - (PyObject_Not(periodic) && sum_of_mults - degree -1 != number_of_poles)) { + if (((PyObject_IsTrue(periodic) ? true : false) && sum_of_mults != number_of_poles) || + ((PyObject_Not(periodic) ? true : false) && sum_of_mults - degree -1 != number_of_poles)) { Standard_Failure::Raise("number of poles and sum of mults mismatch"); return(nullptr); } diff --git a/src/Mod/Part/App/BSplineSurfacePyImp.cpp b/src/Mod/Part/App/BSplineSurfacePyImp.cpp index 9fb49dbeb8..bd831b87c7 100644 --- a/src/Mod/Part/App/BSplineSurfacePyImp.cpp +++ b/src/Mod/Part/App/BSplineSurfacePyImp.cpp @@ -1457,10 +1457,10 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k occvknots.SetValue(i,(double)(i-1)/(occvknots.Length()-1)); } } - if ((PyObject_IsTrue(uperiodic) && sum_of_umults != lu) || - (PyObject_Not(uperiodic) && sum_of_umults - udegree -1 != lu) || - (PyObject_IsTrue(vperiodic) && sum_of_vmults != lv) || - (PyObject_Not(vperiodic) && sum_of_vmults - vdegree -1 != lv)) { + if (((PyObject_IsTrue(uperiodic) ? true : false) && sum_of_umults != lu) || + ((PyObject_Not(uperiodic) ? true : false) && sum_of_umults - udegree -1 != lu) || + ((PyObject_IsTrue(vperiodic) ? true : false) && sum_of_vmults != lv) || + ((PyObject_Not(vperiodic) ? true : false) && sum_of_vmults - vdegree -1 != lv)) { Standard_Failure::Raise("number of poles and sum of mults mismatch"); } // check multiplicity of inner knots @@ -1538,7 +1538,7 @@ PyObject* BSplineSurfacePy::buildFromNSections(PyObject *args) } GeomFill_NSections fillOp(curveSeq); - if (PyObject_IsTrue(refSurf)) { + if (PyObject_IsTrue(refSurf) ? true : false) { Handle(Geom_BSplineSurface) ref = Handle(Geom_BSplineSurface)::DownCast (getGeometryPtr()->handle()); fillOp.SetSurface(ref); diff --git a/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp index 48a3b60174..328904ef46 100644 --- a/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp +++ b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp @@ -1026,10 +1026,10 @@ PyObject* BSplineCurve2dPy::buildFromPoles(PyObject *args) if (poles.Length() <= degree) degree = poles.Length()-1; - if (PyObject_IsTrue(periodic)) { + if (PyObject_IsTrue(periodic) ? true : false) { int mult; int len; - if (PyObject_IsTrue(interpolate)) { + if (PyObject_IsTrue(interpolate) ? true : false) { mult = degree; len = poles.Length() - mult + 2; } @@ -1130,7 +1130,7 @@ PyObject* BSplineCurve2dPy::buildFromPolesMultsKnots(PyObject *args, PyObject *k else { if (knots != Py_None) { number_of_knots = PyObject_Length(knots); } else { //guess number of knots - if (PyObject_IsTrue(periodic)) { + if (PyObject_IsTrue(periodic) ? true : false) { if (number_of_poles < degree) {degree = number_of_poles+1;} number_of_knots = number_of_poles+1; } @@ -1197,8 +1197,8 @@ PyObject* BSplineCurve2dPy::buildFromPolesMultsKnots(PyObject *args, PyObject *k } } // check if the number of poles matches the sum of mults - if ((PyObject_IsTrue(periodic) && sum_of_mults != number_of_poles) || - (PyObject_Not(periodic) && sum_of_mults - degree -1 != number_of_poles)) { + if (((PyObject_IsTrue(periodic) ? true : false) && sum_of_mults != number_of_poles) || + ((PyObject_Not(periodic) ? true : false) && sum_of_mults - degree -1 != number_of_poles)) { Standard_Failure::Raise("number of poles and sum of mults mismatch"); return(nullptr); } diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 82e172468f..91d9bcde6f 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -1394,13 +1394,13 @@ PyObject* TopoShapePy::transformShape(PyObject *args) PyObject *obj; PyObject *copy = Py_False; PyObject *checkScale = Py_False; - if (!PyArg_ParseTuple(args, "O!|O!O", &(Base::MatrixPy::Type),&obj,&(PyBool_Type), ©,&checkScale)) + if (!PyArg_ParseTuple(args, "O!|O!O!", &(Base::MatrixPy::Type),&obj,&(PyBool_Type), ©, &(PyBool_Type), &checkScale)) return nullptr; Base::Matrix4D mat = static_cast(obj)->value(); PY_TRY { this->getTopoShapePtr()->transformShape(mat, PyObject_IsTrue(copy) ? true : false, - PyObject_IsTrue(checkScale)); + PyObject_IsTrue(checkScale) ? true : false); return IncRef(); } PY_CATCH_OCC @@ -1413,15 +1413,15 @@ PyObject* TopoShapePy::transformed(PyObject *args, PyObject *keywds) PyObject* copy = Py_False; PyObject* checkScale = Py_False; const char *op = nullptr; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "O!|OOs", kwlist, - &Base::MatrixPy::Type, &pymat,©,&checkScale,&op)) + if (!PyArg_ParseTupleAndKeywords(args, keywds, "O!|O!O!s", kwlist, + &Base::MatrixPy::Type, &pymat, &PyBool_Type, ©, &PyBool_Type, &checkScale, &op)) return nullptr; Base::Matrix4D mat = static_cast(pymat)->value(); (void)op; PY_TRY { TopoShape s(*getTopoShapePtr()); - s.transformShape(mat,PyObject_IsTrue(copy),PyObject_IsTrue(checkScale)); + s.transformShape(mat,PyObject_IsTrue(copy) ? true : false,PyObject_IsTrue(checkScale) ? true : false); return Py::new_reference_to(shape2pyshape(s)); } PY_CATCH_OCC @@ -1954,7 +1954,7 @@ PyObject* TopoShapePy::tessellate(PyObject *args) try { std::vector Points; std::vector Facets; - if (PyObject_IsTrue(ok)) + if (PyObject_IsTrue(ok) ? true : false) BRepTools::Clean(getTopoShapePtr()->getShape()); getTopoShapePtr()->getFaces(Points, Facets,tolerance); Py::Tuple tuple(2); @@ -2148,7 +2148,7 @@ PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args) } getTopoShapePtr()->setFaces(Points, Facets, tolerance); - if (PyObject_IsTrue(sewShape)) + if (PyObject_IsTrue(sewShape) ? true : false) getTopoShapePtr()->sewShape(tolerance); Py_Return; @@ -2221,7 +2221,7 @@ PyObject* TopoShapePy::isInside(PyObject *args) solidClassifier.Perform(vertex, tolerance); Standard_Boolean test = (solidClassifier.State() == stateIn); - if (PyObject_IsTrue(checkFace) && (solidClassifier.IsOnAFace())) + if ((PyObject_IsTrue(checkFace) ? true : false) && (solidClassifier.IsOnAFace())) test = Standard_True; return Py_BuildValue("O", (test ? Py_True : Py_False)); }