diff --git a/src/libs/qmuparser/qmudef.h b/src/libs/qmuparser/qmudef.h index 39addb376..97ab8f76b 100644 --- a/src/libs/qmuparser/qmudef.h +++ b/src/libs/qmuparser/qmudef.h @@ -42,4 +42,20 @@ inline QString NameRegExp() #pragma GCC diagnostic pop #endif +static inline bool QmuFuzzyComparePossibleNulls(double p1, double p2) +{ + if(qFuzzyIsNull(p1)) + { + return qFuzzyIsNull(p2); + } + else if(qFuzzyIsNull(p2)) + { + return false; + } + else + { + return qFuzzyCompare(p1, p2); + } +} + #endif // QMUDEF_H diff --git a/src/libs/qmuparser/qmuparser.cpp b/src/libs/qmuparser/qmuparser.cpp index 249352fac..bbfee78d9 100644 --- a/src/libs/qmuparser/qmuparser.cpp +++ b/src/libs/qmuparser/qmuparser.cpp @@ -389,9 +389,9 @@ qreal QmuParser::Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon) const // Backwards compatible calculation of epsilon inc case the user doesnt provide // his own epsilon - if (qFuzzyCompare(fEpsilon + 1, 1 + 0)) + if (qFuzzyIsNull(fEpsilon)) { - fEpsilon = (qFuzzyCompare(a_fPos + 1, 1 + 0)) ? static_cast(1e-10) : static_cast(1e-7) * a_fPos; + fEpsilon = qFuzzyIsNull(a_fPos) ? static_cast(1e-10) : static_cast(1e-7) * a_fPos; } *a_Var = a_fPos+2 * fEpsilon; f[0] = Eval(); diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index b08e1dd1d..414517533 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -20,6 +20,7 @@ ******************************************************************************************************/ #include "qmuparserbase.h" +#include "qmudef.h" #include #ifdef QMUP_USE_OPENMP @@ -854,7 +855,7 @@ void QmuParserBase::ApplyIfElse(QStack &a_stOpt, QStack token_type vVal1 = a_stVal.pop(); token_type vExpr = a_stVal.pop(); - a_stVal.push( (qFuzzyCompare(vExpr.GetVal()+1, 1+0)==false) ? vVal1 : vVal2); + a_stVal.push( not qFuzzyIsNull(vExpr.GetVal()) ? vVal1 : vVal2); token_type opIf = a_stOpt.pop(); Q_ASSERT(opElse.GetCode()==cmELSE); @@ -983,11 +984,11 @@ qreal QmuParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const continue; case cmNEQ: --sidx; - Stack[sidx] = (qFuzzyCompare(Stack[sidx], Stack[sidx+1])==false); + Stack[sidx] = not QmuFuzzyComparePossibleNulls(Stack[sidx], Stack[sidx+1]); continue; case cmEQ: --sidx; - Stack[sidx] = qFuzzyCompare(Stack[sidx], Stack[sidx+1]); + Stack[sidx] = QmuFuzzyComparePossibleNulls(Stack[sidx], Stack[sidx+1]); continue; case cmLT: --sidx; @@ -1059,7 +1060,7 @@ qreal QmuParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const //Stack[sidx] = *pTok->Oprt.ptr = Stack[sidx+1]; //continue; case cmIF: - if (qFuzzyCompare(Stack[sidx--]+1, 1+0)) + if (qFuzzyIsNull(Stack[sidx--])) { pTok += pTok->Oprt.offset; } diff --git a/src/libs/qmuparser/qmuparserbytecode.cpp b/src/libs/qmuparser/qmuparserbytecode.cpp index 245141632..32604017c 100644 --- a/src/libs/qmuparser/qmuparserbytecode.cpp +++ b/src/libs/qmuparser/qmuparserbytecode.cpp @@ -20,11 +20,12 @@ ******************************************************************************************************/ #include "qmuparserbytecode.h" +#include "qmuparsertoken.h" +#include "qmudef.h" #include #include #include -#include "qmuparsertoken.h" #include #include @@ -165,11 +166,11 @@ void QmuParserByteCode::ConstantFolding(ECmdCode a_Oprt) m_vRPN.pop_back(); break; case cmNEQ: - x = (qFuzzyCompare(x, y) == false); + x = not QmuFuzzyComparePossibleNulls(x, y); m_vRPN.pop_back(); break; case cmEQ: - x = qFuzzyCompare(x, y); + x = QmuFuzzyComparePossibleNulls(x, y); m_vRPN.pop_back(); break; case cmADD: @@ -342,7 +343,7 @@ void QmuParserByteCode::AddOp(ECmdCode a_Oprt) break; case cmDIV: if (m_vRPN.at(sz-1).Cmd == cmVAL && m_vRPN.at(sz-2).Cmd == cmVARMUL && - (qFuzzyCompare(m_vRPN.at(sz-1).Val.data2+1, 1+0)==false)) + not qFuzzyIsNull(m_vRPN.at(sz-1).Val.data2)) { // Optimization: 4*a/2 -> 2*a m_vRPN[sz-2].Val.data /= m_vRPN.at(sz-1).Val.data2; diff --git a/src/libs/qmuparser/qmuparsertest.cpp b/src/libs/qmuparser/qmuparsertest.cpp index f814d14d2..e1ff4869c 100644 --- a/src/libs/qmuparser/qmuparsertest.cpp +++ b/src/libs/qmuparser/qmuparsertest.cpp @@ -20,6 +20,7 @@ ******************************************************************************************************/ #include "qmuparsertest.h" +#include "qmudef.h" #include #include @@ -1345,7 +1346,7 @@ int QmuParserTester::EqnTest ( const QString &a_str, double a_fRes, bool a_fPass // String parsing and bytecode parsing must yield the same result fVal[0] = p1->Eval(); // result from stringparsing fVal[1] = p1->Eval(); // result from bytecode - if ( qFuzzyCompare( fVal[0], fVal[1] ) == false ) + if ( not QmuFuzzyComparePossibleNulls( fVal[0], fVal[1] ) ) { throw QmuParserError ( "Bytecode / string parsing mismatch." ); } @@ -1400,7 +1401,8 @@ int QmuParserTester::EqnTest ( const QString &a_str, double a_fRes, bool a_fPass #pragma warning(pop) #endif { - bCloseEnough &= (qFuzzyCompare( fabs ( fVal[i] ), std::numeric_limits::infinity())==false ); + bCloseEnough &= (not QmuFuzzyComparePossibleNulls( fabs ( fVal[i] ), + std::numeric_limits::infinity()) ); } } @@ -1422,8 +1424,9 @@ int QmuParserTester::EqnTest ( const QString &a_str, double a_fRes, bool a_fPass { if ( a_fPass ) { - if ( (qFuzzyCompare(fVal[0], fVal[2])==false) && (qFuzzyCompare(fVal[0], -999)==false) && - (qFuzzyCompare(fVal[1], -998 )==false)) + if ( not QmuFuzzyComparePossibleNulls(fVal[0], fVal[2]) && + not QmuFuzzyComparePossibleNulls(fVal[0], -999) && + not QmuFuzzyComparePossibleNulls(fVal[1], -998 )) { qWarning() << "\n fail: " << a_str << " (copy construction)"; } diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 208545345..b807b3f61 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -165,8 +165,8 @@ QPointF VArc::GetP2 () const */ qreal VArc::AngleArc() const { - if ((qFuzzyCompare(d->f1+1, 0+1) && qFuzzyCompare(d->f2, 360)) || - (qFuzzyCompare(d->f1, 360) && qFuzzyCompare(d->f2+1, 0+1))) + if ((qFuzzyIsNull(d->f1) && qFuzzyCompare(d->f2, 360)) || + (qFuzzyCompare(d->f1, 360) && qFuzzyIsNull(d->f2))) { return 360; } diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 5b56a474c..be50f5d6d 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -198,12 +198,12 @@ QPointF VEllipticalArc::GetPoint (qreal angle) const { y = -y; } - else if (qFuzzyCompare(angle, 90)) + else if (VFuzzyComparePossibleNulls(angle, 90)) { x = 0; y = d->radius2; } - else if (qFuzzyCompare(angle, 270)) + else if (VFuzzyComparePossibleNulls(angle, 270)) { x = 0; y = -d->radius2; diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index 8bcab8340..adab12b34 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -304,7 +304,8 @@ QPointF VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line) //--------------------------------------------------------------------------------------------------------------------- int VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2) { - if (qFuzzyCompare(c1.x(), c2.x()) && qFuzzyCompare(c1.y(), c2.y()) && qFuzzyCompare(r1, r2)) + if (VFuzzyComparePossibleNulls(c1.x(), c2.x()) && VFuzzyComparePossibleNulls(c1.y(), c2.y()) + && VFuzzyComparePossibleNulls(r1, r2)) { return 3;// Circles are equal } @@ -319,7 +320,7 @@ int VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF &c { return 0; } - else if (qFuzzyCompare(c*c, r1*r1*(a*a+b*b))) + else if (VFuzzyComparePossibleNulls(c*c, r1*r1*(a*a+b*b))) { p1 = QPointF(x0 + c1.x(), y0 + c1.y()); return 1; @@ -360,7 +361,7 @@ qint32 VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const // how many solutions? qint32 flag = 0; const qreal d = QLineF (center, p).length(); - if (qFuzzyCompare(d, radius)) + if (VFuzzyComparePossibleNulls(d, radius)) { flag = 1; } @@ -507,7 +508,7 @@ double VGObject::GetEpsilon(const QPointF &p1, const QPointF &p2) int VGObject::PointInCircle(const QPointF &p, const QPointF ¢er, qreal radius) { const double d = QLineF (p, center).length(); - if (qFuzzyCompare(radius, d)) + if (VFuzzyComparePossibleNulls(radius, d)) { return 1; // on circle } diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 69b2a85c8..9fb3eef30 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -412,7 +412,7 @@ qint32 VSpline::Cubic(QVector &x, qreal a, qreal b, qreal c) x.insert(0, aa+bb-a/3.); // Real root x.insert(1, (-0.5)*(aa+bb)-a/3.); //Complex root x.insert(2, (sqrt(3.)*0.5)*fabs(aa-bb)); // Complex root - if (qFuzzyCompare(x.at(2) + 1, 0. + 1)) + if (qFuzzyIsNull(x.at(2))) { return(2); } diff --git a/src/libs/vgeometry/vsplinepoint_p.h b/src/libs/vgeometry/vsplinepoint_p.h index fd1b34e1f..909d98366 100644 --- a/src/libs/vgeometry/vsplinepoint_p.h +++ b/src/libs/vgeometry/vsplinepoint_p.h @@ -30,9 +30,11 @@ #define VSPLINEPOINT_P_H #include -#include "vpointf.h" #include +#include "vpointf.h" +#include "../vmisc/def.h" + #ifdef Q_CC_GNU #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" @@ -57,9 +59,9 @@ public: kAsm1(kAsm1), kAsm2(kAsm2) { - if (not qFuzzyCompare(qAbs(angle1-angle2), 180) || qFuzzyIsNull(qAbs(angle1-angle2))) + if (VFuzzyComparePossibleNulls(angle1, angle2) || not qFuzzyCompare(qAbs(angle1-angle2), 180) ) { - qDebug()<<"angle1 and angle2 are not equal."; + qDebug()<<"Make angle1 and angle2 correct."; this->angle1 = angle1; this->angle2 = angle1 + 180; } @@ -127,9 +129,9 @@ public: length2(length2), length2F(length2F) { - if (not qFuzzyCompare(qAbs(angle1-angle2), 180) || qFuzzyIsNull(qAbs(angle1-angle2))) + if (VFuzzyComparePossibleNulls(angle1, angle2) || not qFuzzyCompare(qAbs(angle1-angle2), 180)) { - qDebug()<<"angle1 and angle2 are not equal."; + qDebug()<<"Make angle1 and angle2 correct."; this->angle2 = angle1 + 180; this->angle2F = QString().number(angle2); } diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index a4b216b93..db5f5007c 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -501,7 +501,7 @@ VPosition::InsideType VPosition::InsideContour(const VLayoutDetail &detail, cons const qreal xj = gContour.at(j).x(); //-V807 const qreal yi = gContour.at(i).y(); const qreal yj = gContour.at(j).y(); - if (qFuzzyCompare(yj, yi)) + if (VFuzzyComparePossibleNulls(yj, yi)) { constant.insert(i, xi); multiple.insert(i, 0); @@ -539,7 +539,7 @@ VPosition::InsideType VPosition::InsideContour(const VLayoutDetail &detail, cons const qreal yi = gContour.at(i).y(); const qreal yj = gContour.at(j).y(); - const QPointF &pn = p.at(n); + const QPointF &pn = p.at(n); if (((yi < pn.y() && yj >= pn.y()) || (yj < pn.y() && yi >= pn.y()))) { oddNodes ^= (pn.y() * multiple.at(i) + constant.at(i) < pn.x()); @@ -586,7 +586,7 @@ void VPosition::CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, co // Now we move detail to position near to global contour edge. detail.Translate(dx, dy); - if (not qFuzzyCompare(angle_between+360, 0+360)) + if (not qFuzzyIsNull(angle_between) || not qFuzzyCompare(angle_between, 360)) { detail.Rotate(detailEdge.p2(), -angle_between); } @@ -675,7 +675,7 @@ QVector VPosition::CutEdge(const QLineF &edge, quint32 shift) void VPosition::Rotate(int increase) { int startAngle = 0; - if (qFuzzyCompare(angle_between+360, 0+360)) + if (VFuzzyComparePossibleNulls(angle_between, 360)) { startAngle = increase; } diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 28afb2291..cdd2b5c4c 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -606,4 +606,20 @@ QSharedPointer DefaultPrinter(); QPixmap darkenPixmap(const QPixmap &pixmap); +static inline bool VFuzzyComparePossibleNulls(double p1, double p2) +{ + if(qFuzzyIsNull(p1)) + { + return qFuzzyIsNull(p2); + } + else if(qFuzzyIsNull(p2)) + { + return false; + } + else + { + return qFuzzyCompare(p1, p2); + } +} + #endif // DEF_H diff --git a/src/libs/vpatterndb/variables/vvariable.cpp b/src/libs/vpatterndb/variables/vvariable.cpp index ac3a2d44c..9063656c2 100644 --- a/src/libs/vpatterndb/variables/vvariable.cpp +++ b/src/libs/vpatterndb/variables/vvariable.cpp @@ -94,7 +94,7 @@ void VVariable::SetValue(const qreal &size, const qreal &height, Unit patternUni //--------------------------------------------------------------------------------------------------------------------- bool VVariable::IsNotUsed() const { - if (qFuzzyCompare(d->base+1, 0+1) && qFuzzyCompare(d->ksize+1, 0+1) && qFuzzyCompare(d->kheight+1, 0+1)) + if (qFuzzyIsNull(d->base) && qFuzzyIsNull(d->ksize) && qFuzzyIsNull(d->kheight)) { return true; } diff --git a/src/libs/vpatterndb/vformula.cpp b/src/libs/vpatterndb/vformula.cpp index 8d28c3aa4..8e60633d2 100644 --- a/src/libs/vpatterndb/vformula.cpp +++ b/src/libs/vpatterndb/vformula.cpp @@ -82,7 +82,7 @@ bool VFormula::operator==(const VFormula &formula) const if (this->formula == formula.GetFormula() && this->value == formula.getStringValue() && this->checkZero == formula.getCheckZero() && this->data == formula.getData() && this->toolId == formula.getToolId() && this->postfix == formula.getPostfix() && - this->_error == formula.error() && qFuzzyCompare(this->dValue, formula.getDoubleValue())) + this->_error == formula.error() && VFuzzyComparePossibleNulls(this->dValue, formula.getDoubleValue())) { isEqual = true; } @@ -232,7 +232,7 @@ void VFormula::Eval() delete cal; //if result equal 0 - if (checkZero && qFuzzyCompare(1 + result, 1 + 0)) + if (checkZero && qFuzzyIsNull(result)) { value = QString("0"); _error = true; diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index 5bb33ed3f..81d0eeaac 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -396,7 +396,7 @@ void DialogArc::CheckAngles() return; } - if (qFuzzyCompare(angleF1 + 1, angleF2 + 1)) + if (VFuzzyComparePossibleNulls(angleF1, angleF2)) { flagF1 = false; ChangeColor(ui->labelEditF1, Qt::red); diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index b54039acd..80f68fcc6 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -368,7 +368,7 @@ void DialogArcWithLength::Length() const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); const qreal length = Eval(ui->plainTextEditLength->toPlainText(), flagLength, ui->labelResultLength, postfix); - if (qFuzzyCompare(length+1, 0+1)) + if (qFuzzyIsNull(length)) { flagLength = false; ChangeColor(labelEditFormula, Qt::red); diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 051def095..92b24c48e 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -480,7 +480,7 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt delete cal; //if result equal 0 - if (checkZero && qFuzzyCompare(1 + result, 1 + 0)) + if (checkZero && qFuzzyIsNull(result)) { flag = false; ChangeColor(labelEditFormula, Qt::red); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index 34bf9a97f..69ab52c63 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -244,7 +244,7 @@ void VToolArc::SetFormulaF1(const VFormula &value) QSharedPointer obj = VAbstractTool::data.GetGObject(id); QSharedPointer arc = qSharedPointerDynamicCast(obj); - if (qFuzzyCompare(value.getDoubleValue() + 1, arc->GetEndAngle() + 1)==false)// Angles can't be equal + if (not VFuzzyComparePossibleNulls(value.getDoubleValue(), arc->GetEndAngle()))// Angles can't be equal { arc->SetFormulaF1(value.GetFormula(FormulaType::FromUser), value.getDoubleValue()); SaveOption(obj); @@ -272,7 +272,7 @@ void VToolArc::SetFormulaF2(const VFormula &value) { QSharedPointer obj = VAbstractTool::data.GetGObject(id); QSharedPointer arc = qSharedPointerDynamicCast(obj); - if (qFuzzyCompare(value.getDoubleValue() + 1, arc->GetStartAngle() + 1)==false)// Angles can't be equal + if (not VFuzzyComparePossibleNulls(value.getDoubleValue(), arc->GetStartAngle()))// Angles can't be equal { arc->SetFormulaF2(value.GetFormula(FormulaType::FromUser), value.getDoubleValue()); SaveOption(obj); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index 473e2a933..804413fa7 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -213,7 +213,7 @@ void VToolArcWithLength::SetFormulaF1(const VFormula &value) QSharedPointer obj = VAbstractTool::data.GetGObject(id); QSharedPointer arc = qSharedPointerDynamicCast(obj); - if (qFuzzyCompare(value.getDoubleValue() + 1, arc->GetEndAngle() + 1)==false)// Angles can't be equal + if (not VFuzzyComparePossibleNulls(value.getDoubleValue(), arc->GetEndAngle()))// Angles can't be equal { arc->SetFormulaF1(value.GetFormula(FormulaType::FromUser), value.getDoubleValue()); SaveOption(obj); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp index 78628a79f..576ee48b2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp @@ -100,7 +100,7 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li qDebug()<<"Correction of length in shoulder point tool. Parameter length too small."; toolLength = dist; } - if (qFuzzyCompare(dist, toolLength)) + if (VFuzzyComparePossibleNulls(dist, toolLength)) { return line.p2(); } diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 0cce48dde..d895ed931 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -112,7 +112,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte { case (Tool::NodePoint): { - if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) + if ( qFuzzyIsNull(dx) && qFuzzyIsNull(dy) && (pRotate == 0)) { id = det.at(i).getId(); } @@ -133,7 +133,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte break; case (Tool::NodeArc): { - if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyIsNull(dx) && qFuzzyIsNull(dy) && pRotate == 0) { id = det.at(i).getId(); } @@ -170,7 +170,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte break; case (Tool::NodeSpline): { - if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyIsNull(dx) && qFuzzyIsNull(dy) && pRotate == 0) { id = det.at(i).getId(); } @@ -207,7 +207,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte break; case (Tool::NodeSplinePath): { - if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyIsNull(dx) && qFuzzyIsNull(dy) && pRotate == 0) { id = det.at(i).getId(); } @@ -297,7 +297,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { case (Tool::NodePoint): { - if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) { VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); point->setMode(Draw::Modeling); @@ -308,7 +308,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const break; case (Tool::NodeArc): { - if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) { const QPointF p = data->GeometricObject(pRotate)->toQPointF(); const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); @@ -334,7 +334,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const break; case (Tool::NodeSpline): { - if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) { const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); @@ -360,7 +360,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const break; case (Tool::NodeSplinePath): { - if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) + if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) { VSplinePath *path = new VSplinePath(); path->setMode(Draw::Modeling); diff --git a/src/libs/vtools/visualization/vistoolalongline.cpp b/src/libs/vtools/visualization/vistoolalongline.cpp index 3451cc265..b5361ca73 100644 --- a/src/libs/vtools/visualization/vistoolalongline.cpp +++ b/src/libs/vtools/visualization/vistoolalongline.cpp @@ -79,7 +79,7 @@ void VisToolAlongLine::RefreshGeometry() DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), supportColor); - if (qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(length)) { QLineF mainLine = VGObject::BuildLine(first->toQPointF(), length, line->line().angle()); DrawLine(this, mainLine, mainColor, lineStyle); diff --git a/src/libs/vtools/visualization/vistoolarc.cpp b/src/libs/vtools/visualization/vistoolarc.cpp index 7ac5e3f2c..2e3899919 100644 --- a/src/libs/vtools/visualization/vistoolarc.cpp +++ b/src/libs/vtools/visualization/vistoolarc.cpp @@ -50,7 +50,7 @@ void VisToolArc::RefreshGeometry() const QSharedPointer first = Visualization::data->GeometricObject(object1Id); DrawPoint(arcCenter, first->toQPointF(), supportColor); - if (qFuzzyCompare(1 + radius, 1 + 0) == false && f1 >= 0 && f2 >= 0 && qFuzzyCompare(1 + f1, 1 + f2) == false) + if (not qFuzzyIsNull(radius) && f1 >= 0 && f2 >= 0 && not VFuzzyComparePossibleNulls(f1, f2)) { VArc arc = VArc (*first, radius, f1, f2); DrawPath(this, arc.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/vistoolarcwithlength.cpp index c33c082b5..78b593b46 100644 --- a/src/libs/vtools/visualization/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/vistoolarcwithlength.cpp @@ -50,7 +50,7 @@ void VisToolArcWithLength::RefreshGeometry() const QSharedPointer first = Visualization::data->GeometricObject(object1Id); DrawPoint(arcCenter, first->toQPointF(), supportColor); - if (qFuzzyCompare(1 + radius, 1 + 0) == false && f1 >= 0 && qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(radius) && f1 >= 0 && not qFuzzyIsNull(length)) { VArc arc = VArc (length, *first, radius, f1); DrawPath(this, arc.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/vistoolbisector.cpp b/src/libs/vtools/visualization/vistoolbisector.cpp index bb5ebf6b8..f7672b926 100644 --- a/src/libs/vtools/visualization/vistoolbisector.cpp +++ b/src/libs/vtools/visualization/vistoolbisector.cpp @@ -98,7 +98,7 @@ void VisToolBisector::RefreshGeometry() DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); - if (qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(length)) { qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(), third->toQPointF()); diff --git a/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp index af7a98363..fca148d86 100644 --- a/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp @@ -61,7 +61,7 @@ void VisToolCurveIntersectAxis::RefreshGeometry() { QLineF axis; const QSharedPointer first = Visualization::data->GeometricObject(axisPointId); - if (qFuzzyCompare(angle, -1)) + if (VFuzzyComparePossibleNulls(angle, -1)) { axis = Axis(first->toQPointF(), Visualization::scenePos); } diff --git a/src/libs/vtools/visualization/vistoolcutarc.cpp b/src/libs/vtools/visualization/vistoolcutarc.cpp index 9460b7914..dac213cfe 100644 --- a/src/libs/vtools/visualization/vistoolcutarc.cpp +++ b/src/libs/vtools/visualization/vistoolcutarc.cpp @@ -56,7 +56,7 @@ void VisToolCutArc::RefreshGeometry() const QSharedPointer arc = Visualization::data->GeometricObject(object1Id); DrawPath(this, arc->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); - if (qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(length)) { VArc ar1; VArc ar2; diff --git a/src/libs/vtools/visualization/vistoolcutspline.cpp b/src/libs/vtools/visualization/vistoolcutspline.cpp index 49cb7d81e..48da1306b 100644 --- a/src/libs/vtools/visualization/vistoolcutspline.cpp +++ b/src/libs/vtools/visualization/vistoolcutspline.cpp @@ -56,7 +56,7 @@ void VisToolCutSpline::RefreshGeometry() const auto spl = Visualization::data->GeometricObject(object1Id); DrawPath(this, spl->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); - if (qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(length)) { QPointF spl1p2; QPointF spl1p3; diff --git a/src/libs/vtools/visualization/vistoollineintersectaxis.cpp b/src/libs/vtools/visualization/vistoollineintersectaxis.cpp index 9cb606929..4d7946732 100644 --- a/src/libs/vtools/visualization/vistoollineintersectaxis.cpp +++ b/src/libs/vtools/visualization/vistoollineintersectaxis.cpp @@ -75,7 +75,7 @@ void VisToolLineIntersectAxis::RefreshGeometry() { QLineF axis; const QSharedPointer third = Visualization::data->GeometricObject(axisPointId); - if (qFuzzyCompare(angle, -1)) + if (VFuzzyComparePossibleNulls(angle, -1)) { axis = Axis(third->toQPointF(), Visualization::scenePos); } diff --git a/src/libs/vtools/visualization/vistoolnormal.cpp b/src/libs/vtools/visualization/vistoolnormal.cpp index b52227039..6145e9ce7 100644 --- a/src/libs/vtools/visualization/vistoolnormal.cpp +++ b/src/libs/vtools/visualization/vistoolnormal.cpp @@ -73,7 +73,7 @@ void VisToolNormal::RefreshGeometry() QLineF line_mouse(first->toQPointF(), second->toQPointF()); DrawLine(line, line_mouse, supportColor); - if (qFuzzyCompare(1 + length, 1 + 0)) + if (qFuzzyIsNull(length)) { QLineF normal = line_mouse.normalVector(); QPointF endRay = Ray(normal.p1(), normal.angle()); diff --git a/src/libs/vtools/visualization/vistoolpointofcontact.cpp b/src/libs/vtools/visualization/vistoolpointofcontact.cpp index 2bac802c7..a7a2e670b 100644 --- a/src/libs/vtools/visualization/vistoolpointofcontact.cpp +++ b/src/libs/vtools/visualization/vistoolpointofcontact.cpp @@ -74,7 +74,7 @@ void VisToolPointOfContact::RefreshGeometry() const QSharedPointer third = Visualization::data->GeometricObject(radiusId); DrawPoint(arc_point, third->toQPointF(), supportColor); - if (qFuzzyCompare(1 + radius, 1 + 0) == false) + if (not qFuzzyIsNull(radius)) { QPointF fPoint = VToolPointOfContact::FindPoint(radius, third->toQPointF(), first->toQPointF(), second->toQPointF()); diff --git a/src/libs/vtools/visualization/vistoolshoulderpoint.cpp b/src/libs/vtools/visualization/vistoolshoulderpoint.cpp index 24111f840..06c138c5f 100644 --- a/src/libs/vtools/visualization/vistoolshoulderpoint.cpp +++ b/src/libs/vtools/visualization/vistoolshoulderpoint.cpp @@ -80,7 +80,7 @@ void VisToolShoulderPoint::RefreshGeometry() DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); - if (qFuzzyCompare(1 + length, 1 + 0) == false) + if (not qFuzzyIsNull(length)) { QPointF fPoint = VToolShoulderPoint::FindPoint(second->toQPointF(), third->toQPointF(), first->toQPointF(), length); diff --git a/src/libs/vtools/visualization/vistoolspline.cpp b/src/libs/vtools/visualization/vistoolspline.cpp index bd7513db5..8629882aa 100644 --- a/src/libs/vtools/visualization/vistoolspline.cpp +++ b/src/libs/vtools/visualization/vistoolspline.cpp @@ -141,7 +141,7 @@ void VisToolSpline::RefreshGeometry() } } - if (qFuzzyCompare(angle1, EMPTY_ANGLE) || qFuzzyCompare(angle2, EMPTY_ANGLE)) + if (VFuzzyComparePossibleNulls(angle1, EMPTY_ANGLE) || VFuzzyComparePossibleNulls(angle2, EMPTY_ANGLE)) { VSpline spline(*first, p2, p3, *second); DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index 127d45022..838e282d6 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -192,7 +192,7 @@ void TST_VArc::TestGetPoints() { qreal gSquere = 0.0;// geometry square - if (qFuzzyCompare(arc.AngleArc(), 360.0)) + if (VFuzzyComparePossibleNulls(arc.AngleArc(), 360.0)) {// circle square gSquere = M_PI * radius * radius; } diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 810cb7562..6bfd7fa80 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -335,7 +335,7 @@ void TST_VEllipticalArc::TestGetPoints3() VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); QVector points = arc.GetPoints(); - if (qFuzzyCompare(arc.AngleArc(), 360.0)) + if (VFuzzyComparePossibleNulls(arc.AngleArc(), 360.0)) {// calculated full ellipse square const qreal ellipseSquare = M_PI * radius1 * radius2; const qreal epsSquare = ellipseSquare * 0.5 / 100; // computing error 0.5 % from origin squere @@ -361,7 +361,7 @@ void TST_VEllipticalArc::TestGetPoints4() const VPointF center; VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); - if (qFuzzyCompare(arc.AngleArc(), 360.0)) + if (VFuzzyComparePossibleNulls(arc.AngleArc(), 360.0)) {// calculated full ellipse length const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); const qreal ellipseLength = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)));