From 0f33cb63525847f144ff4be50fe721198dd4322b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 19 Mar 2015 16:20:25 +0200 Subject: [PATCH] Fixed bug with circle intersection. Case with one real and one theoretical intersection. --HG-- branch : release --- .../tools/drawTools/vtoolpointofcontact.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index f9af530ae..598370a08 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -106,15 +106,35 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e return p1; break; case 2: - if (QLineF(firstPoint, p1).length() <= QLineF(firstPoint, p2).length()) + { + const bool flagP1 = VGObject::PointInSegment (p1, firstPoint, secondPoint); + const bool flagP2 = VGObject::PointInSegment (p2, firstPoint, secondPoint); + if ((flagP1 == true && flagP2 == true) || + (flagP1 == false && flagP2 == false)/*In case we have something wrong*/) { - return p1; + // 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; + } + else + { + return p2; + } } else - { - return p2; + { // In this case we have one real and one theoretical intersection. + if (flagP1) + { + return p1; + } + else + { + return p2; + } } break; + } default: qDebug() << "Unxpected value" << res; return QPointF();