diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index e5a2498b0..b24b61134 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -133,7 +133,16 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis const qreal angle = CheckFormula(initData.id, initData.formulaAngle, initData.data); const QSharedPointer curve = initData.data->GeometricObject(initData.curveId); - const QPointF fPoint = FindPoint(static_cast(*basePoint), angle, curve->GetPoints()); + QPointF fPoint; + const bool success = FindPoint(static_cast(*basePoint), angle, curve->GetPoints(), &fPoint); + + if (not success) + { + qWarning() << tr("Error calculating point '%1'. There is no intersection with curve '%2' and axis through " + "point '%3' with angle %4°") + .arg(initData.name, curve->name(), basePoint->name()).arg(angle); + } + const qreal segLength = curve->GetLengthByPoint(fPoint); VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); @@ -176,9 +185,11 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis } //--------------------------------------------------------------------------------------------------------------------- -QPointF VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle, - const QVector &curvePoints) +bool VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle, const QVector &curvePoints, + QPointF *intersectionPoint) { + SCASSERT(intersectionPoint != nullptr) + QRectF rec = QRectF(0, 0, INT_MAX, INT_MAX); rec.translate(-INT_MAX/2.0, -INT_MAX/2.0); @@ -189,7 +200,8 @@ QPointF VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle, { if (points.size() == 1) { - return points.at(0); + *intersectionPoint = points.at(0); + return true; } QMap forward; @@ -216,15 +228,17 @@ QPointF VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle, // Closest point is not always want we need. First return point in forward direction if exists. if (not forward.isEmpty()) { - return points.at(forward.first()); + *intersectionPoint = points.at(forward.first()); + return true; } else if (not backward.isEmpty()) { - return points.at(backward.first()); + *intersectionPoint = points.at(backward.first()); + return true; } } - return QPointF(); + return false; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h index 16f644062..6b7b948a9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h @@ -71,7 +71,8 @@ public: VAbstractPattern *doc, VContainer *data); static VToolCurveIntersectAxis *Create(VToolCurveIntersectAxisInitData &initData); - static QPointF FindPoint(const QPointF &point, qreal angle, const QVector &curvePoints); + static bool FindPoint(const QPointF &point, qreal angle, const QVector &curvePoints, + QPointF *intersectionPoint); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index 9ab07f906..1e53efd74 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -124,7 +124,15 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(VToolLineIntersectAxisIni const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); QLineF line(static_cast(*firstPoint), static_cast(*secondPoint)); - QPointF fPoint = FindPoint(axis, line); + QPointF fPoint; + const bool success = FindPoint(axis, line, &fPoint); + + if (not success) + { + qWarning() << tr("Error calculating point '%1'. Line (%2;%3) doesn't have intersection with axis through " + "point '%4' and angle %5°") + .arg(initData.name, firstPoint->name(), secondPoint->name(), basePoint->name()).arg(axis.angle()); + } VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); @@ -164,8 +172,10 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(VToolLineIntersectAxisIni } //--------------------------------------------------------------------------------------------------------------------- -QPointF VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line) +bool VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line, QPointF *intersectionPoint) { + SCASSERT(intersectionPoint != nullptr) + QPointF fPoint; QLineF::IntersectType intersect = axis.intersect(line, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) @@ -173,16 +183,17 @@ QPointF VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line if(VFuzzyComparePossibleNulls(axis.angle(), line.angle()) || VFuzzyComparePossibleNulls(qAbs(axis.angle() - line.angle()), 180)) { - return QPointF(); + return false; } else { - return fPoint; + *intersectionPoint = fPoint; + return true; } } else { - return QPointF(); + return false; } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h index a6c82f5a3..4c4f633c0 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h @@ -73,7 +73,7 @@ public: VAbstractPattern *doc, VContainer *data); static VToolLineIntersectAxis *Create(VToolLineIntersectAxisInitData &initData); - static QPointF FindPoint(const QLineF &axis, const QLineF &line); + static bool FindPoint(const QLineF &axis, const QLineF &line, QPointF *intersectionPoint); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp index f77007e00..e587be69c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp @@ -112,8 +112,15 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromA const VArc arc = *initData.data->GeometricObject(initData.arcId); const VPointF tPoint = *initData.data->GeometricObject(initData.tangentPointId); - const QPointF point = VToolPointFromArcAndTangent::FindPoint(static_cast(tPoint), &arc, - initData.crossPoint); + QPointF point; + const bool success = VToolPointFromArcAndTangent::FindPoint(static_cast(tPoint), &arc, + initData.crossPoint, &point); + + if (not success) + { + qWarning() << tr("Error calculating point '%1'. Tangent to arc '%2' from point '%3' cannot be found") + .arg(initData.name, arc.name(), tPoint.name()); + } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); @@ -146,8 +153,11 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromA } //--------------------------------------------------------------------------------------------------------------------- -QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType) +bool VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType, + QPointF *intersectionPoint) { + SCASSERT(intersectionPoint != nullptr) + QPointF p1, p2; const QPointF center = static_cast(arc->GetCenter()); const qreal radius = arc->GetRadius(); @@ -180,26 +190,14 @@ QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc switch(localRes) { case 2: - if (pType == CrossCirclesPoint::FirstPoint) - { - return p1; - } - else - { - return p2; - } + *intersectionPoint = (pType == CrossCirclesPoint::FirstPoint ? p1 : p2); + return true; case 1: - if (flagP1) - { - return p1; - } - else - { - return p2; - } + *intersectionPoint = (flagP1 ? p1 : p2); + return true; case 0: default: - return QPointF(); + return false; } break; @@ -207,18 +205,19 @@ QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc case 1: if (arc->IsIntersectLine(r1Arc)) { - return p1; + *intersectionPoint = p1; + return true; } else { - return QPointF(); + return false; } case 3: case 0: default: break; } - return QPointF(); + return false; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h index 7140011e8..29b35373a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h @@ -66,7 +66,7 @@ public: static VToolPointFromArcAndTangent *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolPointFromArcAndTangent *Create(VToolPointFromArcAndTangentInitData initData); - static QPointF FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType); + static bool FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType, QPointF *intersectionPoint); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::PointFromArcAndTangent) }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index 21f8811b1..6addf2b09 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -117,9 +117,16 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPoin const VPointF cPoint = *initData.data->GeometricObject(initData.circleCenterId); const VPointF tPoint = *initData.data->GeometricObject(initData.tangentPointId); - const QPointF point = VToolPointFromCircleAndTangent::FindPoint(static_cast(tPoint), - static_cast(cPoint), radius, - initData.crossPoint); + QPointF point; + const bool success = VToolPointFromCircleAndTangent::FindPoint(static_cast(tPoint), + static_cast(cPoint), radius, + initData.crossPoint, &point); + if (not success) + { + qWarning() << tr("Error calculating point '%1'. Tangent to circle with center '%2' and radius '%3' from " + "point '%4' cannot be found") + .arg(initData.name, cPoint.name()).arg(radius).arg(tPoint.name()); + } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); @@ -152,29 +159,26 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPoin } //--------------------------------------------------------------------------------------------------------------------- -QPointF VToolPointFromCircleAndTangent::FindPoint(const QPointF &p, const QPointF ¢er, qreal radius, - const CrossCirclesPoint crossPoint) +bool VToolPointFromCircleAndTangent::FindPoint(const QPointF &p, const QPointF ¢er, qreal radius, + const CrossCirclesPoint crossPoint, QPointF *intersectionPoint) { + SCASSERT(intersectionPoint != nullptr) + QPointF p1, p2; const int res = VGObject::ContactPoints (p, center, radius, p1, p2); switch(res) { case 2: - if (crossPoint == CrossCirclesPoint::FirstPoint) - { - return p1; - } - else - { - return p2; - } + *intersectionPoint = (crossPoint == CrossCirclesPoint::FirstPoint ? p1 : p2); + return true; case 1: - return p1; + *intersectionPoint = p1; + return true; case 3: case 0: default: - return QPointF(); + return false; } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h index 2e382bd0e..3fecca8ba 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h @@ -69,7 +69,8 @@ public: static VToolPointFromCircleAndTangent *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolPointFromCircleAndTangent *Create(VToolPointFromCircleAndTangentInitData &initData); - static QPointF FindPoint(const QPointF &p, const QPointF ¢er, qreal radius, const CrossCirclesPoint crossPoint); + static bool FindPoint(const QPointF &p, const QPointF ¢er, qreal radius, const CrossCirclesPoint crossPoint, + QPointF *intersectionPoint); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::PointFromCircleAndTangent) }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index 525a6355f..30e092070 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -100,19 +100,23 @@ void VToolPointOfContact::setDialog() * @param center center arc point. * @param firstPoint first line point. * @param secondPoint second line point. - * @return point intersection. + * @param intersectionPoint point of intersection. + * @return true if intersection exists. */ -QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, - const QPointF &secondPoint) +bool VToolPointOfContact::FindPoint(qreal radius, const QPointF ¢er, const QPointF &firstPoint, + const QPointF &secondPoint, QPointF *intersectionPoint) { + SCASSERT(intersectionPoint != nullptr) + QPointF p1, p2; qint32 res = VGObject::LineIntersectCircle(center, radius, QLineF(firstPoint, secondPoint), p1, p2); switch (res) { case 0: - return QPointF(); + return false; case 1: - return p1; + *intersectionPoint = p1; + return true; case 2: { const bool flagP1 = VGObject::IsPointOnLineSegment (p1, firstPoint, secondPoint); @@ -123,22 +127,26 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e // We don't have options for choosing correct point. Use closest to segment first point. if (QLineF(firstPoint, p1).length() <= QLineF(firstPoint, p2).length()) { - return p1; + *intersectionPoint = p1; + return true; } else { - return p2; + *intersectionPoint = p2; + return true; } } else { // In this case we have one real and one theoretical intersection. if (flagP1) { - return p1; + *intersectionPoint = p1; + return true; } else { - return p2; + *intersectionPoint = p2; + return true; } } } @@ -146,7 +154,7 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e qDebug() << "Unxpected value" << res; break; } - return QPointF(); + return false; } //--------------------------------------------------------------------------------------------------------------------- @@ -197,8 +205,17 @@ VToolPointOfContact* VToolPointOfContact::Create(VToolPointOfContactInitData &in const qreal result = CheckFormula(initData.id, initData.radius, initData.data); - QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), static_cast(*centerP), - static_cast(*firstP), static_cast(*secondP)); + QPointF fPoint; + const bool success = VToolPointOfContact::FindPoint(qApp->toPixel(result), static_cast(*centerP), + static_cast(*firstP), static_cast(*secondP), + &fPoint); + + if (not success) + { + qWarning() << tr("Error calculating point '%1'. Circle with center '%2' and radius '%3' doesn't have " + "intersection with line (%4;%5)") + .arg(initData.name, centerP->name()).arg(result).arg(firstP->name(), secondP->name()); + } VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h index 92f6c0c1b..4f8327798 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h @@ -69,8 +69,8 @@ class VToolPointOfContact : public VToolSinglePoint Q_OBJECT public: virtual void setDialog() Q_DECL_OVERRIDE; - static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, - const QPointF &secondPoint); + static bool FindPoint(qreal radius, const QPointF ¢er, const QPointF &firstPoint, + const QPointF &secondPoint, QPointF *intersectionPoint); static VToolPointOfContact* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolPointOfContact* Create(VToolPointOfContactInitData &initData); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp index f857c6b10..eb4dabfc9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp @@ -126,7 +126,7 @@ VToolTriangle* VToolTriangle::Create(QSharedPointer dialog, VMainGra //--------------------------------------------------------------------------------------------------------------------- /** - * @brief Create help create tool. + * @brief Create helps to create the tool. * @param initData init data. * @return the created tool */ @@ -137,8 +137,15 @@ VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData) const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); - QPointF point = FindPoint(static_cast(*axisP1), static_cast(*axisP2), - static_cast(*firstPoint), static_cast(*secondPoint)); + QPointF point; + const bool success = FindPoint(static_cast(*axisP1), static_cast(*axisP2), + static_cast(*firstPoint), static_cast(*secondPoint), &point); + + if (not success) + { + qWarning() << tr("Error calculating point '%1'. Point of intersection cannot be finded") + .arg(initData.name); + } VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); @@ -179,11 +186,14 @@ VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData) * @param axisP2 second axis point. * @param firstPoint first triangle point, what lies on the hypotenuse. * @param secondPoint second triangle point, what lies on the hypotenuse. - * @return point intersection two foots right triangle. + * @param intersectionPoint point intersection two foots right triangle + * @return true if the intersection exists. */ -QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, - const QPointF &secondPoint) +bool VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, + const QPointF &secondPoint, QPointF *intersectionPoint) { + SCASSERT(intersectionPoint != nullptr) + QLineF axis(axisP1, axisP2); QLineF hypotenuse(firstPoint, secondPoint); @@ -191,12 +201,12 @@ QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, c QLineF::IntersectType intersect = axis.intersect(hypotenuse, &startPoint); if (intersect != QLineF::UnboundedIntersection && intersect != QLineF::BoundedIntersection) { - return QPointF(); + return false; } if (VFuzzyComparePossibleNulls(axis.angle(), hypotenuse.angle()) || VFuzzyComparePossibleNulls(qAbs(axis.angle() - hypotenuse.angle()), 180)) { - return QPointF(); + return false; } qreal step = 1; @@ -214,10 +224,11 @@ QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, c qint64 b = qFloor(QLineF(line.p2(), secondPoint).length()); if (c*c <= (a*a + b*b)) { - return line.p2(); + *intersectionPoint = line.p2(); + return true; } } - return QPointF(); + return false; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h index 56079ce02..1dafdcfd5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h @@ -72,8 +72,8 @@ public: static VToolTriangle *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolTriangle *Create(VToolTriangleInitData initData); - static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, - const QPointF &secondPoint); + static bool FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, + const QPointF &secondPoint, QPointF *intersectionPoint); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Triangle)}; diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp index 666cbf8ab..0926fd34f 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp @@ -83,8 +83,8 @@ void VisToolCurveIntersectAxis::RefreshGeometry() DrawPoint(basePoint, static_cast(*first), mainColor); DrawLine(axisLine, axis, supportColor, Qt::DashLine); - QPointF p = VToolCurveIntersectAxis::FindPoint(static_cast(*first), axis.angle(), - curve->GetPoints()); + QPointF p; + VToolCurveIntersectAxis::FindPoint(static_cast(*first), axis.angle(), curve->GetPoints(), &p); QLineF axis_line(static_cast(*first), p); DrawLine(this, axis_line, mainColor, lineStyle); diff --git a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp index f21da50b5..bc8f4c1eb 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp @@ -94,7 +94,8 @@ void VisToolLineIntersectAxis::RefreshGeometry() DrawPoint(basePoint, static_cast(*third), mainColor); DrawLine(axisLine, axis, supportColor, Qt::DashLine); - QPointF p = VToolLineIntersectAxis::FindPoint(axis, base_line); + QPointF p; + VToolLineIntersectAxis::FindPoint(axis, base_line, &p); QLineF axis_line(static_cast(*third), p); DrawLine(this, axis_line, mainColor, lineStyle); diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp index 8ae95d4a2..e145a94c1 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp @@ -72,8 +72,8 @@ void VisToolPointFromArcAndTangent::RefreshGeometry() FindRays(static_cast(*tan), arc.data()); - const QPointF fPoint = VToolPointFromArcAndTangent::FindPoint(static_cast(*tan), arc.data(), - crossPoint); + QPointF fPoint; + VToolPointFromArcAndTangent::FindPoint(static_cast(*tan), arc.data(), crossPoint, &fPoint); DrawPoint(point, fPoint, mainColor); } } diff --git a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp index 810a7f56a..c0135d3ff 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp @@ -74,9 +74,9 @@ void VisToolPointFromCircleAndTangent::RefreshGeometry() FindRays(static_cast(*tan), static_cast(*center), cRadius); - const QPointF fPoint = VToolPointFromCircleAndTangent::FindPoint(static_cast(*tan), - static_cast(*center), - cRadius, crossPoint); + QPointF fPoint; + VToolPointFromCircleAndTangent::FindPoint(static_cast(*tan), static_cast(*center), + cRadius, crossPoint, &fPoint); DrawPoint(point, fPoint, mainColor); } } diff --git a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp index 2d7e49666..72c03684c 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp @@ -80,9 +80,9 @@ void VisToolPointOfContact::RefreshGeometry() if (not qFuzzyIsNull(radius)) { - QPointF fPoint = VToolPointOfContact::FindPoint(radius, static_cast(*third), - static_cast(*first), - static_cast(*second)); + QPointF fPoint; + VToolPointOfContact::FindPoint(radius, static_cast(*third), static_cast(*first), + static_cast(*second), &fPoint); DrawPoint(point, fPoint, mainColor); circle->setRect(PointRect(radius)); diff --git a/src/libs/vtools/visualization/line/vistooltriangle.cpp b/src/libs/vtools/visualization/line/vistooltriangle.cpp index 2ee968c53..7c1d8d079 100644 --- a/src/libs/vtools/visualization/line/vistooltriangle.cpp +++ b/src/libs/vtools/visualization/line/vistooltriangle.cpp @@ -91,9 +91,9 @@ void VisToolTriangle::RefreshGeometry() DrawLine(this, QLineF(static_cast(*third), Visualization::scenePos), supportColor, Qt::DashLine); - QPointF trPoint = VToolTriangle::FindPoint(static_cast(*first), - static_cast(*second), - static_cast(*third), Visualization::scenePos); + QPointF trPoint; + VToolTriangle::FindPoint(static_cast(*first), static_cast(*second), + static_cast(*third), Visualization::scenePos, &trPoint); DrawPoint(point, trPoint, mainColor); DrawLine(foot1, QLineF(static_cast(*third), trPoint), supportColor, Qt::DashLine); @@ -107,10 +107,9 @@ void VisToolTriangle::RefreshGeometry() DrawLine(this, QLineF(static_cast(*third), static_cast(*forth)), supportColor, Qt::DashLine); - QPointF trPoint = VToolTriangle::FindPoint(static_cast(*first), - static_cast(*second), - static_cast(*third), - static_cast(*forth)); + QPointF trPoint; + VToolTriangle::FindPoint(static_cast(*first), static_cast(*second), + static_cast(*third), static_cast(*forth), &trPoint); DrawPoint(point, trPoint, mainColor); DrawLine(foot1, QLineF(static_cast(*third), trPoint), supportColor, Qt::DashLine); diff --git a/src/test/ValentinaTest/tst_findpoint.cpp b/src/test/ValentinaTest/tst_findpoint.cpp index 77712d0ac..24d423b4f 100644 --- a/src/test/ValentinaTest/tst_findpoint.cpp +++ b/src/test/ValentinaTest/tst_findpoint.cpp @@ -235,7 +235,8 @@ void TST_FindPoint::TestLineIntersectAxis() QFETCH(QLineF, line); QFETCH(QPointF, point); - QPointF resultPoint = VToolLineIntersectAxis::FindPoint(axis, line); + QPointF resultPoint; + VToolLineIntersectAxis::FindPoint(axis, line, &resultPoint); QCOMPARE(point, resultPoint); } @@ -266,7 +267,8 @@ void TST_FindPoint::TestTriangle() QFETCH(QPointF, secondPoint); QFETCH(QPointF, point); - QPointF resultPoint = VToolTriangle::FindPoint(axisP1, axisP2, firstPoint, secondPoint); + QPointF resultPoint; + VToolTriangle::FindPoint(axisP1, axisP2, firstPoint, secondPoint, &resultPoint); QCOMPARE(point, resultPoint); } @@ -544,7 +546,8 @@ void TST_FindPoint::TestCurveIntersectAxis() QFETCH(QVector, curvePoints); QFETCH(QPointF, result); - const QPointF resultPoint = VToolCurveIntersectAxis::FindPoint(basePoint, angle, curvePoints); + QPointF resultPoint; + VToolCurveIntersectAxis::FindPoint(basePoint, angle, curvePoints, &resultPoint); QCOMPARE(result, resultPoint); }