QBezier QBezier::bezierOnInterval(qreal t0, qreal t1) const { if (t0 == 0 && t1 == 1) return *this; QBezier bezier = *this; QBezier result; bezier.parameterSplitLeft(t0, &result); qreal trueT = (t1-t0)/(1-t0); bezier.parameterSplitLeft(trueT, &result); return result; }
qreal QBezier::tAtLength(qreal l) const { qreal len = length(); qreal t = qreal(1.0); const qreal error = qreal(0.01); if (l > len || qFuzzyCompare(l, len)) return t; t *= qreal(0.5); //int iters = 0; //qDebug()<<"LEN is "<<l<<len; qreal lastBigger = qreal(1.0); while (1) { //qDebug()<<"\tt is "<<t; QBezier right = *this; QBezier left; right.parameterSplitLeft(t, &left); qreal lLen = left.length(); if (qAbs(lLen - l) < error) break; if (lLen < l) { t += (lastBigger - t) * qreal(0.5); } else { lastBigger = t; t -= t * qreal(0.5); } //++iters; } //qDebug()<<"number of iters is "<<iters; return t; }
QBezier QBezier::getSubRange(qreal t0, qreal t1) const { QBezier result; QBezier temp; // cut at t1 if (qFuzzyIsNull(t1 - qreal(1.))) { result = *this; } else { temp = *this; temp.parameterSplitLeft(t1, &result); } // cut at t0 if (!qFuzzyIsNull(t0)) result.parameterSplitLeft(t0 / t1, &temp); return result; }