New test. Check if epsilon value in method GetParmT() is enough for calculation.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-03-23 13:23:03 +02:00
parent ff667c8602
commit 910dadc871
4 changed files with 45 additions and 14 deletions

View File

@ -83,17 +83,7 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
length = GetLength()*0.98;
}
const qreal eps = 0.001 * qAbs(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);
}
const qreal parT = GetParmT(length);
QLineF seg1_2 ( GetP1 ().toQPointF(), GetControlPoint1 () );
seg1_2.setLength(seg1_2.length () * parT);
@ -137,6 +127,32 @@ QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const
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()
{

View File

@ -48,6 +48,9 @@ public:
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
qreal GetParmT(qreal length) const;
qreal LengthT(qreal t) const;
protected:
virtual void CreateName() Q_DECL_OVERRIDE;
@ -60,9 +63,6 @@ protected:
virtual QPointF GetControlPoint1() const =0;
virtual QPointF GetControlPoint2() const =0;
private:
qreal LengthT(qreal t) const;
};
#endif // VABSTRACTCUBICBEZIER_H

View File

@ -293,6 +293,20 @@ void TST_VSpline::CompareThreeWays()
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
{

View File

@ -47,6 +47,7 @@ private slots:
void GetSegmentPoints_TestPuzzle();
void GetSegmentPoints_NullSegment();
void CompareThreeWays();
void TestParametrT();
private:
Q_DISABLE_COPY(TST_VSpline)