1 import { Curve } from '../core/Curve';
2 import { CatmullRom } from '../core/Interpolations';
3 import { Vector2 } from '../../math/Vector2';
6 function SplineCurve( points /* array of Vector2 */ ) {
10 this.points = ( points === undefined ) ? [] : points;
14 SplineCurve.prototype = Object.create( Curve.prototype );
15 SplineCurve.prototype.constructor = SplineCurve;
17 SplineCurve.prototype.isSplineCurve = true;
19 SplineCurve.prototype.getPoint = function ( t ) {
21 var points = this.points;
22 var point = ( points.length - 1 ) * t;
24 var intPoint = Math.floor( point );
25 var weight = point - intPoint;
27 var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
28 var point1 = points[ intPoint ];
29 var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
30 var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
33 CatmullRom( weight, point0.x, point1.x, point2.x, point3.x ),
34 CatmullRom( weight, point0.y, point1.y, point2.y, point3.y )
39 export { SplineCurve };