split method
Returns two Cubics, created by splitting this curve at the given distance of t between the
original starting and ending anchor points.
Implementation
(Cubic, Cubic) split(double t) {
// Cartesian optimization via the De Casteljau's algorithm.
// Use barycentric interpolation.
final u = 1.0 - t;
// Interpolation 1.
final p01X = anchor0X * u + control0X * t;
final p01Y = anchor0Y * u + control0Y * t;
final p12X = control0X * u + control1X * t;
final p12Y = control0Y * u + control1Y * t;
final p23X = control1X * u + anchor1X * t;
final p23Y = control1Y * u + anchor1Y * t;
// Interpolation 2.
final p012X = p01X * u + p12X * t;
final p012Y = p01Y * u + p12Y * t;
final p123X = p12X * u + p23X * t;
final p123Y = p12Y * u + p23Y * t;
// Interpolation 3.
final p0123X = p012X * u + p123X * t;
final p0123Y = p012Y * u + p123Y * t;
return (
.from(anchor0X, anchor0Y, p01X, p01Y, p012X, p012Y, p0123X, p0123Y),
.from(p0123X, p0123Y, p123X, p123Y, p23X, p23Y, anchor1X, anchor1Y),
);
}