From a4ec72b3bd6a6d25e9aaa544d77b311ba9cf7ccf Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 19 Sep 2018 15:16:29 +0300 Subject: [PATCH] Help function to speed up creating tests. --HG-- branch : release --- src/libs/vlayout/vabstractpiece.cpp | 126 +++++++++++++++++++++++++++- src/libs/vmisc/def.h | 3 +- 2 files changed, 124 insertions(+), 5 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index ab92ed11b..c25719f94 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -35,6 +35,7 @@ #include #include #include +#include const qreal maxL = 2.5; @@ -618,13 +619,121 @@ qreal AngleBetweenBisectors(const QLineF &b1, const QLineF &b2) angle2 = 0; } - if (angle1 <= angle2) + return qMin(angle1, angle2); +} + +//--------------------------------------------------------------------------------------------------------------------- +// Use for writing tests +void DumpVector(const QVector &points) +{ + QTemporaryFile temp; // Go to tmp folder to find dump + temp.setAutoRemove(false); // Remove dump manually + if (temp.open()) { - return angle1; + QTextStream out(&temp); + out << "QVector points;" << endl << endl; + + for(auto point : points) + { + out << QString("points += QPointF(%1, %2);").arg(point.x()).arg(point.y()) << endl; + } + + out << endl << "return points;"; } - else +} + +//--------------------------------------------------------------------------------------------------------------------- +// Use for writing tests +void DumpVector(const QVector &points) +{ + QTemporaryFile temp; // Go to tmp folder to find dump + temp.setAutoRemove(false); // Remove dump manually + if (temp.open()) { - return angle2; + QTextStream out(&temp); + + out << "QVector points;" << endl; + + bool firstPoint = true; + enum PointType {Unknown, Default, Custom}; + PointType type = Unknown; + + for(auto point : points) + { + if (VFuzzyComparePossibleNulls(point.GetSAAfter(), -1) + and VFuzzyComparePossibleNulls(point.GetSABefore(), -1) + and point.GetAngleType() == PieceNodeAngle::ByLength) + { + if (type != Default) + { + out << endl; + } + type = Default; + out << QString("points += VSAPoint(%1, %2);").arg(point.x()).arg(point.y()) << endl; + } + else + { + out << endl; + type = Custom; + + if (firstPoint) + { + out << "VSAPoint "; + firstPoint = false; + } + out << QString("p = VSAPoint(%1, %2);").arg(point.x()).arg(point.y()) << endl; + + if (not VFuzzyComparePossibleNulls(point.GetSABefore(), -1)) + { + out << QString("p.SetSABefore(%1);").arg(point.GetSABefore()) << endl; + } + + if (not VFuzzyComparePossibleNulls(point.GetSAAfter(), -1)) + { + out << QString("p.SetSAAfter(%1);").arg(point.GetSAAfter()) << endl; + } + + if (point.GetAngleType() != PieceNodeAngle::ByLength) + { +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + // This check helps to find missed angle types in the switch + Q_STATIC_ASSERT_X(static_cast(PieceNodeAngle::LAST_ONE_DO_NOT_USE) == 6, + "Not all types were handled."); + + QString typeStr; + switch (point.GetAngleType()) + { + case PieceNodeAngle::LAST_ONE_DO_NOT_USE: + case PieceNodeAngle::ByLength: + Q_UNREACHABLE(); //-V501 + break; + case PieceNodeAngle::ByPointsIntersection: + typeStr = "ByPointsIntersection"; + break; + case PieceNodeAngle::ByFirstEdgeSymmetry: + typeStr = "ByFirstEdgeSymmetry"; + break; + case PieceNodeAngle::BySecondEdgeSymmetry: + typeStr = "BySecondEdgeSymmetry"; + break; + case PieceNodeAngle::ByFirstEdgeRightAngle: + typeStr = "ByFirstEdgeRightAngle"; + break; + case PieceNodeAngle::BySecondEdgeRightAngle: + typeStr = "BySecondEdgeRightAngle"; + break; + } +QT_WARNING_POP + + out << QString("p.SetAngleType(PieceNodeAngle::%1);").arg(typeStr) << endl; + } + + out << "points += p;" << endl; + } + } + + out << endl << "return points;"; } } } @@ -757,6 +866,8 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid return QVector(); } +// DumpVector(points); // Uncomment for dumping test data + points = CorrectEquidistantPoints(points); if ( points.size() < 3 ) { @@ -793,6 +904,7 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid const bool removeFirstAndLast = false; ekvPoints = CheckLoops(CorrectEquidistantPoints(ekvPoints, removeFirstAndLast));//Result path can contain loops +// DumpVector(ekvPoints); // Uncomment for dumping test data return ekvPoints; } @@ -1029,8 +1141,14 @@ QVector VAbstractPiece::EkvPoint(QVector points, const VSAPoin {//Regular equdistant case QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") + // This check helps to find missed angle types in the switch + Q_STATIC_ASSERT_X(static_cast(PieceNodeAngle::LAST_ONE_DO_NOT_USE) == 6, + "Not all types were handled."); switch (p2Line1.GetAngleType()) { + case PieceNodeAngle::LAST_ONE_DO_NOT_USE: + Q_UNREACHABLE(); //-V501 + break; case PieceNodeAngle::ByLength: return AngleByLength(points, p2Line1, bigLine1, crosPoint, bigLine2, p2Line1, width); case PieceNodeAngle::ByPointsIntersection: diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 7796a6d96..9c37c1974 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -77,7 +77,8 @@ enum class PieceNodeAngle : unsigned char ByFirstEdgeSymmetry, BySecondEdgeSymmetry, ByFirstEdgeRightAngle, - BySecondEdgeRightAngle + BySecondEdgeRightAngle, + LAST_ONE_DO_NOT_USE }; enum class PassmarkLineType : unsigned char