Part: Use PyObject_IsTrue in combination with conditional ternary operator

This commit is contained in:
marioalexis
2022-05-17 16:31:06 -03:00
committed by Chris Hennes
parent 44da7b7c0b
commit eaf01ab0c6
5 changed files with 31 additions and 29 deletions

View File

@@ -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<Base::MatrixPy*>(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());

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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), &copy,&checkScale))
if (!PyArg_ParseTuple(args, "O!|O!O!", &(Base::MatrixPy::Type),&obj,&(PyBool_Type), &copy, &(PyBool_Type), &checkScale))
return nullptr;
Base::Matrix4D mat = static_cast<Base::MatrixPy*>(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,&copy,&checkScale,&op))
if (!PyArg_ParseTupleAndKeywords(args, keywds, "O!|O!O!s", kwlist,
&Base::MatrixPy::Type, &pymat, &PyBool_Type, &copy, &PyBool_Type, &checkScale, &op))
return nullptr;
Base::Matrix4D mat = static_cast<Base::MatrixPy*>(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<Base::Vector3d> Points;
std::vector<Data::ComplexGeoData::Facet> 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));
}