CubicBezierCurve.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Curve } from '../core/Curve.js';
  2. import { CubicBezier } from '../core/Interpolations.js';
  3. import { Vector2 } from '../../math/Vector2.js';
  4. function CubicBezierCurve( v0, v1, v2, v3 ) {
  5. Curve.call( this );
  6. this.type = 'CubicBezierCurve';
  7. this.v0 = v0 || new Vector2();
  8. this.v1 = v1 || new Vector2();
  9. this.v2 = v2 || new Vector2();
  10. this.v3 = v3 || new Vector2();
  11. }
  12. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  13. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  14. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  15. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  16. var point = optionalTarget || new Vector2();
  17. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  18. point.set(
  19. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  20. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21. );
  22. return point;
  23. };
  24. CubicBezierCurve.prototype.copy = function ( source ) {
  25. Curve.prototype.copy.call( this, source );
  26. this.v0.copy( source.v0 );
  27. this.v1.copy( source.v1 );
  28. this.v2.copy( source.v2 );
  29. this.v3.copy( source.v3 );
  30. return this;
  31. };
  32. export { CubicBezierCurve };