bezierCurveTo method

void bezierCurveTo(
  1. double cp1x,
  2. double cp1y,
  3. double cp2x,
  4. double cp2y,
  5. double x,
  6. double y,
)

Draws a cubic bezier curve to the given point.

Implementation

void bezierCurveTo(
  double cp1x,
  double cp1y,
  double cp2x,
  double cp2y,
  double x,
  double y,
) {
  // Approximate bezier curve with line segments
  final p0 = _currentPoint ?? Point.zero;
  final p1 = Point(cp1x, cp1y);
  final p2 = Point(cp2x, cp2y);
  final p3 = Point(x, y);

  const segments = 10;
  for (int i = 1; i <= segments; i++) {
    final t = i / segments;
    final point = _cubicBezier(p0, p1, p2, p3, t);
    _points.add(point);
  }

  _currentPoint = p3;
}