From 7392e8e914d13424f133e155291a8461c667e3ca Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 17 May 2015 18:31:17 +0300 Subject: [PATCH] Fixed issue #304. Layout appears different than my pattern. --HG-- branch : develop --- src/libs/vlayout/vabstractdetail.cpp | 37 ++-- src/libs/vlayout/vlayoutdetail.cpp | 26 +-- src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + .../ValentinaTest/tst_vabstractdetail.cpp | 4 +- src/test/ValentinaTest/tst_vlayoutdetail.cpp | 186 ++++++++++++++++++ src/test/ValentinaTest/tst_vlayoutdetail.h | 57 ++++++ 7 files changed, 272 insertions(+), 46 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vlayoutdetail.cpp create mode 100644 src/test/ValentinaTest/tst_vlayoutdetail.h diff --git a/src/libs/vlayout/vabstractdetail.cpp b/src/libs/vlayout/vabstractdetail.cpp index 5c8ab52e5..11845cf92 100644 --- a/src/libs/vlayout/vabstractdetail.cpp +++ b/src/libs/vlayout/vabstractdetail.cpp @@ -227,26 +227,27 @@ QVector VAbstractDetail::Equidistant(const QVector &points, co QVector VAbstractDetail::RemoveDublicates(const QVector &points) { QVector p = points; - for (int i = 0; i < p.size(); i++) - { - QPointF current = p.at(i); - for (int j = i; j < p.size(); j++) + if (not p.isEmpty() && p.size() > 1) + { + // Path can't be closed + if (p.first() == p.last()) { - if (j == i) - { - continue; - } - else - { - QPointF temp = p.at(j); - if (current == temp) - { - QVector::iterator iter = p.begin() + j; - p.erase(iter); - j--; - } - } + #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) + p.remove(p.size() - 1); + #else + p.removeLast(); + #endif + } + } + + for (int i = 0; i < p.size()-1; ++i) + { + if (p.at(i) == p.at(i+1)) + { + p.erase(p.begin() + i + 1); + --i; + continue; } } diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 2cd9826f9..09e921aa2 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -74,21 +74,7 @@ QVector VLayoutDetail::GetContourPoints() const //--------------------------------------------------------------------------------------------------------------------- void VLayoutDetail::SetCountourPoints(const QVector &points) { - d->contour = points; - if (not d->contour.isEmpty()) - { - // Contour can't be closed - if (d->contour.first() == d->contour.last()) - { - #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) - d->contour.remove(d->layoutAllowence.size() - 1); - #else - d->contour.removeLast(); - #endif - } - } - - d->contour = RemoveDublicates(RoundPoints(d->contour)); + d->contour = RemoveDublicates(RoundPoints(points)); } //--------------------------------------------------------------------------------------------------------------------- @@ -107,16 +93,6 @@ void VLayoutDetail::SetSeamAllowencePoints(const QVector &points, bool d->seamAllowence = points; if (not d->seamAllowence.isEmpty()) { - // Seam allowence can't be closed - if (d->seamAllowence.first() == d->seamAllowence.last()) - { - #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) - d->seamAllowence.remove(d->layoutAllowence.size() - 1); - #else - d->seamAllowence.removeLast(); - #endif - } - d->seamAllowence = RemoveDublicates(RoundPoints(d->seamAllowence)); } else diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 602201a6c..f2954bbde 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -39,14 +39,16 @@ SOURCES += \ tst_vabstractdetail.cpp \ tst_vspline.cpp \ abstracttest.cpp \ - tst_nameregexp.cpp + tst_nameregexp.cpp \ + tst_vlayoutdetail.cpp HEADERS += \ tst_vposter.h \ tst_vabstractdetail.h \ tst_vspline.h \ abstracttest.h \ - tst_nameregexp.h + tst_nameregexp.h \ + tst_vlayoutdetail.h CONFIG(debug, debug|release){ # Debug mode diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 152ded166..a4fa8d606 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -32,6 +32,7 @@ #include "tst_vabstractdetail.h" #include "tst_vspline.h" #include "tst_nameregexp.h" +#include "tst_vlayoutdetail.h" int main(int argc, char** argv) { @@ -48,6 +49,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VAbstractDetail()); ASSERT_TEST(new TST_VSpline()); ASSERT_TEST(new TST_NameRegExp()); + ASSERT_TEST(new TST_VLayoutDetail()); return status; } diff --git a/src/test/ValentinaTest/tst_vabstractdetail.cpp b/src/test/ValentinaTest/tst_vabstractdetail.cpp index 978545ab7..2e2582ae6 100644 --- a/src/test/ValentinaTest/tst_vabstractdetail.cpp +++ b/src/test/ValentinaTest/tst_vabstractdetail.cpp @@ -42,7 +42,9 @@ TST_VAbstractDetail::TST_VAbstractDetail(QObject *parent) void TST_VAbstractDetail::EquidistantRemoveLoop() const { // These are two real cases where equdistant has loop. - // Code should clean loops. + // See issue #298. Segmented Curve isn't selected in Seam Allowance tool. + // https://bitbucket.org/dismine/valentina/issue/298/segmented-curve-isnt-selected-in-seam + // Code should clean loops in path. Case1(); Case2(); } diff --git a/src/test/ValentinaTest/tst_vlayoutdetail.cpp b/src/test/ValentinaTest/tst_vlayoutdetail.cpp new file mode 100644 index 000000000..64272204d --- /dev/null +++ b/src/test/ValentinaTest/tst_vlayoutdetail.cpp @@ -0,0 +1,186 @@ +/************************************************************************ + ** + ** @file tst_vlayoutdetail.cpp + ** @author Roman Telezhynskyi + ** @date 17 5, 2015 + ** + ** @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) 2015 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_vlayoutdetail.h" +#include "../../libs/vlayout/vlayoutdetail.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VLayoutDetail::TST_VLayoutDetail(QObject *parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VLayoutDetail::RemoveDublicates() const +{ + qDebug()<<"Case 1."; + Case1(); + + qDebug()<<"Case 2."; + Case2(); + + qDebug()<<"Case 3."; + Case3(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VLayoutDetail::Case1() const +{ + // See issue #304. Layout appears different than my pattern. + // https://bitbucket.org/dismine/valentina/issue/304/layout-appears-different-than-my-pattern + + VLayoutDetail det = VLayoutDetail(); + det.SetCountourPoints(InputPointsCase1()); + + // Begin comparison + Comparison(det.GetContourPoints(), OutputPointsCase1()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TST_VLayoutDetail::InputPointsCase1() const +{ + QVector points; + + points += QPointF(557.0, -94.0); + points += QPointF(760.0, -53.0); + points += QPointF(661.0, 411.0); + points += QPointF(708.0, 467.0); + points += QPointF(366.0, 845.0); + points += QPointF(750.0, 509.0); + points += QPointF(957.0, 556.0); + points += QPointF(933.0, 787.0); + points += QPointF(366.0, 845.0); + points += QPointF(921.0, 901.0); + points += QPointF(883.0, 1158.0); + points += QPointF(866.0, 1446.0); + points += QPointF(396.0, 1446.0); + points += QPointF(400.0, 1093.0); + points += QPointF(366.0, 917.0); + points += QPointF(366.0, 845.0); + points += QPointF(466.0, 411.0); + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TST_VLayoutDetail::OutputPointsCase1() const +{ + QVector points; + + points += QPointF(557.0, -94.0); + points += QPointF(760.0, -53.0); + points += QPointF(661.0, 411.0); + points += QPointF(708.0, 467.0); + points += QPointF(366.0, 845.0); + points += QPointF(750.0, 509.0); + points += QPointF(957.0, 556.0); + points += QPointF(933.0, 787.0); + points += QPointF(366.0, 845.0); + points += QPointF(921.0, 901.0); + points += QPointF(883.0, 1158.0); + points += QPointF(866.0, 1446.0); + points += QPointF(396.0, 1446.0); + points += QPointF(400.0, 1093.0); + points += QPointF(366.0, 917.0); + points += QPointF(366.0, 845.0); + points += QPointF(466.0, 411.0); + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VLayoutDetail::Case2() const +{ + VLayoutDetail det = VLayoutDetail(); + det.SetCountourPoints(InputPointsCase2()); + + // Begin comparison + Comparison(det.GetContourPoints(), OutputPointsCase2()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TST_VLayoutDetail::InputPointsCase2() const +{ + QVector points; + + points += QPointF(557.0, -94.0); + points += QPointF(760.0, -53.0); + points += QPointF(760.0, -53.0);// Need delete this part + points += QPointF(760.0, -53.0);// Need delete this part + points += QPointF(760.0, -53.0);// Need delete this part + points += QPointF(661.0, 411.0); + points += QPointF(708.0, 467.0); + points += QPointF(366.0, 845.0); + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TST_VLayoutDetail::OutputPointsCase2() const +{ + QVector points; + + points += QPointF(557.0, -94.0); + points += QPointF(760.0, -53.0); + points += QPointF(661.0, 411.0); + points += QPointF(708.0, 467.0); + points += QPointF(366.0, 845.0); + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VLayoutDetail::Case3() const +{ + VLayoutDetail det = VLayoutDetail(); + det.SetCountourPoints(InputPointsCase3()); + + // Begin comparison + Comparison(det.GetContourPoints(), OutputPointsCase3()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TST_VLayoutDetail::InputPointsCase3() const +{ + QVector points; + + points += QPointF(557.0, -94.0);// Only one point + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector TST_VLayoutDetail::OutputPointsCase3() const +{ + QVector points; + + points += QPointF(557.0, -94.0);// Only one point + + return points; +} diff --git a/src/test/ValentinaTest/tst_vlayoutdetail.h b/src/test/ValentinaTest/tst_vlayoutdetail.h new file mode 100644 index 000000000..1fe004a52 --- /dev/null +++ b/src/test/ValentinaTest/tst_vlayoutdetail.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file tst_vlayoutdetail.h + ** @author Roman Telezhynskyi + ** @date 17 5, 2015 + ** + ** @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) 2015 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_VLAYOUTDETAIL_H +#define TST_VLAYOUTDETAIL_H + +#include "abstracttest.h" + +class TST_VLayoutDetail : public AbstractTest +{ + Q_OBJECT +public: + TST_VLayoutDetail(QObject *parent = 0); + +private slots: + void RemoveDublicates() const; + +private: + void Case1() const; + QVector InputPointsCase1() const; + QVector OutputPointsCase1() const; + + void Case2() const; + QVector InputPointsCase2() const; + QVector OutputPointsCase2() const; + + void Case3() const; + QVector InputPointsCase3() const; + QVector OutputPointsCase3() const; +}; + +#endif // TST_VLAYOUTDETAIL_H