insertNCurvesToPointList method

List<Vector3> insertNCurvesToPointList(
  1. int n,
  2. List<Vector3> points
)

Implementation

List<Vector3> insertNCurvesToPointList(int n, List<Vector3> points) {
  if (points.length == 1) {
    return [for (var _ in range(end: nPointsPerCurve * n)) ...points];
  }

  var bezierQuads = getCubicBezierTuplesFromPoints(points);
  var currentNum = bezierQuads.length;
  var targetNum = currentNum + n;

  var repeatIndices = [
    for (var i in range(end: targetNum)) i * currentNum ~/ targetNum
  ];

  var splitFactors = [
    for (var i in range(end: currentNum))
      sum([for (var j in repeatIndices) i == j ? 1 : 0])
  ];

  var newPoints = <Vector3>[];

  for (var zipData in IterableZip([bezierQuads, splitFactors])) {
    var quad = zipData[0] as BezierTuple;
    var sf = zipData[1] as int;

    var alphas = linspace(start: 0, end: 1, count: sf + 1).getColumn(0);
    for (var a in IterableZip([alphas, withoutFirst(alphas)])) {
      newPoints.addAll(
          partialBezierPoints(quad.toList().cast<Vector3>(), a[0], a[1]));
    }
  }

  return newPoints;
}