Better way to seek value of t.
--HG-- branch : develop
This commit is contained in:
parent
a91112faee
commit
a56c3354e1
|
@ -83,45 +83,41 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
|
||||||
length = GetLength()*0.98;
|
length = GetLength()*0.98;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Very stupid way find correct value of t.
|
const qreal eps = 0.001 * qAbs(length);
|
||||||
// Better first compare with t = 0.5. Find length of spline.
|
qreal parT = 0.5;
|
||||||
// If length larger, take t = 0.75 and so on.
|
qreal step = parT;
|
||||||
// If length less, take t = 0.25 and so on.
|
|
||||||
qreal parT = 0;
|
|
||||||
qreal step = 0.001;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
parT = parT + step;
|
|
||||||
qreal splLength = LengthT(parT);
|
qreal splLength = LengthT(parT);
|
||||||
if (splLength >= length || parT > 1)
|
|
||||||
|
while (qAbs(splLength - length) > eps)
|
||||||
{
|
{
|
||||||
break;
|
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);
|
||||||
QPointF p12 = seg1_2.p2();
|
const QPointF p12 = seg1_2.p2();
|
||||||
|
|
||||||
QLineF seg2_3 ( GetControlPoint1(), GetControlPoint2 () );
|
QLineF seg2_3 ( GetControlPoint1(), GetControlPoint2 () );
|
||||||
seg2_3.setLength(seg2_3.length () * parT);
|
seg2_3.setLength(seg2_3.length () * parT);
|
||||||
QPointF p23 = seg2_3.p2();
|
const QPointF p23 = seg2_3.p2();
|
||||||
|
|
||||||
QLineF seg12_23 ( p12, p23 );
|
QLineF seg12_23 ( p12, p23 );
|
||||||
seg12_23.setLength(seg12_23.length () * parT);
|
seg12_23.setLength(seg12_23.length () * parT);
|
||||||
QPointF p123 = seg12_23.p2();
|
const QPointF p123 = seg12_23.p2();
|
||||||
|
|
||||||
QLineF seg3_4 ( GetControlPoint2 (), GetP4 ().toQPointF() );
|
QLineF seg3_4 ( GetControlPoint2 (), GetP4 ().toQPointF() );
|
||||||
seg3_4.setLength(seg3_4.length () * parT);
|
seg3_4.setLength(seg3_4.length () * parT);
|
||||||
QPointF p34 = seg3_4.p2();
|
const QPointF p34 = seg3_4.p2();
|
||||||
|
|
||||||
QLineF seg23_34 ( p23, p34 );
|
QLineF seg23_34 ( p23, p34 );
|
||||||
seg23_34.setLength(seg23_34.length () * parT);
|
seg23_34.setLength(seg23_34.length () * parT);
|
||||||
QPointF p234 = seg23_34.p2();
|
const QPointF p234 = seg23_34.p2();
|
||||||
|
|
||||||
QLineF seg123_234 ( p123, p234 );
|
QLineF seg123_234 ( p123, p234 );
|
||||||
seg123_234.setLength(seg123_234.length () * parT);
|
seg123_234.setLength(seg123_234.length () * parT);
|
||||||
QPointF p1234 = seg123_234.p2();
|
const QPointF p1234 = seg123_234.p2();
|
||||||
|
|
||||||
spl1p2 = p12;
|
spl1p2 = p12;
|
||||||
spl1p3 = p123;
|
spl1p3 = p123;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user