New test. Check if epsilon value in method GetParmT() is enough for calculation.
--HG-- branch : develop
This commit is contained in:
parent
ff667c8602
commit
910dadc871
|
@ -83,17 +83,7 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
|
||||||
length = GetLength()*0.98;
|
length = GetLength()*0.98;
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal eps = 0.001 * qAbs(length);
|
const qreal parT = GetParmT(length);
|
||||||
qreal parT = 0.5;
|
|
||||||
qreal step = parT;
|
|
||||||
qreal splLength = LengthT(parT);
|
|
||||||
|
|
||||||
while (qAbs(splLength - length) > eps)
|
|
||||||
{
|
|
||||||
step = step/2.0;
|
|
||||||
splLength > length ? parT -= step : parT += step;
|
|
||||||
splLength = LengthT(parT);
|
|
||||||
}
|
|
||||||
|
|
||||||
QLineF seg1_2 ( GetP1 ().toQPointF(), GetControlPoint1 () );
|
QLineF seg1_2 ( GetP1 ().toQPointF(), GetControlPoint1 () );
|
||||||
seg1_2.setLength(seg1_2.length () * parT);
|
seg1_2.setLength(seg1_2.length () * parT);
|
||||||
|
@ -137,6 +127,32 @@ QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VAbstractCubicBezier::GetParmT(qreal length) const
|
||||||
|
{
|
||||||
|
if (length < 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (length > GetLength())
|
||||||
|
{
|
||||||
|
length = GetLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
const qreal eps = 0.001 * length;
|
||||||
|
qreal parT = 0.5;
|
||||||
|
qreal step = parT;
|
||||||
|
qreal splLength = LengthT(parT);
|
||||||
|
|
||||||
|
while (qAbs(splLength - length) > eps)
|
||||||
|
{
|
||||||
|
step /= 2.0;
|
||||||
|
splLength > length ? parT -= step : parT += step;
|
||||||
|
splLength = LengthT(parT);
|
||||||
|
}
|
||||||
|
return parT;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractCubicBezier::CreateName()
|
void VAbstractCubicBezier::CreateName()
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,9 @@ public:
|
||||||
|
|
||||||
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
|
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
qreal GetParmT(qreal length) const;
|
||||||
|
qreal LengthT(qreal t) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateName() Q_DECL_OVERRIDE;
|
virtual void CreateName() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -60,9 +63,6 @@ protected:
|
||||||
|
|
||||||
virtual QPointF GetControlPoint1() const =0;
|
virtual QPointF GetControlPoint1() const =0;
|
||||||
virtual QPointF GetControlPoint2() const =0;
|
virtual QPointF GetControlPoint2() const =0;
|
||||||
|
|
||||||
private:
|
|
||||||
qreal LengthT(qreal t) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VABSTRACTCUBICBEZIER_H
|
#endif // VABSTRACTCUBICBEZIER_H
|
||||||
|
|
|
@ -293,6 +293,20 @@ void TST_VSpline::CompareThreeWays()
|
||||||
CompareSplines(spl3, spl1);
|
CompareSplines(spl3, spl1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VSpline::TestParametrT()
|
||||||
|
{
|
||||||
|
VPointF p1(1168.8582803149607, 39.999874015748034, "p1", 5.0000125984251973, 9.9999874015748045);
|
||||||
|
VPointF p4(681.33729132409951, 1815.7969526662778, "p4", 5.0000125984251973, 9.9999874015748045);
|
||||||
|
|
||||||
|
VSpline spl(p1, p4, 229.381, 41.6325, 0.96294100000000005, 1.00054, 1);
|
||||||
|
|
||||||
|
const qreal halfLength = spl.GetLength()/2.0;
|
||||||
|
const qreal resLength = spl.LengthT(spl.GetParmT(halfLength));
|
||||||
|
|
||||||
|
QVERIFY(qAbs(halfLength - resLength) < UnitConvertor(0.5, Unit::Mm, Unit::Px));
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const
|
void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,7 @@ private slots:
|
||||||
void GetSegmentPoints_TestPuzzle();
|
void GetSegmentPoints_TestPuzzle();
|
||||||
void GetSegmentPoints_NullSegment();
|
void GetSegmentPoints_NullSegment();
|
||||||
void CompareThreeWays();
|
void CompareThreeWays();
|
||||||
|
void TestParametrT();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(TST_VSpline)
|
Q_DISABLE_COPY(TST_VSpline)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user