cubicTo method
void
cubicTo()
override
Implementation
@override
void cubicTo(
double x1, double y1, double x2, double y2, double x3, double y3) {
assert(!_expectsMove);
// ignore: parameter_assignments
x1 -= _offsetX;
// ignore: parameter_assignments
x2 -= _offsetX;
// ignore: parameter_assignments
x3 -= _offsetX;
// ignore: parameter_assignments
y1 -= _offsetY;
// ignore: parameter_assignments
y2 -= _offsetY;
// ignore: parameter_assignments
y3 -= _offsetY;
if (_quickRejectY(_prevY, y1, y2, y3)) {
_prevX = x3;
_prevY = y3;
return;
}
final count =
_countCubicSegments(_prevX, _prevY, x1, y1, x2, y2, x3, y3, _tolerance);
final dt = 1.0 / count;
double t = dt;
// Compute simple coefficients for the cubic polynomial
// ... much faster to evaluate multiple times
// ... At^3 + Bt^2 + Ct + D
//
final aX = (x3 - _prevX) + 3 * (x1 - x2);
final bX = 3 * ((x2 - x1) + (_prevX - x1));
final cX = 3 * (x1 - _prevX);
final dX = _prevX;
final aY = (y3 - _prevY) + 3 * (y1 - y2);
final bY = 3 * ((y2 - y1) + (_prevY - y1));
final cY = 3 * (y1 - _prevY);
final dY = _prevY;
// we don't need the first point eval(0) or the last eval(1)
double px = _prevX;
double py = _prevY;
for (int i = 1; i < count - 1; ++i) {
// Horner's method for evaluating the simple polynomial
final nx = ((aX * t + bX) * t + cX) * t + dX;
final ny = ((aY * t + bY) * t + cY) * t + dY;
_clipLine(px, py, nx, ny);
px = nx;
py = ny;
t += dt;
}
_clipLine(px, py, x3, y3);
_prevX = x3;
_prevY = y3;
}