From 9c7ab2fb4ae73373d73a733e053e88f7c806a332 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 28 Oct 2022 13:55:24 +0300 Subject: [PATCH] Refactor CastTo. --- src/app/puzzle/layout/vppiece.cpp | 6 +- src/app/puzzle/layout/vpsheet.cpp | 6 +- src/app/puzzle/scene/vpgraphicspiece.cpp | 2 +- src/app/puzzle/scene/vpmaingraphicsview.cpp | 2 +- src/libs/ifc/xml/vlayoutconverter.cpp | 3 +- src/libs/vlayout/vabstractpiece.cpp | 83 +++---------------- src/libs/vlayout/vabstractpiece.h | 68 +++++++++++++++ src/libs/vlayout/vlayoutpiece.cpp | 30 +++++-- src/libs/vlayout/vlayoutpiece_p.h | 4 +- src/libs/vlayout/vlayoutpiecepath.cpp | 4 +- src/libs/vlayout/vlayoutpiecepath_p.h | 2 +- src/libs/vlayout/vlayoutpoint.h | 33 ++++---- src/libs/vlayout/vposition.cpp | 6 +- src/libs/vpatterndb/vpassmark.cpp | 30 ++++--- src/libs/vpatterndb/vpiece.cpp | 20 +++-- src/libs/vpatterndb/vpiecepath.cpp | 9 +- .../tools/piece/dialogseamallowance.cpp | 3 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 7 +- .../visualization/path/vistoolpiece.cpp | 2 +- src/test/ValentinaTest/tst_vabstractpiece.cpp | 15 ++-- src/test/ValentinaTest/tst_vlayoutdetail.cpp | 24 ++++-- src/test/ValentinaTest/tst_vpiece.cpp | 3 +- 22 files changed, 216 insertions(+), 146 deletions(-) diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index 9eee5abe9..e3f166948 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -409,7 +409,8 @@ auto VPPiece::StickyPosition(qreal &dx, qreal &dy) const -> bool return false; } - QVector path = CastTo(GetMappedExternalContourPoints()); + QVector path; + CastTo(GetMappedExternalContourPoints(), path); QRectF boundingRect = VLayoutPiece::BoundingRect(path); const qreal stickyDistance = pieceGap+minStickyDistance; QRectF stickyZone = QRectF(boundingRect.topLeft().x()-stickyDistance, boundingRect.topLeft().y()-stickyDistance, @@ -425,7 +426,8 @@ auto VPPiece::StickyPosition(qreal &dx, qreal &dy) const -> bool continue; } - QVector piecePath = CastTo(piece->GetMappedExternalContourPoints()); + QVector piecePath; + CastTo(piece->GetMappedExternalContourPoints(), piecePath); QRectF pieceBoundingRect = VLayoutPiece::BoundingRect(piecePath); if (stickyZone.intersects(pieceBoundingRect) || pieceBoundingRect.contains(stickyZone) || diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index 7a45acf75..3504a3f80 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -507,7 +507,8 @@ void VPSheet::ValidateSuperpositionOfPieces() const } const bool oldSuperpositionOfPieces = piece->HasSuperpositionWithPieces(); - QVector path1 = CastTo(piece->GetMappedExternalContourPoints()); + QVector path1; + CastTo(piece->GetMappedExternalContourPoints(), path1); bool hasSuperposition = false; for (const auto &p : pieces) @@ -517,7 +518,8 @@ void VPSheet::ValidateSuperpositionOfPieces() const continue; } - QVector path2 = CastTo(p->GetMappedExternalContourPoints()); + QVector path2; + CastTo(p->GetMappedExternalContourPoints(), path2); bool superposition = VPPiece::PathsSuperposition(path1, path2); if (superposition) diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index c937c5d32..a78ded1c4 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -709,7 +709,7 @@ void VPGraphicsPiece::GroupMove(const QPointF &pos) QVector path; if (not p.isNull() && p->StickyPosition(m_stickyTranslateX, m_stickyTranslateY)) { - path = CastTo(p->GetMappedExternalContourPoints()); + CastTo(p->GetMappedExternalContourPoints(), path); QTransform m; m.translate(m_stickyTranslateX, m_stickyTranslateY); path = m.map(path); diff --git a/src/app/puzzle/scene/vpmaingraphicsview.cpp b/src/app/puzzle/scene/vpmaingraphicsview.cpp index ebe358635..18d8076f7 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.cpp +++ b/src/app/puzzle/scene/vpmaingraphicsview.cpp @@ -521,7 +521,7 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy) QVector path; if (not p.isNull() && p->StickyPosition(m_stickyTranslateX, m_stickyTranslateY)) { - path = CastTo(p->GetMappedExternalContourPoints()); + CastTo(p->GetMappedExternalContourPoints(), path); QTransform m; m.translate(m_stickyTranslateX, m_stickyTranslateY); path = m.map(path); diff --git a/src/libs/ifc/xml/vlayoutconverter.cpp b/src/libs/ifc/xml/vlayoutconverter.cpp index 44482c785..ae29df999 100644 --- a/src/libs/ifc/xml/vlayoutconverter.cpp +++ b/src/libs/ifc/xml/vlayoutconverter.cpp @@ -225,7 +225,8 @@ void VLayoutConverter::ConvertPathToV0_1_3(QDomElement &node) } RemoveAllChildren(node); - QVector path = CastTo(StringV0_1_2ToPath(oldPath)); + QVector path; + CastTo(StringV0_1_2ToPath(oldPath), path); for (auto &point : path) { diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index b53232a47..c66118abe 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -1122,15 +1122,20 @@ auto VAbstractPiece::Equidistant(QVector points, qreal width, const QS QT_WARNING_POP } + QVector cleaned; // Uncomment for debug -// QVector cleaned = CastTo(ekvPoints); +// CastTo(ekvPoints, cleaned); const bool removeFirstAndLast = false; ekvPoints = RemoveDublicates(ekvPoints, removeFirstAndLast); - QVector cleaned = CastTo(CheckLoops(ekvPoints));//Result path can contain loops + ekvPoints = CheckLoops(ekvPoints); + CastTo(ekvPoints, cleaned);//Result path can contain loops cleaned = CorrectEquidistantPoints(cleaned, removeFirstAndLast); cleaned = CorrectPathDistortion(cleaned); -// DumpVector(CastTo(cleaned), QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data + +// QVector dump; +// CastTo(cleaned, dump); +// DumpVector(dump, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data return cleaned; } @@ -2041,76 +2046,10 @@ auto VAbstractPiece::LabelShapePath(const PlaceLabelImg &shape) -> QPainterPath if (not p.isEmpty()) { path.moveTo(ConstFirst(p)); - path.addPolygon(CastTo(p)); + QVector polygon; + CastTo(p, polygon); + path.addPolygon(polygon); } } return path; } - -//--------------------------------------------------------------------------------------------------------------------- -template -auto VAbstractPiece::ComparePoints(QVector &points, const T &p1, const T &p2, qreal accuracy) -> bool -{ - if (not VFuzzyComparePoints(p1, p2, accuracy)) - { - points.append(p2); - return false; - } - - if (not points.isEmpty() && p2.TurnPoint()) - { - points.last().SetTurnPoint(true); - } - - if (not points.isEmpty() && p2.CurvePoint()) - { - points.last().SetCurvePoint(true); - } - - return true; -} - -//--------------------------------------------------------------------------------------------------------------------- -template <> -auto VAbstractPiece::ComparePoints(QVector &points, const QPointF &p1, const QPointF &p2, - qreal accuracy) -> bool -{ - if (not VFuzzyComparePoints(p1, p2, accuracy)) - { - points.append(p2); - return false; - } - - return true; -} - -//--------------------------------------------------------------------------------------------------------------------- -template -auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void -{ - if (VFuzzyComparePoints(ConstFirst(points), ConstLast(points), accuracy)) - { - const T& l = ConstLast(points); - points.removeLast(); - - if (not points.isEmpty() && l.TurnPoint()) - { - points.last().SetTurnPoint(true); - } - - if (not points.isEmpty() && l.CurvePoint()) - { - points.last().SetCurvePoint(true); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -template <> -auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void -{ - if (VFuzzyComparePoints(ConstFirst(points), ConstLast(points), accuracy)) - { - points.removeLast(); - } -} diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index d2e02846a..5467e7806 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -328,6 +328,74 @@ inline auto VAbstractPiece::RemoveDublicates(const QVector &points, bool remo return p; } +//--------------------------------------------------------------------------------------------------------------------- +template +inline auto VAbstractPiece::ComparePoints(QVector &points, const T &p1, const T &p2, qreal accuracy) -> bool +{ + if (not VFuzzyComparePoints(p1, p2, accuracy)) + { + points.append(p2); + return false; + } + + if (not points.isEmpty() && p2.TurnPoint()) + { + points.last().SetTurnPoint(true); + } + + if (not points.isEmpty() && p2.CurvePoint()) + { + points.last().SetCurvePoint(true); + } + + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +template <> +inline auto VAbstractPiece::ComparePoints(QVector &points, const QPointF &p1, const QPointF &p2, + qreal accuracy) -> bool +{ + if (not VFuzzyComparePoints(p1, p2, accuracy)) + { + points.append(p2); + return false; + } + + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void +{ + const T& l = ConstLast(points); + if (VFuzzyComparePoints(ConstFirst(points), l, accuracy)) + { + points.removeLast(); + + if (not points.isEmpty() && l.TurnPoint()) + { + points.last().SetTurnPoint(true); + } + + if (not points.isEmpty() && l.CurvePoint()) + { + points.last().SetCurvePoint(true); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template <> +inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void +{ + if (VFuzzyComparePoints(ConstFirst(points), ConstLast(points), accuracy)) + { + points.removeLast(); + } +} + //--------------------------------------------------------------------------------------------------------------------- template inline auto VAbstractPiece::IsInsidePolygon(const QVector &path, const QVector &polygon, qreal accuracy) -> bool diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 946af549d..ca52896df 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1198,13 +1198,17 @@ auto VLayoutPiece::LayoutEdgeByPoint(const QPointF &p1) const -> int //--------------------------------------------------------------------------------------------------------------------- auto VLayoutPiece::MappedDetailBoundingRect() const -> QRectF { - return BoundingRect(CastTo(GetMappedExternalContourPoints())); + QVector points; + CastTo(GetMappedExternalContourPoints(), points); + return BoundingRect(points); } //--------------------------------------------------------------------------------------------------------------------- auto VLayoutPiece::DetailBoundingRect() const -> QRectF { - return BoundingRect(CastTo(GetExternalContourPoints())); + QVector points; + CastTo(GetExternalContourPoints(), points); + return BoundingRect(points); } //--------------------------------------------------------------------------------------------------------------------- @@ -1245,24 +1249,30 @@ void VLayoutPiece::SetLayoutAllowancePoints() { if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) { - d->m_layoutAllowance = CastTo(Equidistant(CastTo(GetMappedSeamAllowancePoints()), - d->m_layoutWidth, GetName())); + QVector seamAllowancePoints; + CastTo(GetMappedSeamAllowancePoints(), seamAllowancePoints); + CastTo(Equidistant(seamAllowancePoints, d->m_layoutWidth, GetName()), d->m_layoutAllowance); if (not d->m_layoutAllowance.isEmpty()) { d->m_layoutAllowance.removeLast(); - d->m_square = qFloor(qAbs(SumTrapezoids(CastTo(GetSeamAllowancePoints()))/2.0)); + QVector points; + CastTo(GetSeamAllowancePoints(), points); + d->m_square = qFloor(qAbs(SumTrapezoids(points)/2.0)); } } else { - d->m_layoutAllowance = CastTo(Equidistant(CastTo(GetMappedContourPoints()), - d->m_layoutWidth, GetName())); + QVector seamLinePoints; + CastTo(GetMappedContourPoints(), seamLinePoints); + CastTo(Equidistant(seamLinePoints, d->m_layoutWidth, GetName()), d->m_layoutAllowance); if (not d->m_layoutAllowance.isEmpty()) { d->m_layoutAllowance.removeLast(); - d->m_square = qFloor(qAbs(SumTrapezoids(CastTo(GetContourPoints()))/2.0)); + QVector points; + CastTo(GetContourPoints(), points); + d->m_square = qFloor(qAbs(SumTrapezoids(points)/2.0)); } } } @@ -1486,7 +1496,9 @@ auto VLayoutPiece::IsLayoutAllowanceValid() const -> bool { QVector base = (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) ? d->m_seamAllowance : d->m_contour; - return VAbstractPiece::IsAllowanceValid(CastTo(base), d->m_layoutAllowance); + QVector points; + CastTo(base, points); + return VAbstractPiece::IsAllowanceValid(points, d->m_layoutAllowance); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vlayoutpiece_p.h b/src/libs/vlayout/vlayoutpiece_p.h index 67d6bd92d..f42e10a19 100644 --- a/src/libs/vlayout/vlayoutpiece_p.h +++ b/src/libs/vlayout/vlayoutpiece_p.h @@ -197,7 +197,9 @@ inline auto operator>>(QDataStream &dataStream, VLayoutPieceData &piece) -> QDat { QVector points; dataStream >> points; - return CastTo(points); + QVector casted; + CastTo(points, casted); + return casted; }; piece.m_contour = ReadPoints(); diff --git a/src/libs/vlayout/vlayoutpiecepath.cpp b/src/libs/vlayout/vlayoutpiecepath.cpp index 197fc437c..5a90d3465 100644 --- a/src/libs/vlayout/vlayoutpiecepath.cpp +++ b/src/libs/vlayout/vlayoutpiecepath.cpp @@ -100,7 +100,9 @@ QPainterPath VLayoutPiecePath::GetPainterPath() const QPainterPath path; if (not d->m_points.isEmpty()) { - path.addPolygon(QPolygonF(CastTo(d->m_points))); + QVector points; + CastTo(d->m_points, points); + path.addPolygon(QPolygonF(points)); path.setFillRule(Qt::WindingFill); } return path; diff --git a/src/libs/vlayout/vlayoutpiecepath_p.h b/src/libs/vlayout/vlayoutpiecepath_p.h index 5fc436000..0bfdbcdfc 100644 --- a/src/libs/vlayout/vlayoutpiecepath_p.h +++ b/src/libs/vlayout/vlayoutpiecepath_p.h @@ -126,7 +126,7 @@ QDataStream& operator>>(QDataStream &dataStream, VLayoutPiecePathData &path) { QVector points; dataStream >> points; - path.m_points = CastTo(points); + CastTo(points, path.m_points); } else { diff --git a/src/libs/vlayout/vlayoutpoint.h b/src/libs/vlayout/vlayoutpoint.h index 083a968cf..3b7b91682 100644 --- a/src/libs/vlayout/vlayoutpoint.h +++ b/src/libs/vlayout/vlayoutpoint.h @@ -67,31 +67,36 @@ Q_DECLARE_TYPEINFO(VLayoutPoint, Q_MOVABLE_TYPE); // NOLINT //--------------------------------------------------------------------------------------------------------------------- template -inline auto CastTo(const QVector &points) -> QVector +inline auto CastTo(const QVector &points, QVector &casted) -> void { - return points; + Q_UNUSED(points) + Q_UNUSED(casted) } //--------------------------------------------------------------------------------------------------------------------- -// upcast +//upcast template ::value>::type* = nullptr> -inline auto CastTo(const QVector &points) -> QVector +inline auto CastTo(const QVector &points, QVector &casted) -> void { - QVector castedPoints; - castedPoints.reserve(points.size()); - std::transform(points.begin(), points.end(), castedPoints.begin(), [](const Base &p) { return Derived(p); }); - return castedPoints; + casted.clear(); + casted.reserve(points.size()); + for (const auto &p : points) + { + casted.append(Derived(p)); + } } //--------------------------------------------------------------------------------------------------------------------- -// downcast +//downcast template ::value>::type* = nullptr> -inline auto CastTo(const QVector &points) -> QVector +inline auto CastTo(const QVector &points, QVector &casted) -> void { - QVector castedPoints; - castedPoints.reserve(points.size()); - std::transform(points.begin(), points.end(), castedPoints.begin(), [](const Base &p) { return p; }); - return castedPoints; + casted.clear(); + casted.reserve(points.size()); + for (const auto &p : points) + { + casted.append(p); + } } /***************************************************************************** diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index de7f02d2a..bb626f78c 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -462,9 +462,9 @@ auto VPosition::Crossing(const VLayoutPiece &detail) const -> VPosition::Crossin const QRectF layoutBoundingRect = VLayoutPiece::BoundingRect(layoutPoints); const QPainterPath layoutAllowancePath = VAbstractPiece::PainterPath(layoutPoints); - const QVector contourPoints = - CastTo(detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() ? - detail.GetMappedSeamAllowancePoints() : detail.GetMappedContourPoints()); + QVector contourPoints; + CastTo(detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() ? + detail.GetMappedSeamAllowancePoints() : detail.GetMappedContourPoints(), contourPoints); const QRectF detailBoundingRect = VLayoutPiece::BoundingRect(contourPoints); const QPainterPath contourPath = VAbstractPiece::PainterPath(contourPoints); diff --git a/src/libs/vpatterndb/vpassmark.cpp b/src/libs/vpatterndb/vpassmark.cpp index c18491adf..017a8570b 100644 --- a/src/libs/vpatterndb/vpassmark.cpp +++ b/src/libs/vpatterndb/vpassmark.cpp @@ -688,7 +688,7 @@ QVector VPassmark::FullPassmark(const VPiece &piece, const VContainer *d { if (m_null) { - return QVector(); + return {}; } if (not piece.IsSeamAllowanceBuiltIn()) @@ -719,16 +719,18 @@ QVector VPassmark::SAPassmark(const VPiece &piece, const VContainer *dat { if (m_null) { - return QVector(); + return {}; } if (not piece.IsSeamAllowanceBuiltIn()) { // Because rollback cannot be calulated if passmark is not first point in main path we rotate it. - return SAPassmark(CastTo(piece.SeamAllowancePointsWithRotation(data, m_data.passmarkIndex)), side); + QVector points; + CastTo(piece.SeamAllowancePointsWithRotation(data, m_data.passmarkIndex), points); + return SAPassmark(points, side); } - return QVector(); + return {}; } //--------------------------------------------------------------------------------------------------------------------- @@ -736,7 +738,7 @@ QVector VPassmark::SAPassmark(const QVector &seamAllowance, Pas { if (m_null) { - return QVector(); + return {}; } // Because rollback @seamAllowance must be rotated here. @@ -800,8 +802,9 @@ QVector VPassmark::BuiltInSAPassmark(const VPiece &piece, const VContain return QVector(); } - return CreatePassmarkLines(m_data.passmarkLineType, m_data.passmarkAngleType, lines, - CastTo(piece.MainPathPoints(data)), PassmarkSide::All); + QVector points; + CastTo(piece.MainPathPoints(data), points); + return CreatePassmarkLines(m_data.passmarkLineType, m_data.passmarkAngleType, lines, points, PassmarkSide::All); } //--------------------------------------------------------------------------------------------------------------------- @@ -853,7 +856,7 @@ QVector VPassmark::BuiltInSAPassmarkBaseLine(const VPiece &piece) const edge1.setAngle(edge1.angle() + edge1.angleTo(edge2)/2.); edge1.setLength(length); - return QVector({edge1}); + return {edge1}; } //--------------------------------------------------------------------------------------------------------------------- @@ -861,17 +864,18 @@ QVector VPassmark::SAPassmarkBaseLine(const VPiece &piece, const VContai { if (m_null) { - return QVector(); + return {}; } if (not piece.IsSeamAllowanceBuiltIn()) { // Because rollback cannot be calulated if passmark is not first point in main path we rotate it. - return SAPassmarkBaseLine(CastTo(piece.SeamAllowancePointsWithRotation(data, m_data.passmarkIndex)), - side); + QVector points; + CastTo(piece.SeamAllowancePointsWithRotation(data, m_data.passmarkIndex), points); + return SAPassmarkBaseLine(points, side); } - return QVector(); + return {}; } //--------------------------------------------------------------------------------------------------------------------- @@ -879,7 +883,7 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa { if (m_null) { - return QVector(); + return {}; } if (seamAllowance.size() < 2) diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 753d6cacf..69e270b17 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -208,12 +208,15 @@ QVector VPiece::SeamAllowancePoints(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::CuttingPathPoints(const VContainer *data) const { + QVector points; if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) { - return CastTo(SeamAllowancePoints(data)); + CastTo(SeamAllowancePoints(data), points); + return points; } - return CastTo(MainPathPoints(data)); + CastTo(MainPathPoints(data), points); + return points; } //--------------------------------------------------------------------------------------------------------------------- @@ -269,7 +272,9 @@ QVector VPiece::CurvesPainterPath(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiece::MainPathPath(const VContainer *data) const { - return VPiece::MainPathPath(CastTo(MainPathPoints(data))); + QVector points; + CastTo(MainPathPoints(data), points); + return VPiece::MainPathPath(points); } //--------------------------------------------------------------------------------------------------------------------- @@ -349,8 +354,13 @@ bool VPiece::IsSeamAllowanceValid(const VContainer *data) const { if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) { - return VAbstractPiece::IsAllowanceValid(CastTo(UniteMainPathPoints(data)), - CastTo(SeamAllowancePoints(data))); + QVector mainPathPoints; + CastTo(UniteMainPathPoints(data), mainPathPoints); + + QVector seamAllowancePoints; + CastTo(SeamAllowancePoints(data), seamAllowancePoints); + + return VAbstractPiece::IsAllowanceValid(mainPathPoints, seamAllowancePoints); } return true; diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 12fd52467..8860d9c1d 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -570,7 +570,10 @@ QVector VPiecePath::SeamAllowancePoints(const VContainer *data, qreal //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiecePath::PainterPath(const VContainer *data, const QVector &cuttingPath) const { - return MakePainterPath(CastTo(PathPoints(data, cuttingPath))); + QVector points = PathPoints(data, cuttingPath); + QVector casted; + CastTo(points, casted); + return MakePainterPath(casted); } //--------------------------------------------------------------------------------------------------------------------- @@ -580,7 +583,7 @@ QVector VPiecePath::CurvesPainterPath(const VContainer *data) cons QVector paths; paths.reserve(curves.size()); - for(auto &curve : curves) + for(const auto &curve : curves) { paths.append(MakePainterPath(curve)); } @@ -1258,7 +1261,7 @@ QString VPiecePath::NodeName(const QVector &nodes, int nodeIndex, co { // ignore } - return QString(); + return {}; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index b4e705ab2..9104cb8a4 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -2763,7 +2763,8 @@ void DialogSeamAllowance::ValidObjects(bool value) //--------------------------------------------------------------------------------------------------------------------- bool DialogSeamAllowance::MainPathIsClockwise() const { - const QVector points = CastTo(CreatePiece().MainPathPoints(data)); + QVector points; + CastTo(CreatePiece().MainPathPoints(data), points); if(points.count() < 3) { diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 4f5b3d02d..ad41a1f03 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -2093,9 +2093,10 @@ auto VToolSeamAllowance::IsGrainlinePositionValid() const -> bool { QLineF grainLine = m_grainLine->Grainline(); const VPiece detail = VAbstractTool::data.GetPiece(m_id); - const QVector contourPoints = - detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() ? - CastTo(detail.SeamAllowancePoints(getData())) : CastTo(detail.MainPathPoints(getData())); + QVector contourPoints; + detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() + ? CastTo(detail.SeamAllowancePoints(getData()), contourPoints) + : CastTo(detail.MainPathPoints(getData()), contourPoints); QVector points = VAbstractCurve::CurveIntersectLine(contourPoints, grainLine); if (not points.isEmpty()) diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp index d919d0103..f40bb5204 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -52,7 +52,7 @@ void VisToolPiece::RefreshGeometry() if (GetMode() == Mode::Creation) { m_cachedCurvesPath = m_piece.CurvesPainterPath(GetData()); - m_cachedMainPathPoints = CastTo(m_piece.MainPathPoints(GetData())); + CastTo(m_piece.MainPathPoints(GetData()), m_cachedMainPathPoints); m_cachedMainPath = VPiece::MainPathPath(m_cachedMainPathPoints); } else diff --git a/src/test/ValentinaTest/tst_vabstractpiece.cpp b/src/test/ValentinaTest/tst_vabstractpiece.cpp index 296113497..9ef493550 100644 --- a/src/test/ValentinaTest/tst_vabstractpiece.cpp +++ b/src/test/ValentinaTest/tst_vabstractpiece.cpp @@ -308,7 +308,8 @@ void TST_VAbstractPiece::EquidistantRemoveLoop() const QFETCH(qreal, width); QFETCH(QVector, ekvOrig); - const QVector ekv = CastTo(VAbstractPiece::Equidistant(points, width, QString())); + QVector ekv; + CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv); // Begin comparison ComparePathsDistance(ekv, ekvOrig); @@ -360,7 +361,8 @@ void TST_VAbstractPiece::LayoutAllowanceRemoveLoop() const QFETCH(qreal, width); QFETCH(QVector, ekvOrig); - const QVector ekv = CastTo(VAbstractPiece::Equidistant(points, width, QString())); + QVector ekv; + CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv); // Begin comparison ComparePathsDistance(ekv, ekvOrig); @@ -402,7 +404,8 @@ void TST_VAbstractPiece::RawPathRemoveLoop() const QFETCH(QVector, path); QFETCH(QVector, expect); - QVector res = CastTo(VAbstractPiece::CheckLoops(path)); + QVector res; + CastTo(VAbstractPiece::CheckLoops(path), res); ComparePathsDistance(res, expect); } @@ -962,7 +965,8 @@ void TST_VAbstractPiece::BrokenDetailEquidistant() const QFETCH(qreal, width); QFETCH(QVector, ekvOrig); - const QVector ekv = CastTo(VAbstractPiece::Equidistant(points, width, QString()));// Take result + QVector ekv; + CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv);// Take result // Begin comparison ComparePathsDistance(ekv, ekvOrig); @@ -1074,7 +1078,8 @@ void TST_VAbstractPiece::EquidistantAngleType() const QFETCH(qreal, width); QFETCH(QVector, ekvOrig); - const QVector ekv = CastTo(VAbstractPiece::Equidistant(points, width, QString()));// Take result + QVector ekv; + CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv);// Take result // Begin comparison ComparePathsDistance(ekv, ekvOrig); diff --git a/src/test/ValentinaTest/tst_vlayoutdetail.cpp b/src/test/ValentinaTest/tst_vlayoutdetail.cpp index e03c60ee7..5353ec947 100644 --- a/src/test/ValentinaTest/tst_vlayoutdetail.cpp +++ b/src/test/ValentinaTest/tst_vlayoutdetail.cpp @@ -57,10 +57,14 @@ void TST_VLayoutDetail::Case1() const // https://bitbucket.org/dismine/valentina/issue/304/layout-appears-different-than-my-pattern VLayoutPiece det = VLayoutPiece(); - det.SetCountourPoints(CastTo(InputPointsCase1())); + QVector inputPoints; + CastTo(InputPointsCase1(), inputPoints); + det.SetCountourPoints(inputPoints); // Begin comparison - ComparePathsDistance(CastTo(det.GetMappedContourPoints()), OutputPointsCase1()); + QVector contourPoints; + CastTo(det.GetMappedContourPoints(), contourPoints); + ComparePathsDistance(contourPoints, OutputPointsCase1()); } //--------------------------------------------------------------------------------------------------------------------- @@ -119,10 +123,14 @@ QVector TST_VLayoutDetail::OutputPointsCase1() const //-V524 void TST_VLayoutDetail::Case2() const { VLayoutPiece det = VLayoutPiece(); - det.SetCountourPoints(CastTo(InputPointsCase2())); + QVector inputPoints; + CastTo(InputPointsCase2(), inputPoints); + det.SetCountourPoints(inputPoints); // Begin comparison - ComparePathsDistance(CastTo(det.GetMappedContourPoints()), OutputPointsCase2()); + QVector contourPoints; + CastTo(det.GetMappedContourPoints(), contourPoints); + ComparePathsDistance(contourPoints, OutputPointsCase2()); } //--------------------------------------------------------------------------------------------------------------------- @@ -160,10 +168,14 @@ QVector TST_VLayoutDetail::OutputPointsCase2() const void TST_VLayoutDetail::Case3() const { VLayoutPiece det = VLayoutPiece(); - det.SetCountourPoints(CastTo(InputPointsCase3())); + QVector inputPoints; + CastTo(InputPointsCase3(), inputPoints); + det.SetCountourPoints(inputPoints); // Begin comparison - ComparePathsDistance(CastTo(det.GetMappedContourPoints()), OutputPointsCase3()); + QVector contourPoints; + CastTo(det.GetMappedContourPoints(), contourPoints); + ComparePathsDistance(contourPoints, OutputPointsCase3()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/ValentinaTest/tst_vpiece.cpp b/src/test/ValentinaTest/tst_vpiece.cpp index 1554c25e8..67fd62c78 100644 --- a/src/test/ValentinaTest/tst_vpiece.cpp +++ b/src/test/ValentinaTest/tst_vpiece.cpp @@ -53,7 +53,8 @@ void TST_VPiece::Issue620() VPiece detail; AbstractTest::PieceFromJson(QStringLiteral("://Issue_620/input.json"), detail, data); - const QVector pointsEkv = CastTo(detail.MainPathPoints(data.data())); + QVector pointsEkv; + CastTo(detail.MainPathPoints(data.data()), pointsEkv); QVector origPoints = AbstractTest::VectorFromJson(QStringLiteral("://Issue_620/output.json")); // Begin comparison