diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index e9e91f1cd..713239bf7 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -575,3 +576,39 @@ int VGObject::GetLengthContour(const QVector &contour, const QVector &contour, const QVector &newPoints); static double accuracyPointOnLine; +protected: + static QTransform FlippingMatrix(const QLineF &axis); private: QSharedDataPointer d; diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index 67de60447..d6c3ab42c 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -113,6 +114,14 @@ VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString return VPointF(p, name() + prefix, mx(), my()); } +//--------------------------------------------------------------------------------------------------------------------- +VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const +{ + const QTransform matrix = FlippingMatrix(axis); + const QPointF p = matrix.map(toQPointF()); + return VPointF(p, name() + prefix, mx(), my()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mx return offset name respect to x diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 1b4777a7f..8bd7e1eca 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -65,6 +65,7 @@ public: VPointF &operator=(const VPointF &point); operator QPointF() const; VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VPointF Flip(const QLineF &axis, const QString &prefix = QString()) const; qreal mx() const; qreal my() const; void setMx(qreal mx); diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 39e50881e..3f5c649de 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -52,7 +52,8 @@ SOURCES += \ tst_vellipticalarc.cpp \ tst_vcubicbezierpath.cpp \ tst_vgobject.cpp \ - tst_vsplinepath.cpp + tst_vsplinepath.cpp \ + tst_vpointf.cpp win32-msvc*:SOURCES += stable.cpp @@ -75,7 +76,8 @@ HEADERS += \ tst_vellipticalarc.h \ tst_vcubicbezierpath.h \ tst_vgobject.h \ - tst_vsplinepath.h + tst_vsplinepath.h \ + tst_vpointf.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 36d818382..02cf31d74 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -46,6 +46,7 @@ #include "tst_vcubicbezierpath.h" #include "tst_vgobject.h" #include "tst_vsplinepath.h" +#include "tst_vpointf.h" #include "../vmisc/def.h" @@ -80,6 +81,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VAbstractCurve()); ASSERT_TEST(new TST_VCubicBezierPath()); ASSERT_TEST(new TST_VGObject()); + ASSERT_TEST(new TST_VPointF()); return status; } diff --git a/src/test/ValentinaTest/tst_vpointf.cpp b/src/test/ValentinaTest/tst_vpointf.cpp new file mode 100644 index 000000000..6d3b983ba --- /dev/null +++ b/src/test/ValentinaTest/tst_vpointf.cpp @@ -0,0 +1,86 @@ +/************************************************************************ + ** + ** @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_vpointf.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/logging.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VPointF::TST_VPointF(QObject *parent) + : QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPointF::TestFlip_data() +{ + QTest::addColumn("originPoint"); + QTest::addColumn("axis"); + QTest::addColumn("flipped"); + QTest::addColumn("prefix"); + + VPointF originPoint; + QLineF axis = QLineF(QPointF(5, 0), QPointF(5, 10)); + QPointF flipped = QPointF(10, 0); + + QTest::newRow("Vertical axis") << originPoint << axis << flipped << "a2"; + + axis = QLineF(QPointF(0, 5), QPointF(10, 5)); + flipped = QPointF(0, 10); + + QTest::newRow("Horizontal axis") << originPoint << axis << flipped << "a2"; + + QLineF l = QLineF(QPointF(), QPointF(10, 0)); + l.setAngle(315); + flipped = l.p2(); + l.setLength(l.length()/2.0); + + axis = QLineF(l.p2(), l.p1()); + axis.setAngle(axis.angle()+90); + + QTest::newRow("Diagonal axis") << originPoint << axis << flipped << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPointF::TestFlip() +{ + QFETCH(VPointF, originPoint); + QFETCH(QLineF, axis); + QFETCH(QPointF, flipped); + QFETCH(QString, prefix); + + const VPointF res = originPoint.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(flipped.toPoint(), res.toQPointF().toPoint()); +} + diff --git a/src/test/ValentinaTest/tst_vpointf.h b/src/test/ValentinaTest/tst_vpointf.h new file mode 100644 index 000000000..903acfa38 --- /dev/null +++ b/src/test/ValentinaTest/tst_vpointf.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @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_VPOINTF_H +#define TST_VPOINTF_H + +#include +#include + +class TST_VPointF : public QObject +{ + Q_OBJECT +public: + explicit TST_VPointF(QObject *parent = nullptr); +private slots: + void TestFlip_data(); + void TestFlip(); +private: + Q_DISABLE_COPY(TST_VPointF) +}; + +#endif // TST_VPOINTF_H