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