From 6530b57a8a39ee2e265b94bb60a762e330ae6274 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 29 May 2015 11:03:16 +0300 Subject: [PATCH] Changes for issue #232. --HG-- branch : develop --- .../vtoolpointofintersectionarcs.cpp | 65 +++++++++++++++++-- src/libs/vgeometry/vabstractcurve.cpp | 7 ++ src/libs/vgeometry/vabstractcurve.h | 1 + 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp b/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp index 38fec5d57..883d2dc8c 100644 --- a/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersectionarcs.cpp @@ -129,21 +129,76 @@ QPointF VToolPointOfIntersectionArcs::FindPoint(const VArc *arc1, const VArc *ar const int res = VGObject::IntersectionCircles(arc1->GetCenter().toQPointF(), arc1->GetRadius(), arc2->GetCenter().toQPointF(), arc2->GetRadius(), p1, p2); + QLineF r1Arc1(arc1->GetCenter().toQPointF(), p1); + r1Arc1.setLength(r1Arc1.length()+10); + + QLineF r1Arc2(arc2->GetCenter().toQPointF(), p1); + r1Arc2.setLength(r1Arc2.length()+10); + + QLineF r2Arc1(arc1->GetCenter().toQPointF(), p2); + r2Arc1.setLength(r2Arc1.length()+10); + + QLineF r2Arc2(arc2->GetCenter().toQPointF(), p2); + r2Arc2.setLength(r2Arc2.length()+10); + switch(res) { case 2: - if (pType == CrossArcsPoint::FirstPoint) + { + int localRes = 0; + bool flagP1 = false; + + if (arc1->IsIntersectLine(r1Arc1) && arc2->IsIntersectLine(r1Arc2)) + { + ++localRes; + flagP1 = true; + } + + if (arc1->IsIntersectLine(r2Arc1) && arc2->IsIntersectLine(r2Arc2)) + { + ++localRes; + } + + switch(localRes) + { + case 2: + if (pType == CrossArcsPoint::FirstPoint) + { + return p1; + } + else + { + return p2; + } + break; + case 1: + if (flagP1) + { + return p1; + } + else + { + return p2; + } + break; + case 0: + default: + return QPointF(0, 0); + break; + } + + break; + } + case 1: + if (arc1->IsIntersectLine(r1Arc1) && arc2->IsIntersectLine(r1Arc2)) { return p1; } else { - return p2; + return QPointF(0, 0); } break; - case 1: - return p1; - break; case 3: case 0: default: diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index 79e7579d1..7e0047826 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -169,6 +169,13 @@ QVector VAbstractCurve::IntersectLine(const QLineF &line) const return intersections; } +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractCurve::IsIntersectLine(const QLineF &line) const +{ + const QVector points = IntersectLine(line); + return not points.isEmpty(); +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VAbstractCurve::ShowDirection(const QVector &points) const { diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index e6198a25a..54a949f5c 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -51,6 +51,7 @@ public: virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const; virtual qreal GetLength() const =0; virtual QVector IntersectLine(const QLineF &line) const; + virtual bool IsIntersectLine(const QLineF &line) const; protected: QPainterPath ShowDirection(const QVector &points) const; private: