From e7bd65bde9ea861aaeb90a1392f4ebae5a2c9bd5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 26 Mar 2019 19:10:13 +0200 Subject: [PATCH] Refactoring. Move code in functions. --HG-- branch : develop --- src/libs/vlayout/vcontour.cpp | 84 ++++++++++++++++++---------------- src/libs/vlayout/vcontour.h | 2 + src/libs/vlayout/vposition.cpp | 4 +- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/libs/vlayout/vcontour.cpp b/src/libs/vlayout/vcontour.cpp index 72278f988..03a458b45 100644 --- a/src/libs/vlayout/vcontour.cpp +++ b/src/libs/vlayout/vcontour.cpp @@ -144,15 +144,7 @@ QVector VContour::UniteWithContour(const VLayoutPiece &detail, int glob return QVector(); } - int i2 = 0; - if (globalI == d->globalContour.count()) - { - i2 = 0; - } - else - { - i2 = globalI; - } + const int i2 = globalI == d->globalContour.count() ? 0 : globalI; int i=0; while (i < d->globalContour.count()) @@ -165,40 +157,11 @@ QVector VContour::UniteWithContour(const VLayoutPiece &detail, int glob } else { - int processedEdges = 0; - const int nD = detail.LayoutEdgesCount(); - int j = detJ+1; - do - { - if (j > nD) - { - j=1; - } - if (j != detJ) - { - const QVector points = CutEdge(detail.LayoutEdge(j)); - for (int i = 0; i < points.size()-1; ++i) - { - newContour.append(points.at(i)); - } - } - ++processedEdges; - ++j; - }while (processedEdges < nD); + InsertDetail(newContour, detail, detJ); } } - if (not newContour.isEmpty()) - { - if (newContour.last() != d->globalContour.at(i)) - { - newContour.append(d->globalContour.at(i)); - } - } - else - { - newContour.append(d->globalContour.at(i)); - } + AppendToContour(newContour, d->globalContour.at(i)); ++i; } } @@ -336,6 +299,22 @@ QPainterPath VContour::ContourPath() const return path; } +//--------------------------------------------------------------------------------------------------------------------- +void VContour::AppendToContour(QVector &contour, QPointF point) const +{ + if (not contour.isEmpty()) + { + if (not VFuzzyComparePoints(contour.last(), point)) + { + contour.append(point); + } + } + else + { + contour.append(point); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VContour::AppendWhole(QVector &contour, const VLayoutPiece &detail, int detJ) const { @@ -358,6 +337,31 @@ void VContour::AppendWhole(QVector &contour, const VLayoutPiece &detail }while (processedEdges < nD); } +//--------------------------------------------------------------------------------------------------------------------- +void VContour::InsertDetail(QVector &contour, const VLayoutPiece &detail, int detJ) const +{ + int processedEdges = 0; + const int nD = detail.LayoutEdgesCount(); + int j = detJ+1; + do + { + if (j > nD) + { + j=1; + } + if (j != detJ) + { + for(auto &point : CutEdge(detail.LayoutEdge(j))) + { + AppendToContour(contour, point); + } + } + ++processedEdges; + ++j; + } + while (processedEdges < nD); +} + //--------------------------------------------------------------------------------------------------------------------- bool VContour::IsPortrait() const { diff --git a/src/libs/vlayout/vcontour.h b/src/libs/vlayout/vcontour.h index 8b6c388f0..206a1ca99 100644 --- a/src/libs/vlayout/vcontour.h +++ b/src/libs/vlayout/vcontour.h @@ -94,7 +94,9 @@ public: private: QSharedDataPointer d; + void AppendToContour(QVector &contour, QPointF point) const; void AppendWhole(QVector &contour, const VLayoutPiece &detail, int detJ) const; + void InsertDetail(QVector &contour, const VLayoutPiece &detail, int detJ) const; }; Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE); diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 9ca07f055..ed8ac759a 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -311,8 +311,8 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detai newGContour.append(newGContour.first()); const QSizeF size = QPolygonF(newGContour).boundingRect().size(); - const bool isPortrait = m_data.gContour.GetSize().height() >= m_data.gContour.GetSize().width(); - const qreal position = isPortrait ? detail.DetailBoundingRect().y() : detail.DetailBoundingRect().x(); + const qreal position = m_data.gContour.IsPortrait() ? detail.DetailBoundingRect().y() : + detail.DetailBoundingRect().x(); bestResult.NewResult(size, globalI, detJ, detail.GetMatrix(), detail.IsMirror(), position, type); }