From 950e4766820b66d9afc0bd37877652302b38f914 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 27 May 2019 17:13:57 +0300 Subject: [PATCH] New function VAbstractCurve::SubdividePath. --HG-- branch : develop --- src/libs/vgeometry/vabstractcurve.cpp | 68 +++++++++++++++++++++++++++ src/libs/vgeometry/vabstractcurve.h | 3 ++ 2 files changed, 71 insertions(+) diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index b22b3fbd8..4b4651482 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -262,6 +262,74 @@ bool VAbstractCurve::IsPointOnCurve(const QPointF &p) const return IsPointOnCurve(GetPoints(), p); } +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractCurve::SubdividePath(const QVector &points, QPointF p, QVector &sub1, + QVector &sub2) +{ + if (points.size() < 2) + { + return false; + } + + bool found = false; + sub1.clear(); + sub2.clear(); + + for (qint32 i = 0; i < points.count()-1; ++i) + { + if (not found) + { + if (IsPointOnLineSegment(p, points.at(i), points.at(i+1))) + { + if (not VFuzzyComparePoints(points.at(i), p)) + { + sub1.append(points.at(i)); + sub1.append(p); + } + else + { + if (not sub1.isEmpty()) + { + sub1.append(p); + } + } + + if (not VFuzzyComparePoints(points.at(i+1), p)) + { + sub2.append(p); + + if (i+1 == points.count()-1) + { + sub2.append(points.at(i+1)); + } + } + + found = true; + } + else + { + sub1.append(points.at(i)); + } + } + else + { + sub2.append(points.at(i)); + + if (i+1 == points.count()-1) + { + sub2.append(points.at(i+1)); + } + } + } + + if (not found) + { + sub1.clear(); + } + + return found; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VAbstractCurve::GetDuplicate() const { diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index c57e5e5b8..6dab65fc3 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -77,6 +77,9 @@ public: static bool IsPointOnCurve(const QVector &points, const QPointF &p); bool IsPointOnCurve(const QPointF &p) const; + static bool SubdividePath(const QVector &points, QPointF p, QVector &sub1, + QVector &sub2); + virtual qreal GetStartAngle () const=0; virtual qreal GetEndAngle () const=0;