New function VFuzzyComparePoints to compare two points.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2018-09-27 14:52:21 +03:00
parent 1eaccd6a41
commit 515df843d3
12 changed files with 27 additions and 59 deletions

View File

@ -115,7 +115,7 @@ qreal CSR(qreal length, qreal split, qreal arcLength)
const qreal arcAngle = sign > 0 ? line.angleTo(radius): radius.angleTo(line); const qreal arcAngle = sign > 0 ? line.angleTo(radius): radius.angleTo(line);
arcL = (M_PI*radius.length())/180.0 * arcAngle; arcL = (M_PI*radius.length())/180.0 * arcAngle;
} }
while(qAbs(arcL - arcLength) > (0.5/*mm*/ / 25.4) * PRINTDPI); while(qAbs(arcL - arcLength) > (0.5/*mm*/ / 25.4) * PrintDPI);
return angle; return angle;
} }
@ -262,9 +262,9 @@ qreal QmuParser::R2CM(qreal v)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal QmuParser::CSRCm(qreal length, qreal split, qreal arcLength) qreal QmuParser::CSRCm(qreal length, qreal split, qreal arcLength)
{ {
length = ((length * 10.0) / 25.4) * PRINTDPI; length = ((length * 10.0) / 25.4) * PrintDPI;
split = ((split * 10.0) / 25.4) * PRINTDPI; split = ((split * 10.0) / 25.4) * PrintDPI;
arcLength = ((arcLength * 10.0) / 25.4) * PRINTDPI; arcLength = ((arcLength * 10.0) / 25.4) * PrintDPI;
return CSR(length, split, arcLength); return CSR(length, split, arcLength);
} }
@ -272,9 +272,9 @@ qreal QmuParser::CSRCm(qreal length, qreal split, qreal arcLength)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal QmuParser::CSRInch(qreal length, qreal split, qreal arcLength) qreal QmuParser::CSRInch(qreal length, qreal split, qreal arcLength)
{ {
length = length * PRINTDPI; length = length * PrintDPI;
split = split * PRINTDPI; split = split * PrintDPI;
arcLength = arcLength * PRINTDPI; arcLength = arcLength * PrintDPI;
return CSR(length, split, arcLength); return CSR(length, split, arcLength);
} }

View File

@ -40,8 +40,6 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "vgobject_p.h" #include "vgobject_p.h"
const double VGObject::accuracyPointOnLine = (0.12/*mm*/ / 25.4) * PrintDPI;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VGObject default constructor. * @brief VGObject default constructor.

View File

@ -102,8 +102,6 @@ public:
template <typename T> template <typename T>
static QVector<T> GetReversePoints(const QVector<T> &points); static QVector<T> GetReversePoints(const QVector<T> &points);
static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints); static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
static const double accuracyPointOnLine;
protected: protected:
static QTransform FlippingMatrix(const QLineF &axis); static QTransform FlippingMatrix(const QLineF &axis);
private: private:

View File

@ -1256,7 +1256,7 @@ bool VAbstractPiece::IsEkvPointOnLine(const VSAPoint &iPoint, const VSAPoint &pr
return (VGObject::IsPointOnLineviaPDP(iPoint, prevPoint, nextPoint) return (VGObject::IsPointOnLineviaPDP(iPoint, prevPoint, nextPoint)
&& VGObject::IsPointOnLineviaPDP(bigLine1.p2(), bigLine1.p1(), bigLine2.p2()) && VGObject::IsPointOnLineviaPDP(bigLine1.p2(), bigLine1.p1(), bigLine2.p2())
&& VGObject::IsPointOnLineviaPDP(bigLine2.p1(), bigLine1.p1(), bigLine2.p2()) && VGObject::IsPointOnLineviaPDP(bigLine2.p1(), bigLine1.p1(), bigLine2.p2())
&& qAbs(prevPoint.GetSAAfter(tmpWidth) - nextPoint.GetSABefore(tmpWidth)) < VGObject::accuracyPointOnLine); && qAbs(prevPoint.GetSAAfter(tmpWidth) - nextPoint.GetSABefore(tmpWidth)) < accuracyPointOnLine);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -279,8 +279,7 @@ QVector<T> VAbstractPiece::RemoveDublicates(const QVector<T> &points, bool remov
{ {
// Path can't be closed // Path can't be closed
// See issue #686 // See issue #686
if ((qAbs(p.first().x() - p.last().x()) < VGObject::accuracyPointOnLine) if (VFuzzyComparePoints(p.first(), p.last()))
&& (qAbs(p.first().y() - p.last().y()) < VGObject::accuracyPointOnLine))
{ {
p.removeLast(); p.removeLast();
} }
@ -289,8 +288,7 @@ QVector<T> VAbstractPiece::RemoveDublicates(const QVector<T> &points, bool remov
for (int i = 0; i < p.size()-1; ++i) for (int i = 0; i < p.size()-1; ++i)
{ {
if ((qAbs(p.at(i).x() - p.at(i+1).x()) < VGObject::accuracyPointOnLine) if (VFuzzyComparePoints(p.at(i), p.at(i+1)))
&& (qAbs(p.at(i).y() - p.at(i+1).y()) < VGObject::accuracyPointOnLine))
{ {
if (not removeFirstAndLast && (i == p.size()-1)) if (not removeFirstAndLast && (i == p.size()-1))
{ {

View File

@ -463,6 +463,14 @@ static inline bool VFuzzyComparePossibleNulls(double p1, double p2)
} }
} }
Q_DECL_CONSTEXPR qreal accuracyPointOnLine = (0.12/*mm*/ / 25.4) * PrintDPI;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline bool VFuzzyComparePoints(const QPointF &p1, const QPointF &p2);
Q_DECL_CONSTEXPR static inline bool VFuzzyComparePoints(const QPointF &p1, const QPointF &p2)
{
return qAbs(p1.x() - p2.x()) <= accuracyPointOnLine && qAbs(p1.y() - p2.y()) <= accuracyPointOnLine;
}
/** /**
* @brief The CustomSA struct contains record about custom seam allowanse (SA). * @brief The CustomSA struct contains record about custom seam allowanse (SA).
*/ */

View File

@ -1,30 +0,0 @@
/************************************************************************
**
** @file global.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 13 11, 2017
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 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 "defglobal.h"
const qreal PrintDPI = PRINTDPI;

View File

@ -32,8 +32,7 @@
#include "backport/qoverload.h" #include "backport/qoverload.h"
#define PRINTDPI 96.0 Q_DECL_CONSTEXPR qreal PrintDPI = 96.0;
extern const qreal PrintDPI;
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
// this adds const to non-const objects (like std::as_const) // this adds const to non-const objects (like std::as_const)

View File

@ -12,7 +12,6 @@ SOURCES += \
$$PWD/qxtcsvmodel.cpp \ $$PWD/qxtcsvmodel.cpp \
$$PWD/vtablesearch.cpp \ $$PWD/vtablesearch.cpp \
$$PWD/dialogs/dialogexporttocsv.cpp \ $$PWD/dialogs/dialogexporttocsv.cpp \
$$PWD/defglobal.cpp \
$$PWD/literals.cpp $$PWD/literals.cpp
*msvc*:SOURCES += $$PWD/stable.cpp *msvc*:SOURCES += $$PWD/stable.cpp

View File

@ -1107,8 +1107,7 @@ bool VPiece::GetSeamPassmarkSAPoint(const VSAPoint &previousSAPoint, const VSAPo
if (IsEkvPointOnLine(passmarkSAPoint, previousSAPoint, nextSAPoint)// see issue #665 if (IsEkvPointOnLine(passmarkSAPoint, previousSAPoint, nextSAPoint)// see issue #665
|| (IsEkvPointOnLine(static_cast<QPointF>(passmarkSAPoint), static_cast<QPointF>(previousSAPoint), || (IsEkvPointOnLine(static_cast<QPointF>(passmarkSAPoint), static_cast<QPointF>(previousSAPoint),
static_cast<QPointF>(nextSAPoint)) static_cast<QPointF>(nextSAPoint))
&& qAbs(passmarkSAPoint.GetSABefore(width) && qAbs(passmarkSAPoint.GetSABefore(width) - passmarkSAPoint.GetSAAfter(width)) < accuracyPointOnLine))
- passmarkSAPoint.GetSAAfter(width)) < VGObject::accuracyPointOnLine))
{ {
QLineF line (passmarkSAPoint, nextSAPoint); QLineF line (passmarkSAPoint, nextSAPoint);
line.setAngle(line.angle() + 90); line.setAngle(line.angle() + 90);

View File

@ -69,8 +69,7 @@ void AbstractTest::Comparison(const QVector<QPointF> &ekv, const QVector<QPointF
const QString msg = QString("Index: %1. Got '%2;%3', Expected '%4;%5'.") const QString msg = QString("Index: %1. Got '%2;%3', Expected '%4;%5'.")
.arg(i).arg(p1.x()).arg(p1.y()).arg(p2.x()).arg(p2.y()); .arg(i).arg(p1.x()).arg(p1.y()).arg(p2.x()).arg(p2.y());
// Check each point. Don't use comparison float values // Check each point. Don't use comparison float values
QVERIFY2((qAbs(p1.x() - p2.x()) <= VGObject::accuracyPointOnLine) QVERIFY2(VFuzzyComparePoints(p1, p2), qUtf8Printable(msg));
&& (qAbs(p1.y() - p2.y()) <= VGObject::accuracyPointOnLine), qUtf8Printable(msg));
} }
} }

View File

@ -68,7 +68,7 @@ void TST_VGObject::TestIsPointOnLineviaPDP_data()
} }
{ {
const qreal gap = VGObject::accuracyPointOnLine; const qreal gap = accuracyPointOnLine;
const QPointF p1(483.54330708661416, 3819.527433070866); const QPointF p1(483.54330708661416, 3819.527433070866);
const QPointF p2(483.54330708661416, 1929.763653543307); const QPointF p2(483.54330708661416, 1929.763653543307);
const QPointF t(483.54330708661416 + gap, 2874.763653543307); const QPointF t(483.54330708661416 + gap, 2874.763653543307);
@ -76,7 +76,7 @@ void TST_VGObject::TestIsPointOnLineviaPDP_data()
} }
{ {
const qreal gap = VGObject::accuracyPointOnLine; const qreal gap = accuracyPointOnLine;
const QPointF p1(483.54330708661416, 3819.527433070866); const QPointF p1(483.54330708661416, 3819.527433070866);
const QPointF p2(483.54330708661416, 1929.763653543307); const QPointF p2(483.54330708661416, 1929.763653543307);
const QPointF t(483.54330708661416 + gap, 1929.763653543307); const QPointF t(483.54330708661416 + gap, 1929.763653543307);
@ -84,7 +84,7 @@ void TST_VGObject::TestIsPointOnLineviaPDP_data()
} }
{ {
const qreal gap = VGObject::accuracyPointOnLine + VGObject::accuracyPointOnLine*0.01; const qreal gap = accuracyPointOnLine + accuracyPointOnLine*0.01;
const QPointF p1(483.54330708661416, 3819.527433070866); const QPointF p1(483.54330708661416, 3819.527433070866);
const QPointF p2(483.54330708661416, 1929.763653543307); const QPointF p2(483.54330708661416, 1929.763653543307);
const QPointF t(483.54330708661416 + gap, 2874.763653543307); const QPointF t(483.54330708661416 + gap, 2874.763653543307);
@ -92,7 +92,7 @@ void TST_VGObject::TestIsPointOnLineviaPDP_data()
} }
{ {
const qreal gap = VGObject::accuracyPointOnLine + VGObject::accuracyPointOnLine*0.01; const qreal gap = accuracyPointOnLine + accuracyPointOnLine*0.01;
const QPointF p1(483.54330708661416, 3819.527433070866); const QPointF p1(483.54330708661416, 3819.527433070866);
const QPointF p2(483.54330708661416, 1929.763653543307); const QPointF p2(483.54330708661416, 1929.763653543307);
const QPointF t(483.54330708661416 + gap, 1929.763653543307); const QPointF t(483.54330708661416 + gap, 1929.763653543307);
@ -102,14 +102,14 @@ void TST_VGObject::TestIsPointOnLineviaPDP_data()
{ {
const QPointF p1(483.54330708661416, 3819.527433070866); const QPointF p1(483.54330708661416, 3819.527433070866);
const QPointF p2(483.54330708661416, 1929.763653543307); const QPointF p2(483.54330708661416, 1929.763653543307);
const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine/2., 2874.763653543307); const QPointF t(483.54330708661416 + accuracyPointOnLine/2., 2874.763653543307);
QTest::newRow("Less than min accuracy gap. On middle.") << p1 << p2 << t << true; QTest::newRow("Less than min accuracy gap. On middle.") << p1 << p2 << t << true;
} }
{ {
const QPointF p1(483.54330708661416, 3819.527433070866); const QPointF p1(483.54330708661416, 3819.527433070866);
const QPointF p2(483.54330708661416, 1929.763653543307); const QPointF p2(483.54330708661416, 1929.763653543307);
const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine/2., 1929.763653543307); const QPointF t(483.54330708661416 + accuracyPointOnLine/2., 1929.763653543307);
QTest::newRow("Less than min accuracy gap. The end of segment.") << p1 << p2 << t << true; QTest::newRow("Less than min accuracy gap. The end of segment.") << p1 << p2 << t << true;
} }