Refactoring. In some cases, for systems with different precision,

IsPointOnLineviaPDP must take different accuracy value.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-07-21 09:00:42 +03:00
parent 3c289f6d60
commit 71466eac13
2 changed files with 7 additions and 6 deletions

View File

@ -492,10 +492,10 @@ QPointF VGObject::CorrectDistortion(const QPointF &t, const QPointF &p1, const Q
* The pdp is zero only if the t lies on the line e1 = vector from p1 to p2.
* @return true if point is on line
*/
bool VGObject::IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2)
bool VGObject::IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2, qreal accuracy)
{
const double p = qAbs(PerpDotProduct(p1, p2, t));
const double e = GetEpsilon(p1, p2);
const double e = GetEpsilon(p1, p2, accuracy);
// We can't use common "<=" here because of the floating-point accuraccy problem
return p < e || VFuzzyComparePossibleNulls(p, e);
}
@ -521,11 +521,11 @@ double VGObject::PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPoi
* 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)
double VGObject::GetEpsilon(const QPointF &p1, const QPointF &p2, qreal accuracy)
{
QLineF line(p1, p2);
line.setAngle(line.angle() + 90);
line.setLength(accuracyPointOnLine); // less than accuracy means the same point
line.setLength(accuracy); // less than accuracy means the same point
return qAbs(PerpDotProduct(p1, p2, line.p2()));
}

View File

@ -98,7 +98,8 @@ public:
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
static bool IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2);
static QPointF CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2);
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2);
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2,
qreal accuracy = accuracyPointOnLine);
template <typename T>
static QVector<T> GetReversePoints(const QVector<T> &points);
@ -109,7 +110,7 @@ private:
QSharedDataPointer<VGObjectData> d;
static double PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPointF &t);
static double GetEpsilon(const QPointF &p1, const QPointF &p2);
static double GetEpsilon(const QPointF &p1, const QPointF &p2, qreal accuracy);
static int PointInCircle (const QPointF &p, const QPointF &center, qreal radius);
};