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);