From 7b3c05dfa8a8e4b1df442c1542fc127a2114dab8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 1 Dec 2016 20:44:29 +0200 Subject: [PATCH] Refactoring VPiecePath::StartSegment and VPiecePath::EndSegment. --HG-- branch : feature --- src/libs/vpatterndb/vpiecepath.cpp | 57 +++++++++++++----------------- src/libs/vpatterndb/vpiecepath.h | 3 ++ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index b0b3ac8ee..716058e95 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -250,7 +250,7 @@ QPainterPath VPiecePath::PainterPath(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- VSAPoint VPiecePath::StartSegment(const VContainer *data, const QVector &nodes, int i, bool reverse) { - if (i < 0 && i > nodes.size()-1) + if (i < 0 || i > nodes.size()-1) { return VSAPoint(); } @@ -266,36 +266,10 @@ VSAPoint VPiecePath::StartSegment(const VContainer *data, const QVector 1) { - if (i == 0) - { - if (nodes.at(nodes.size()-1).GetTypeTool() == Tool::NodePoint) - { - const VPieceNode &node = nodes.at(nodes.size()-1); - const QPointF p = *data->GeometricObject(node.GetId()); - if (curve->IsPointOnCurve(p)) - { - begin = VSAPoint(p); - begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); - begin.SetAngleType(node.GetAngleType()); - } - } - } - else - { - if (nodes.at(i-1).GetTypeTool() == Tool::NodePoint) - { - const VPieceNode &node = nodes.at(i-1); - const QPointF p = *data->GeometricObject(node.GetId()); - if (curve->IsPointOnCurve(p)) - { - begin = VSAPoint(p); - begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); - begin.SetAngleType(node.GetAngleType()); - } - } - } + int index = 0; + i == 0 ? index = nodes.size()-1 : index = i-1; + + begin = CurvePoint(begin, data, nodes.at(index), curve); } return begin; } @@ -303,7 +277,7 @@ VSAPoint VPiecePath::StartSegment(const VContainer *data, const QVector &nodes, int i, bool reverse) { - if (i < 0 && i > nodes.size()-1) + if (i < 0 || i > nodes.size()-1) { return VSAPoint(); } @@ -513,3 +487,22 @@ QVector VPiecePath::CurveSeamAllowanceSegment(const VContainer *data, return pointsEkv; } + +//--------------------------------------------------------------------------------------------------------------------- +VSAPoint VPiecePath::CurvePoint(const VSAPoint &candidate, const VContainer *data, const VPieceNode &node, + const QSharedPointer &curve) +{ + VSAPoint point = candidate; + if (node.GetTypeTool() == Tool::NodePoint) + { + const QPointF p = *data->GeometricObject(node.GetId()); + if (curve->IsPointOnCurve(p)) + { + point = VSAPoint(p); + point.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + point.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + point.SetAngleType(node.GetAngleType()); + } + } + return point; +} diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 317ae75f8..dfbe580a5 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -92,6 +92,9 @@ public: private: QSharedDataPointer d; + + static VSAPoint CurvePoint(const VSAPoint &candidate, const VContainer *data, const VPieceNode &node, + const QSharedPointer &curve); }; Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE);