getPoints method

  1. @override
List<Vector?> getPoints([
  1. int divisions = 12
])
override

divisions -- number of pieces to divide the curve into. Default is 12.

Returns an array of points representing a sequence of curves. The division parameter defines the number of pieces each curve is divided into. However, for optimization and quality purposes, the actual sampling resolution for each curve depends on its type. For example, for a page:LineCurve, the returned number of points is always just 2.

Implementation

@override
List<Vector?> getPoints([int divisions = 12]) {
  final List<Vector?> points = [];
  Vector? last;
  final List<Curve> curves = this.curves;

  for (int i = 0; i < curves.length; i++) {
    final curve = curves[i];
    final resolution = (curve.isEllipseCurve)
        ? divisions * 2
        : ((curve is LineCurve || curve is LineCurve3))
            ? 1
            : (curve.isSplineCurve)
                ? divisions * curve.points.length
                : divisions;

    final pts = curve.getPoints(resolution);

    for (int j = 0; j < pts.length; j++) {
      final point = pts[j];

      if (last != null && last.equals(point!)) {
        continue;
      } // ensures no consecutive points are duplicates

      points.add(point);
      last = point;
    }
  }

  if (autoClose &&
      points.length > 1 &&
      points[points.length - 1] != null &&
      points[0] != null &&
      !points[points.length - 1]!.equals(points[0]!)) {
    points.add(points[0]);
  }

  return points;
}