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.0 - t;
  final pointOnCurve = this.pointOnCurve(t);

  // Shared calculations
  final uSquared = u * u;
  final tSquared = t * t;
  final twoUt = 2.0 * u * t;

  return (
    .from(
      anchor0X,
      anchor0Y,
      anchor0X * u + control0X * t,
      anchor0Y * u + control0Y * t,
      anchor0X * uSquared + control0X * twoUt + control1X * tSquared,
      anchor0Y * uSquared + control0Y * twoUt + control1Y * tSquared,
      pointOnCurve.x,
      pointOnCurve.y,
    ),
    .from(
      pointOnCurve.x,
      pointOnCurve.y,
      control0X * uSquared + control1X * twoUt + anchor1X * tSquared,
      control0Y * uSquared + control1Y * twoUt + anchor1Y * tSquared,
      control1X * u + anchor1X * t,
      control1Y * u + anchor1Y * t,
      anchor1X,
      anchor1Y,
    ),
  );
}