split method

(Cubic, Cubic) split(
  1. double t
)

Returns two Cubics, created by splitting this curve at the given distance of t between the original starting and ending anchor points.

Implementation

// TODO: cartesian optimization?
(Cubic, Cubic) split(double t) {
  final u = 1 - t;
  final point = pointOnCurve(t);

  return (
    Cubic(
      anchor0X,
      anchor0Y,
      anchor0X * u + control0X * t,
      anchor0Y * u + control0Y * t,
      anchor0X * (u * u) + control0X * (2 * u * t) + control1X * (t * t),
      anchor0Y * (u * u) + control0Y * (2 * u * t) + control1Y * (t * t),
      point.x,
      point.y,
    ),
    Cubic(
      // TODO: should calculate once and share the result.
      point.x,
      point.y,
      control0X * (u * u) + control1X * (2 * u * t) + anchor1X * (t * t),
      control0Y * (u * u) + control1Y * (2 * u * t) + anchor1Y * (t * t),
      control1X * u + anchor1X * t,
      control1Y * u + anchor1Y * t,
      anchor1X,
      anchor1Y,
    ),
  );
}