From e9c9d263f66479b7825c879fab66934b758a364f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 25 Mar 2017 10:18:03 +0200 Subject: [PATCH] Skip excluded nodes when prepare segment of curve. --HG-- branch : feature --- src/libs/vpatterndb/vpiecepath.cpp | 70 ++++++++++++++++++++++++++++-- src/libs/vpatterndb/vpiecepath.h | 3 ++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 998061e1b..3e23330e4 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -387,9 +387,12 @@ VSAPoint VPiecePath::StartSegment(const VContainer *data, const QVector 1) { int index = 0; - i == 0 ? index = nodes.size()-1 : index = i-1; + i == 0 ? index = FindInLoopNotExcludedUp(nodes.size()-1, nodes) : index = FindInLoopNotExcludedUp(i-1, nodes); - begin = CurveStartPoint(begin, data, nodes.at(index), points); + if (index != -1 && index != i) + { + begin = CurveStartPoint(begin, data, nodes.at(index), points); + } } return begin; } @@ -416,9 +419,12 @@ VSAPoint VPiecePath::EndSegment(const VContainer *data, const QVector 2) { int index = 0; - i == nodes.size() - 1 ? index = 0 : index = i+1; + i == nodes.size()-1 ? index=FindInLoopNotExcludedDown(0, nodes) : index=FindInLoopNotExcludedDown(i+1, nodes); - end = CurveEndPoint(end, data, nodes.at(index), points); + if (index != -1 && index != i) + { + end = CurveEndPoint(end, data, nodes.at(index), points); + } } return end; } @@ -762,6 +768,62 @@ QPointF VPiecePath::NodeNextPoint(const VContainer *data, int i) const return point; } +//--------------------------------------------------------------------------------------------------------------------- +int VPiecePath::FindInLoopNotExcludedUp(int candidate, const QVector &nodes) +{ + if (candidate < 0 || candidate >= nodes.size()) + { + return -1; + } + + int checked = 0; + int i = candidate; + do + { + if (not nodes.at(i).IsExcluded()) + { + break; + } + + ++checked; + --i; + if (i < 0) + { + i = nodes.size() - 1; + } + } while (checked < nodes.size()); + + return i; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPiecePath::FindInLoopNotExcludedDown(int candidate, const QVector &nodes) +{ + if (candidate < 0 || candidate >= nodes.size()) + { + return -1; + } + + int checked = 0; + int i = candidate; + do + { + if (not nodes.at(i).IsExcluded()) + { + break; + } + + ++checked; + ++i; + if (i >= nodes.size()) + { + i = 0; + } + } while (checked < nodes.size()); + + return i; +} + //--------------------------------------------------------------------------------------------------------------------- VSAPoint VPiecePath::PreparePointEkv(const VPieceNode &node, const VContainer *data) { diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 492053c0c..8bda5957b 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -94,6 +94,9 @@ public: QPointF NodePreviousPoint(const VContainer *data, int i) const; QPointF NodeNextPoint(const VContainer *data, int i) const; + static int FindInLoopNotExcludedUp(int candidate, const QVector &nodes); + static int FindInLoopNotExcludedDown(int candidate, const QVector &nodes); + static VSAPoint StartSegment(const VContainer *data, const QVector &nodes, int i, bool reverse); static VSAPoint EndSegment(const VContainer *data, const QVector &nodes, int i, bool reverse);