Fixed issue #543. Detail loses details.

(grafted from 7e5b3ed76ac3b86fd6112b90b51e8c0c4702bbf0)

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-08-16 18:23:38 +03:00
parent 3ef57202d1
commit 222bbeaa75
7 changed files with 201 additions and 7 deletions

View File

@ -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.

View File

@ -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()));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -91,6 +91,8 @@ public:
static QVector<QPointF> GetReversePoints(const QVector<QPointF> &points);
static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
static double accuracyPointOnLine;
private:
QSharedDataPointer<VGObjectData> d;

View File

@ -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()

View File

@ -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;
}

View File

@ -0,0 +1,138 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "tst_vgobject.h"
#include <QtTest>
#include "../vgeometry/vgobject.h"
#include "../vmisc/def.h"
//---------------------------------------------------------------------------------------------------------------------
TST_VGObject::TST_VGObject(QObject *parent)
:QObject(parent)
{}
//---------------------------------------------------------------------------------------------------------------------
void TST_VGObject::TestIsPointOnLineviaPDP_data()
{
QTest::addColumn<QPointF>("p1");
QTest::addColumn<QPointF>("p2");
QTest::addColumn<QPointF>("t");
QTest::addColumn<bool>("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);
}

View File

@ -0,0 +1,45 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef TST_VGOBJECT_H
#define TST_VGOBJECT_H
#include <QObject>
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