From 222bbeaa7545633a6be3cdad741548184be406b6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 16 Aug 2016 18:23:38 +0300 Subject: [PATCH] Fixed issue #543. Detail loses details. (grafted from 7e5b3ed76ac3b86fd6112b90b51e8c0c4702bbf0) --HG-- branch : develop --- ChangeLog.txt | 1 + src/libs/vgeometry/vgobject.cpp | 14 +- src/libs/vgeometry/vgobject.h | 2 + src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_vgobject.cpp | 138 ++++++++++++++++++++ src/test/ValentinaTest/tst_vgobject.h | 45 +++++++ 7 files changed, 201 insertions(+), 7 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vgobject.cpp create mode 100644 src/test/ValentinaTest/tst_vgobject.h diff --git a/ChangeLog.txt b/ChangeLog.txt index 40e8370b5..b6fb43eec 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -55,6 +55,7 @@ - [#532] Unexpected error occurs when zoom out image. - [#537] Valentina crashes when use undo command. - [#544] Error: Color Lines are black until touched. +- [#543] Detail loses details. # Version 0.4.4 April 12, 2016 - Updated measurement templates with all measurements. Added new template Aldrich/Women measurements. diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index d5c1e8bdc..9934f7363 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -40,6 +40,8 @@ #include "../ifc/ifcdef.h" #include "vgobject_p.h" +double VGObject::accuracyPointOnLine = (0.5/*mm*/ / 25.4) * PrintDPI; + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGObject default constructor. @@ -505,14 +507,16 @@ double VGObject::PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPoi * There is the floating-point accuraccy problem, so instead of checking against zero, some epsilon value has to be * used. Because the size of the pdp value depends on the length of the vectors, no static value can be used. One * approach is to compare the pdp/area value to the fraction of another area which also depends on the length of the - * line e1=(p1, p2), e.g. the area of the square with side e1 which is computed below + * line e1=(p1, p2), e.g. the minimal area calucalted with PerpDotProduc() if point still not on the line. This distance + * is controled by variable accuracyPointOnLine */ double VGObject::GetEpsilon(const QPointF &p1, const QPointF &p2) { - const double dx1 = p2.x() - p1.x(); - const double dy1 = p2.y() - p1.y(); - const double epsilon = 0.06 * (dx1 * dx1 + dy1 * dy1); //-V636 - return epsilon; + QLineF line(p1, p2); + line.setAngle(line.angle() + 90); + line.setLength(accuracyPointOnLine); // less than accuracy means the same point + + return qAbs(PerpDotProduct(p1, p2, line.p2())); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index ba8f8625a..19a6ddc18 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -91,6 +91,8 @@ public: static QVector GetReversePoints(const QVector &points); static int GetLengthContour(const QVector &contour, const QVector &newPoints); + + static double accuracyPointOnLine; private: QSharedDataPointer d; diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 3673f84c6..ab9dec109 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -50,7 +50,8 @@ SOURCES += \ tst_vabstractcurve.cpp \ tst_findpoint.cpp \ tst_vellipticalarc.cpp \ - tst_vcubicbezierpath.cpp + tst_vcubicbezierpath.cpp \ + tst_vgobject.cpp win32-msvc*:SOURCES += stable.cpp @@ -71,7 +72,8 @@ HEADERS += \ tst_vabstractcurve.h \ tst_findpoint.h \ tst_vellipticalarc.h \ - tst_vcubicbezierpath.h + tst_vcubicbezierpath.h \ + tst_vgobject.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 cbf42dd43..a1bf9628d 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -44,6 +44,7 @@ #include "tst_findpoint.h" #include "tst_vabstractcurve.h" #include "tst_vcubicbezierpath.h" +#include "tst_vgobject.h" #include "../vmisc/def.h" @@ -76,6 +77,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VCommandLine()); ASSERT_TEST(new TST_VAbstractCurve()); ASSERT_TEST(new TST_VCubicBezierPath()); + ASSERT_TEST(new TST_VGObject()); return status; } diff --git a/src/test/ValentinaTest/tst_vgobject.cpp b/src/test/ValentinaTest/tst_vgobject.cpp new file mode 100644 index 000000000..4cdadad0d --- /dev/null +++ b/src/test/ValentinaTest/tst_vgobject.cpp @@ -0,0 +1,138 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 8, 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_vgobject.h" + +#include + +#include "../vgeometry/vgobject.h" +#include "../vmisc/def.h" + +//--------------------------------------------------------------------------------------------------------------------- +TST_VGObject::TST_VGObject(QObject *parent) + :QObject(parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VGObject::TestIsPointOnLineviaPDP_data() +{ + QTest::addColumn("p1"); + QTest::addColumn("p2"); + QTest::addColumn("t"); + QTest::addColumn("excpect"); + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416, 1920.763653543307); + QTest::newRow("Point is on line, but not on segment.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416, 2874.763653543307); + QTest::newRow("Point is on segment. On middle.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416, 1929.763653543307); + QTest::newRow("Point is on segment. The end of segment.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine, 2874.763653543307); + QTest::newRow("Min accuracy gap. On middle.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine, 1929.763653543307); + QTest::newRow("Min accuracy gap.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine/2., 2874.763653543307); + QTest::newRow("Less than min accuracy gap. On middle.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine/2., 1929.763653543307); + QTest::newRow("Less than min accuracy gap.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(370.1574803149606, 2874.763653543307); + QTest::newRow("Issue 534 - 3 cm gap. On middle.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(370.1574803149606, 1929.763653543307); + QTest::newRow("Issue 534 - 3 cm gap.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(407.9527559055118, 2874.763653543307); + QTest::newRow("Issue 534 - 2 cm gap. On middle.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(407.9527559055118, 1929.763653543307); + QTest::newRow("Issue 534 - 2 cm gap.") << p1 << p2 << t << false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VGObject::TestIsPointOnLineviaPDP() const +{ + QFETCH(QPointF, p1); + QFETCH(QPointF, p2); + QFETCH(QPointF, t); + QFETCH(bool, excpect); + + const bool res = VGObject::IsPointOnLineviaPDP(t, p1, p2); + QCOMPARE(res, excpect); +} + diff --git a/src/test/ValentinaTest/tst_vgobject.h b/src/test/ValentinaTest/tst_vgobject.h new file mode 100644 index 000000000..9211f6b17 --- /dev/null +++ b/src/test/ValentinaTest/tst_vgobject.h @@ -0,0 +1,45 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 8, 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_VGOBJECT_H +#define TST_VGOBJECT_H + +#include + +class TST_VGObject : public QObject +{ + Q_OBJECT +public: + explicit TST_VGObject(QObject *parent = nullptr); + +private slots: + void TestIsPointOnLineviaPDP_data(); + void TestIsPointOnLineviaPDP() const; +}; + +#endif // TST_VGOBJECT_H