From cbc7eb7571752b8bad9a6c97d72b8b6a3b8aea9e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Sep 2016 14:17:08 +0300 Subject: [PATCH 1/2] Test rotating VSplinePath. --HG-- branch : develop --- src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_vsplinepath.cpp | 137 ++++++++++++++++++++ src/test/ValentinaTest/tst_vsplinepath.h | 46 +++++++ 4 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vsplinepath.cpp create mode 100644 src/test/ValentinaTest/tst_vsplinepath.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index c72e37346..39e50881e 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -51,7 +51,8 @@ SOURCES += \ tst_findpoint.cpp \ tst_vellipticalarc.cpp \ tst_vcubicbezierpath.cpp \ - tst_vgobject.cpp + tst_vgobject.cpp \ + tst_vsplinepath.cpp win32-msvc*:SOURCES += stable.cpp @@ -73,7 +74,8 @@ HEADERS += \ tst_findpoint.h \ tst_vellipticalarc.h \ tst_vcubicbezierpath.h \ - tst_vgobject.h + tst_vgobject.h \ + tst_vsplinepath.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index a1bf9628d..36d818382 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -45,6 +45,7 @@ #include "tst_vabstractcurve.h" #include "tst_vcubicbezierpath.h" #include "tst_vgobject.h" +#include "tst_vsplinepath.h" #include "../vmisc/def.h" @@ -66,6 +67,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VPoster()); ASSERT_TEST(new TST_VAbstractDetail()); ASSERT_TEST(new TST_VSpline()); + ASSERT_TEST(new TST_VSplinePath()); ASSERT_TEST(new TST_NameRegExp()); ASSERT_TEST(new TST_VLayoutDetail()); ASSERT_TEST(new TST_VArc()); diff --git a/src/test/ValentinaTest/tst_vsplinepath.cpp b/src/test/ValentinaTest/tst_vsplinepath.cpp new file mode 100644 index 000000000..14af3e847 --- /dev/null +++ b/src/test/ValentinaTest/tst_vsplinepath.cpp @@ -0,0 +1,137 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "tst_vsplinepath.h" +#include "../vgeometry/vsplinepath.h" +#include "../vmisc/logging.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VSplinePath::TST_VSplinePath(QObject *parent) + : QObject (parent) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSplinePath::TestRotation_data() +{ + QTest::addColumn>("originPoints"); + QTest::addColumn("originPoint"); + QTest::addColumn("degrees"); + QTest::addColumn("prefix"); + QTest::addColumn>("rotatedPoints"); + + QVector originPoints; + + { + VPointF pSpline(30, 39.999874015748034, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 89.208600000000004, "89.2086", 269.20859999999999, "269.209", 0, "0", + 153.33618897637794, "4.05702"); + originPoints.append(p); + } + + { + VPointF pSpline(198.77104389529981, 249.18158602595835, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 146.43199999999999, "146.432", 326.43200000000002, "326.432", + 36.387590551181106, "0.962755", 60.978897637795278, "1.6134"); + originPoints.append(p); + } + + { + VPointF pSpline(820.42771653543309, 417.95262992125987, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 173.39500000000001, "173.395", 353.39499999999998, "353.395", + 381.23716535433073, "10.0869", 0, "0"); + originPoints.append(p); + } + + QVector rotatedPoints; + + { + VPointF pSpline(-347.55140568256883, 400.53936590535034, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 176.56789999999998, "176.568", 356.56790000000001, "356.568", 0, "0", + 153.33618897637794, "4.05702"); + rotatedPoints.append(p); + } + + { + VPointF pSpline(-130.81610509751462, 241.58508512833563, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 233.79130000000001, "233.791", 53.791300000000014, "53.7913", + 36.387590551181141, "0.962755", 60.978897637795207, "1.6134"); + rotatedPoints.append(p); + } + + { + VPointF pSpline(66.417055567032421, -371.63572683892357, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 260.7543, "260.754", 80.754300000000015, "80.7543", 381.23716535433078, "10.0869", 0, + "0"); + rotatedPoints.append(p); + } + + + QTest::newRow("Test spline path 1") << originPoints << QPointF(30, 417.95262992125987) << 87.359300000000005 << "a2" + << rotatedPoints; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSplinePath::TestRotation() +{ + QFETCH(QVector, originPoints); + QFETCH(QPointF, originPoint); + QFETCH(qreal, degrees); + QFETCH(QString, prefix); + QFETCH(QVector, rotatedPoints); + + const VSplinePath rotatedPath(rotatedPoints); + + const VSplinePath originPath(originPoints); + const VSplinePath res = originPath.Rotate(originPoint, degrees, prefix); + + QCOMPARE(originPath.GetLength(), res.GetLength()); + QCOMPARE(rotatedPath.GetLength(), res.GetLength()); + QCOMPARE(rotatedPath.CountPoints(), res.CountPoints()); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + const QVector resPoints = res.GetSplinePath(); + + for (int i=0; i < resPoints.size(); ++i) + { + const VSplinePoint resPoint = resPoints.at(i); + const VSplinePoint rotatedPoint = rotatedPoints.at(i); + + QCOMPARE(rotatedPoint.Angle1(), resPoint.Angle1()); + QCOMPARE(rotatedPoint.Angle2(), resPoint.Angle2()); + QCOMPARE(rotatedPoint.Length1(), resPoint.Length1()); + QCOMPARE(rotatedPoint.Length2(), resPoint.Length2()); + QCOMPARE(rotatedPoint.P().toQPointF().toPoint(), resPoint.P().toQPointF().toPoint()); + } +} + diff --git a/src/test/ValentinaTest/tst_vsplinepath.h b/src/test/ValentinaTest/tst_vsplinepath.h new file mode 100644 index 000000000..0baec27a2 --- /dev/null +++ b/src/test/ValentinaTest/tst_vsplinepath.h @@ -0,0 +1,46 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef TST_VSPLINEPATH_H +#define TST_VSPLINEPATH_H + +#include + +class TST_VSplinePath : public QObject +{ + Q_OBJECT +public: + explicit TST_VSplinePath(QObject *parent = nullptr); +private slots: + void TestRotation_data(); + void TestRotation(); +private: + Q_DISABLE_COPY(TST_VSplinePath) +}; + +#endif // TST_VSPLINEPATH_H From 868fc3db1d7f7c6836675eda2cf0373f544fa668 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Sep 2016 14:19:32 +0300 Subject: [PATCH 2/2] Fix definition VFSplinePoint and VSplinePoint. Improving efficiency. --HG-- branch : develop --- src/libs/vgeometry/vsplinepoint.cpp | 7 ++++--- src/libs/vgeometry/vsplinepoint.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libs/vgeometry/vsplinepoint.cpp b/src/libs/vgeometry/vsplinepoint.cpp index 21b09c5ae..db22decf7 100644 --- a/src/libs/vgeometry/vsplinepoint.cpp +++ b/src/libs/vgeometry/vsplinepoint.cpp @@ -50,7 +50,7 @@ VFSplinePoint::VFSplinePoint() * @param kAsm2 coefficient of length second control line. * @param angle2 second angle control line. */ -VFSplinePoint::VFSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) +VFSplinePoint::VFSplinePoint(const VPointF &pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) :d(new VFSplinePointData(pSpline, kAsm1, angle1, kAsm2, angle2)) {} @@ -195,8 +195,9 @@ VSplinePoint::VSplinePoint() } //--------------------------------------------------------------------------------------------------------------------- -VSplinePoint::VSplinePoint(VPointF pSpline, qreal angle1, const QString &angle1F, qreal angle2, const QString &angle2F, - qreal length1, const QString &length1F, qreal length2, const QString &length2F) +VSplinePoint::VSplinePoint(const VPointF &pSpline, qreal angle1, const QString &angle1F, qreal angle2, + const QString &angle2F, qreal length1, const QString &length1F, qreal length2, + const QString &length2F) : d(new VSplinePointData(pSpline, angle1, angle1F, angle2, angle2F, length1, length1F, length2, length2F)) { } diff --git a/src/libs/vgeometry/vsplinepoint.h b/src/libs/vgeometry/vsplinepoint.h index 7070b8575..daba6e5ad 100644 --- a/src/libs/vgeometry/vsplinepoint.h +++ b/src/libs/vgeometry/vsplinepoint.h @@ -47,7 +47,7 @@ class VFSplinePoint { public: VFSplinePoint(); - VFSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); + VFSplinePoint(const VPointF &pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); VFSplinePoint(const VFSplinePoint &point); VFSplinePoint &operator=(const VFSplinePoint &point); ~VFSplinePoint(); @@ -79,7 +79,7 @@ class VSplinePoint { public: VSplinePoint(); - VSplinePoint(VPointF pSpline, qreal angle1, const QString &angle1F, qreal angle2, const QString &angle2F, + VSplinePoint(const VPointF &pSpline, qreal angle1, const QString &angle1F, qreal angle2, const QString &angle2F, qreal length1, const QString &length1F, qreal length2, const QString &length2F); VSplinePoint(const VSplinePoint &point); VSplinePoint &operator=(const VSplinePoint &point);