From 49506c0bf262ba33eb12c3cc56599786decaf320 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 13 Sep 2018 17:31:14 +0300 Subject: [PATCH] Refactring. MaxLocalSA can be part of VSAPoint class. --HG-- branch : release --- src/libs/vlayout/vabstractpiece.cpp | 50 ++++++++++++++--------------- src/libs/vlayout/vabstractpiece.h | 3 +- src/libs/vpatterndb/vpiece.cpp | 6 ++-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index b920719a5..f4c6b1b5a 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -212,7 +212,7 @@ QVector AngleByLength(QVector points, QPointF p2, const QLineF { const QPointF sp1 = bigLine1.p1(); const QPointF sp3 = bigLine2.p2(); - const qreal localWidth = VAbstractPiece::MaxLocalSA(p, width); + const qreal localWidth = p.MaxLocalSA(width); if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), sp2) && IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), sp2) ) { @@ -282,7 +282,7 @@ QVector AngleByIntersection(const QVector &points, QPointF p1, const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2, const VSAPoint &p, qreal width) { - const qreal localWidth = VAbstractPiece::MaxLocalSA(p, width); + const qreal localWidth = p.MaxLocalSA(width); QVector pointsIntr = points; // First point @@ -345,7 +345,7 @@ QVector AngleByFirstSymmetry(const QVector &points, QPointF p1 const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2, const VSAPoint &p, qreal width) { - const qreal localWidth = VAbstractPiece::MaxLocalSA(p, width); + const qreal localWidth = p.MaxLocalSA(width); QVector pointsIntr = points; QLineF sEdge(VPointF::FlipPF(bigLine2, p1), VPointF::FlipPF(bigLine2, p2)); @@ -407,7 +407,7 @@ QVector AngleBySecondSymmetry(const QVector &points, QPointF p const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2, const VSAPoint &p, qreal width) { - const qreal localWidth = VAbstractPiece::MaxLocalSA(p, width); + const qreal localWidth = p.MaxLocalSA(width); QVector pointsIntr = points; QLineF sEdge(VPointF::FlipPF(bigLine1, p2), VPointF::FlipPF(bigLine1, p3)); @@ -471,7 +471,7 @@ QVector AngleByFirstRightAngle(const QVector &points, QPointF const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2, const VSAPoint &p, qreal width) { - const qreal localWidth = VAbstractPiece::MaxLocalSA(p, width); + const qreal localWidth = p.MaxLocalSA(width); QVector pointsRA = points; QLineF edge(p1, p2); @@ -517,7 +517,7 @@ QVector AngleBySecondRightAngle(QVector points, QPointF p2, QP const QLineF &bigLine1, QPointF sp2, const QLineF &bigLine2, const VSAPoint &p, qreal width) { - const qreal localWidth = VAbstractPiece::MaxLocalSA(p, width); + const qreal localWidth = p.MaxLocalSA(width); QLineF edge(p2, p3); QPointF px; @@ -974,24 +974,6 @@ QVector VAbstractPiece::CheckLoops(const QVector &points) return ekvPoints; } -//--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractPiece::MaxLocalSA(const VSAPoint &p, qreal width) -{ - qreal w1 = p.GetSAAfter(); - if (w1 < 0) - { - w1 = width; - } - - qreal w2 = p.GetSABefore(); - if (w2 < 0) - { - w2 = width; - } - - return qMax(w1, w2); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief EkvPoint return seam aloowance points in place of intersection two edges. Last points of two edges should be @@ -1034,7 +1016,7 @@ QVector VAbstractPiece::EkvPoint(QVector points, const VSAPoin return points; } - const qreal localWidth = MaxLocalSA(p2Line1, width); + const qreal localWidth = p2Line1.MaxLocalSA(width); QLineF line( p2Line1, crosPoint ); // Checking two subcases @@ -1234,3 +1216,21 @@ qreal VSAPoint::GetSAAfter(qreal width) const } return m_after; } + +//--------------------------------------------------------------------------------------------------------------------- +qreal VSAPoint::MaxLocalSA(qreal width) const +{ + qreal w1 = GetSAAfter(); + if (w1 < 0) + { + w1 = width; + } + + qreal w2 = GetSABefore(); + if (w2 < 0) + { + w2 = width; + } + + return qMax(w1, w2); +} diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 2cb1e8f2d..45578fd42 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -68,6 +68,8 @@ public: Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const; void SetAngleType(PieceNodeAngle value); + qreal MaxLocalSA(qreal width) const; + private: qreal m_before; qreal m_after; @@ -187,7 +189,6 @@ public: static QVector EkvPoint(QVector points, const VSAPoint &p1Line1, const VSAPoint &p2Line1, const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width); static QLineF ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width); - static qreal MaxLocalSA(const VSAPoint &p, qreal width); template static QVector CorrectEquidistantPoints(const QVector &points, bool removeFirstAndLast = true); diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 7faa32b21..8c9484d2b 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -1112,7 +1112,7 @@ bool VPiece::GetSeamPassmarkSAPoint(const VSAPoint &previousSAPoint, const VSAPo { QLineF line (passmarkSAPoint, nextSAPoint); line.setAngle(line.angle() + 90); - line.setLength(VAbstractPiece::MaxLocalSA(passmarkSAPoint, width)); + line.setLength(passmarkSAPoint.MaxLocalSA(width)); ekvPoints.append(line.p2()); } else @@ -1249,7 +1249,7 @@ QVector VPiece::SAPassmark(const QVector &path, VSAPoint &pr QVector passmarksLines; - qreal passmarkLength = VAbstractPiece::MaxLocalSA(passmarkSAPoint, width) * passmarkFactor; + qreal passmarkLength = passmarkSAPoint.MaxLocalSA(width) * passmarkFactor; passmarkLength = qMin(passmarkLength, maxPassmarkLength); const VPieceNode &node = path.at(passmarkIndex); @@ -1347,7 +1347,7 @@ QVector VPiece::BuiltInSAPassmark(const QVector &path, const QVector passmarksLines; const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); - qreal passmarkLength = VAbstractPiece::MaxLocalSA(passmarkSAPoint, width) * passmarkFactor; + qreal passmarkLength = passmarkSAPoint.MaxLocalSA(width) * passmarkFactor; passmarkLength = qMin(passmarkLength, maxPassmarkLength); QLineF edge1 = QLineF(passmarkSAPoint, previousSAPoint);