|
@@ -6,27 +6,24 @@ import { CubicBezierCurve } from '../curves/CubicBezierCurve.js';
|
|
|
import { QuadraticBezierCurve } from '../curves/QuadraticBezierCurve.js';
|
|
|
import { LineCurve } from '../curves/LineCurve.js';
|
|
|
|
|
|
-function Path( points ) {
|
|
|
+class Path extends CurvePath {
|
|
|
|
|
|
- CurvePath.call( this );
|
|
|
+ constructor( points ) {
|
|
|
|
|
|
- this.type = 'Path';
|
|
|
+ super();
|
|
|
+ this.type = 'Path';
|
|
|
|
|
|
- this.currentPoint = new Vector2();
|
|
|
+ this.currentPoint = new Vector2();
|
|
|
|
|
|
- if ( points ) {
|
|
|
+ if ( points ) {
|
|
|
|
|
|
- this.setFromPoints( points );
|
|
|
+ this.setFromPoints( points );
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
+ }
|
|
|
|
|
|
- constructor: Path,
|
|
|
+ }
|
|
|
|
|
|
- setFromPoints: function ( points ) {
|
|
|
+ setFromPoints( points ) {
|
|
|
|
|
|
this.moveTo( points[ 0 ].x, points[ 0 ].y );
|
|
|
|
|
@@ -38,17 +35,17 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- moveTo: function ( x, y ) {
|
|
|
+ moveTo( x, y ) {
|
|
|
|
|
|
this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- lineTo: function ( x, y ) {
|
|
|
+ lineTo( x, y ) {
|
|
|
|
|
|
const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
|
|
|
this.curves.push( curve );
|
|
@@ -57,9 +54,9 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
|
|
|
+ quadraticCurveTo( aCPx, aCPy, aX, aY ) {
|
|
|
|
|
|
const curve = new QuadraticBezierCurve(
|
|
|
this.currentPoint.clone(),
|
|
@@ -73,9 +70,9 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
|
|
+ bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
|
|
|
|
|
const curve = new CubicBezierCurve(
|
|
|
this.currentPoint.clone(),
|
|
@@ -90,9 +87,9 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- splineThru: function ( pts /*Array of Vector*/ ) {
|
|
|
+ splineThru( pts /*Array of Vector*/ ) {
|
|
|
|
|
|
const npts = [ this.currentPoint.clone() ].concat( pts );
|
|
|
|
|
@@ -103,9 +100,9 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
|
|
+ arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
|
|
|
|
|
const x0 = this.currentPoint.x;
|
|
|
const y0 = this.currentPoint.y;
|
|
@@ -115,17 +112,17 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
|
|
+ absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
|
|
|
|
|
this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
+ ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
|
|
|
const x0 = this.currentPoint.x;
|
|
|
const y0 = this.currentPoint.y;
|
|
@@ -134,9 +131,9 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
+ absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
|
|
|
|
|
const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
|
|
|
|
|
@@ -160,31 +157,31 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( source ) {
|
|
|
+ copy( source ) {
|
|
|
|
|
|
- CurvePath.prototype.copy.call( this, source );
|
|
|
+ super.copy( source );
|
|
|
|
|
|
this.currentPoint.copy( source.currentPoint );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toJSON: function () {
|
|
|
+ toJSON() {
|
|
|
|
|
|
- const data = CurvePath.prototype.toJSON.call( this );
|
|
|
+ const data = super.toJSON( );
|
|
|
|
|
|
data.currentPoint = this.currentPoint.toArray();
|
|
|
|
|
|
return data;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fromJSON: function ( json ) {
|
|
|
+ fromJSON( json ) {
|
|
|
|
|
|
- CurvePath.prototype.fromJSON.call( this, json );
|
|
|
+ super.fromJSON( json );
|
|
|
|
|
|
this.currentPoint.fromArray( json.currentPoint );
|
|
|
|
|
@@ -192,7 +189,7 @@ Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
|
|
|
|
|
|
export { Path };
|