getPoint method

  1. @override
dynamic getPoint(
  1. num t,
  2. dynamic optionalTarget
)
override

Implementation

@override
getPoint(num t, optionalTarget) {
  var point = optionalTarget ?? Vector2(null, null);

  var points = this.points;
  num p = (points.length - 1) * t;

  var intPoint = Math.floor(p).toInt();
  var weight = p - intPoint;

  var p0 = points[intPoint == 0 ? intPoint : intPoint - 1];
  var p1 = points[intPoint];
  var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];

  point.set(
    catmullRom(weight, p0.x, p1.x, p2.x, p3.x),
    catmullRom(weight, p0.y, p1.y, p2.y, p3.y),
  );

  return point;
}