curve static method

List<Op> curve(
  1. List<PointD> points,
  2. DrawConfig config
)

Implementation

static List<Op> curve(List<PointD> points, DrawConfig config) {
  final int len = points.length;
  if (len > 3) {
    final List<Op> ops = [];
    final double s = 1 - config.curveTightness!;
    ops.add(Op.move(points[1]));
    for (int i = 1; (i + 2) < len; i++) {
      final point = points[i];
      final next = points[i + 1];
      final afterNext = points[i + 2];
      final PointD previous = points[i - 1];
      final control1 = PointD(point.x + (s * next.x - s * previous.x) / 6,
          point.y + (s * next.y - s * previous.y) / 6);
      final control2 = PointD(next.x + (s * point.x - s * afterNext.x) / 6,
          next.y + (s * point.y - s * afterNext.y) / 6);
      final end = PointD(next.x, next.y);
      ops.add(Op.curveTo(control1, control2, end));
    }
    return ops;
  } else if (len == 3) {
    return [Op.move(points[1]), Op.curveTo(points[1], points[2], points[2])];
  } else if (len == 2) {
    return doubleLine(
        points[0].x, points[0].y, points[1].x, points[1].y, config);
  }
  return [];
}