From a667fdce1c44980cf88a046a04805f90f95172fc Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 6 Aug 2019 16:37:55 +0300 Subject: [PATCH] New function IsLineSegmentOnLineSegment(). Helps to find if two segments are on same line have real intersection. --HG-- branch : develop --- src/libs/vgeometry/vgobject.cpp | 18 ++++++++++++++++++ src/libs/vgeometry/vgobject.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index d7bb0cea7..78d5ae5a6 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -472,6 +472,24 @@ bool VGObject::IsPointOnLineSegment(const QPointF &t, const QPointF &p1, const Q return IsPointOnLineviaPDP(t, p1, p2, accuracy); } +//--------------------------------------------------------------------------------------------------------------------- +bool VGObject::IsLineSegmentOnLineSegment(const QLineF &seg1, const QLineF &seg2, qreal accuracy) +{ + const bool onLine = IsPointOnLineviaPDP(seg1.p1(), seg2.p1(), seg2.p2(), accuracy) && + IsPointOnLineviaPDP(seg1.p2(), seg2.p1(), seg2.p2(), accuracy); + if (onLine) + { + return IsPointOnLineSegment(seg1.p1(), seg2.p1(), seg2.p2(), accuracy) || + IsPointOnLineSegment(seg1.p2(), seg2.p1(), seg2.p2(), accuracy) || + IsPointOnLineSegment(seg2.p1(), seg1.p1(), seg1.p2(), accuracy) || + IsPointOnLineSegment(seg2.p2(), seg1.p1(), seg1.p2(), accuracy); + } + else + { + return onLine; + } +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VGObject::CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2) { diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index be1790b7b..553788460 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -98,6 +98,8 @@ public: static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); static bool IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2, qreal accuracy = accuracyPointOnLine); + static bool IsLineSegmentOnLineSegment (const QLineF &seg1, const QLineF &seg2, + qreal accuracy = accuracyPointOnLine); static QPointF CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2); static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2, qreal accuracy = accuracyPointOnLine);