Browse Source

src/extras/curves: move to es6 classes

Rawr 5 years ago
parent
commit
154d6f4691

+ 7 - 7
src/extras/curves/ArcCurve.js

@@ -1,17 +1,17 @@
 import { EllipseCurve } from './EllipseCurve.js';
 
-function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
+class ArcCurve extends EllipseCurve {
 
-	EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
+	constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
 
-	this.type = 'ArcCurve';
+		super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
 
-}
+		this.type = 'ArcCurve';
+		Object.defineProperty( this, 'isArcCurve', { value: true } );
 
-ArcCurve.prototype = Object.create( EllipseCurve.prototype );
-ArcCurve.prototype.constructor = ArcCurve;
+	}
 
-ArcCurve.prototype.isArcCurve = true;
+}
 
 
 export { ArcCurve };

+ 102 - 104
src/extras/curves/CatmullRomCurve3.js

@@ -81,173 +81,171 @@ function CubicPoly() {
 const tmp = new Vector3();
 const px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
 
-function CatmullRomCurve3( points, closed, curveType, tension ) {
+class CatmullRomCurve3 extends Curve {
 
-	Curve.call( this );
+	constructor( points, closed, curveType, tension ) {
 
-	this.type = 'CatmullRomCurve3';
+		super();
 
-	this.points = points || [];
-	this.closed = closed || false;
-	this.curveType = curveType || 'centripetal';
-	this.tension = ( tension !== undefined ) ? tension : 0.5;
+		this.type = 'CatmullRomCurve3';
+		Object.defineProperty( this, 'isCatmullRomCurve3', { value: true } );
 
-}
+		this.points = points || [];
+		this.closed = closed || false;
+		this.curveType = curveType || 'centripetal';
+		this.tension = ( tension !== undefined ) ? tension : 0.5;
 
-CatmullRomCurve3.prototype = Object.create( Curve.prototype );
-CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
+	}
+	getPoint( t, optionalTarget ) {
 
-CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
+		const point = optionalTarget || new Vector3();
 
-CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
+		const points = this.points;
+		const l = points.length;
 
-	const point = optionalTarget || new Vector3();
+		const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
+		let intPoint = Math.floor( p );
+		let weight = p - intPoint;
 
-	const points = this.points;
-	const l = points.length;
+		if ( this.closed ) {
 
-	const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
-	let intPoint = Math.floor( p );
-	let weight = p - intPoint;
+			intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
 
-	if ( this.closed ) {
+		} else if ( weight === 0 && intPoint === l - 1 ) {
 
-		intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
+			intPoint = l - 2;
+			weight = 1;
 
-	} else if ( weight === 0 && intPoint === l - 1 ) {
+		}
 
-		intPoint = l - 2;
-		weight = 1;
+		let p0, p3; // 4 points (p1 & p2 defined below)
 
-	}
+		if ( this.closed || intPoint > 0 ) {
 
-	let p0, p3; // 4 points (p1 & p2 defined below)
+			p0 = points[ ( intPoint - 1 ) % l ];
 
-	if ( this.closed || intPoint > 0 ) {
+		} else {
 
-		p0 = points[ ( intPoint - 1 ) % l ];
+			// extrapolate first point
+			tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
+			p0 = tmp;
 
-	} else {
+		}
 
-		// extrapolate first point
-		tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
-		p0 = tmp;
+		const p1 = points[ intPoint % l ];
+		const p2 = points[ ( intPoint + 1 ) % l ];
 
-	}
+		if ( this.closed || intPoint + 2 < l ) {
 
-	const p1 = points[ intPoint % l ];
-	const p2 = points[ ( intPoint + 1 ) % l ];
+			p3 = points[ ( intPoint + 2 ) % l ];
 
-	if ( this.closed || intPoint + 2 < l ) {
+		} else {
 
-		p3 = points[ ( intPoint + 2 ) % l ];
+			// extrapolate last point
+			tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
+			p3 = tmp;
 
-	} else {
+		}
 
-		// extrapolate last point
-		tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
-		p3 = tmp;
+		if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
 
-	}
+			// init Centripetal / Chordal Catmull-Rom
+			const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
+			let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
+			let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
+			let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
 
-	if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
+			// safety check for repeated points
+			if ( dt1 < 1e-4 )
+				dt1 = 1.0;
+			if ( dt0 < 1e-4 )
+				dt0 = dt1;
+			if ( dt2 < 1e-4 )
+				dt2 = dt1;
 
-		// init Centripetal / Chordal Catmull-Rom
-		const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
-		let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
-		let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
-		let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
+			px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
+			py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
+			pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
 
-		// safety check for repeated points
-		if ( dt1 < 1e-4 ) dt1 = 1.0;
-		if ( dt0 < 1e-4 ) dt0 = dt1;
-		if ( dt2 < 1e-4 ) dt2 = dt1;
+		} else if ( this.curveType === 'catmullrom' ) {
 
-		px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
-		py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
-		pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
+			px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
+			py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
+			pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
 
-	} else if ( this.curveType === 'catmullrom' ) {
+		}
 
-		px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
-		py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
-		pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
+		point.set(
+			px.calc( weight ),
+			py.calc( weight ),
+			pz.calc( weight )
+		);
 
-	}
+		return point;
 
-	point.set(
-		px.calc( weight ),
-		py.calc( weight ),
-		pz.calc( weight )
-	);
+	}
+	copy( source ) {
 
-	return point;
+		super.copy( source );
 
-};
+		this.points = [];
 
-CatmullRomCurve3.prototype.copy = function ( source ) {
+		for ( let i = 0, l = source.points.length; i < l; i ++ ) {
 
-	Curve.prototype.copy.call( this, source );
+			const point = source.points[ i ];
 
-	this.points = [];
+			this.points.push( point.clone() );
 
-	for ( let i = 0, l = source.points.length; i < l; i ++ ) {
+		}
 
-		const point = source.points[ i ];
+		this.closed = source.closed;
+		this.curveType = source.curveType;
+		this.tension = source.tension;
 
-		this.points.push( point.clone() );
+		return this;
 
 	}
+	toJSON() {
 
-	this.closed = source.closed;
-	this.curveType = source.curveType;
-	this.tension = source.tension;
-
-	return this;
+		const data = super.toJSON();
 
-};
+		data.points = [];
 
-CatmullRomCurve3.prototype.toJSON = function () {
+		for ( let i = 0, l = this.points.length; i < l; i ++ ) {
 
-	const data = Curve.prototype.toJSON.call( this );
+			const point = this.points[ i ];
+			data.points.push( point.toArray() );
 
-	data.points = [];
+		}
 
-	for ( let i = 0, l = this.points.length; i < l; i ++ ) {
+		data.closed = this.closed;
+		data.curveType = this.curveType;
+		data.tension = this.tension;
 
-		const point = this.points[ i ];
-		data.points.push( point.toArray() );
+		return data;
 
 	}
+	fromJSON( json ) {
 
-	data.closed = this.closed;
-	data.curveType = this.curveType;
-	data.tension = this.tension;
-
-	return data;
+		super.fromJSON( json );
 
-};
+		this.points = [];
 
-CatmullRomCurve3.prototype.fromJSON = function ( json ) {
+		for ( let i = 0, l = json.points.length; i < l; i ++ ) {
 
-	Curve.prototype.fromJSON.call( this, json );
+			const point = json.points[ i ];
+			this.points.push( new Vector3().fromArray( point ) );
 
-	this.points = [];
+		}
 
-	for ( let i = 0, l = json.points.length; i < l; i ++ ) {
+		this.closed = json.closed;
+		this.curveType = json.curveType;
+		this.tension = json.tension;
 
-		const point = json.points[ i ];
-		this.points.push( new Vector3().fromArray( point ) );
+		return this;
 
 	}
 
-	this.closed = json.closed;
-	this.curveType = json.curveType;
-	this.tension = json.tension;
-
-	return this;
-
-};
-
+}
 
 export { CatmullRomCurve3 };

+ 44 - 49
src/extras/curves/CubicBezierCurve.js

@@ -2,77 +2,72 @@ import { Curve } from '../core/Curve.js';
 import { CubicBezier } from '../core/Interpolations.js';
 import { Vector2 } from '../../math/Vector2.js';
 
-function CubicBezierCurve( v0, v1, v2, v3 ) {
+class CubicBezierCurve extends Curve {
 
-	Curve.call( this );
+	constructor( v0, v1, v2, v3 ) {
 
-	this.type = 'CubicBezierCurve';
+		super();
 
-	this.v0 = v0 || new Vector2();
-	this.v1 = v1 || new Vector2();
-	this.v2 = v2 || new Vector2();
-	this.v3 = v3 || new Vector2();
+		this.type = 'CubicBezierCurve';
+		Object.defineProperty( this, 'isCubicBezierCurve', { value: true } );
 
-}
-
-CubicBezierCurve.prototype = Object.create( Curve.prototype );
-CubicBezierCurve.prototype.constructor = CubicBezierCurve;
-
-CubicBezierCurve.prototype.isCubicBezierCurve = true;
-
-CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
+		this.v0 = v0 || new Vector2();
+		this.v1 = v1 || new Vector2();
+		this.v2 = v2 || new Vector2();
+		this.v3 = v3 || new Vector2();
 
-	const point = optionalTarget || new Vector2();
+	}
+	getPoint( t, optionalTarget ) {
 
-	const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
+		const point = optionalTarget || new Vector2();
 
-	point.set(
-		CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
-		CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
-	);
+		const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
 
-	return point;
+		point.set(
+			CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
+			CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
+		);
 
-};
+		return point;
 
-CubicBezierCurve.prototype.copy = function ( source ) {
+	}
+	copy( source ) {
 
-	Curve.prototype.copy.call( this, source );
+		super.copy( source );
 
-	this.v0.copy( source.v0 );
-	this.v1.copy( source.v1 );
-	this.v2.copy( source.v2 );
-	this.v3.copy( source.v3 );
+		this.v0.copy( source.v0 );
+		this.v1.copy( source.v1 );
+		this.v2.copy( source.v2 );
+		this.v3.copy( source.v3 );
 
-	return this;
+		return this;
 
-};
+	}
+	toJSON() {
 
-CubicBezierCurve.prototype.toJSON = function () {
+		const data = super.toJSON();
 
-	const data = Curve.prototype.toJSON.call( this );
+		data.v0 = this.v0.toArray();
+		data.v1 = this.v1.toArray();
+		data.v2 = this.v2.toArray();
+		data.v3 = this.v3.toArray();
 
-	data.v0 = this.v0.toArray();
-	data.v1 = this.v1.toArray();
-	data.v2 = this.v2.toArray();
-	data.v3 = this.v3.toArray();
+		return data;
 
-	return data;
+	}
+	fromJSON( json ) {
 
-};
+		super.fromJSON( json );
 
-CubicBezierCurve.prototype.fromJSON = function ( json ) {
+		this.v0.fromArray( json.v0 );
+		this.v1.fromArray( json.v1 );
+		this.v2.fromArray( json.v2 );
+		this.v3.fromArray( json.v3 );
 
-	Curve.prototype.fromJSON.call( this, json );
+		return this;
 
-	this.v0.fromArray( json.v0 );
-	this.v1.fromArray( json.v1 );
-	this.v2.fromArray( json.v2 );
-	this.v3.fromArray( json.v3 );
-
-	return this;
-
-};
+	}
 
+}
 
 export { CubicBezierCurve };

+ 45 - 50
src/extras/curves/CubicBezierCurve3.js

@@ -2,78 +2,73 @@ import { Curve } from '../core/Curve.js';
 import { CubicBezier } from '../core/Interpolations.js';
 import { Vector3 } from '../../math/Vector3.js';
 
-function CubicBezierCurve3( v0, v1, v2, v3 ) {
+class CubicBezierCurve3 extends Curve {
 
-	Curve.call( this );
+	constructor( v0, v1, v2, v3 ) {
 
-	this.type = 'CubicBezierCurve3';
+		super();
 
-	this.v0 = v0 || new Vector3();
-	this.v1 = v1 || new Vector3();
-	this.v2 = v2 || new Vector3();
-	this.v3 = v3 || new Vector3();
+		this.type = 'CubicBezierCurve3';
+		Object.defineProperty( this, 'isCubicBezierCurve3', { value: true } );
 
-}
-
-CubicBezierCurve3.prototype = Object.create( Curve.prototype );
-CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
-
-CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
-
-CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
+		this.v0 = v0 || new Vector3();
+		this.v1 = v1 || new Vector3();
+		this.v2 = v2 || new Vector3();
+		this.v3 = v3 || new Vector3();
 
-	const point = optionalTarget || new Vector3();
+	}
+	getPoint( t, optionalTarget ) {
 
-	const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
+		const point = optionalTarget || new Vector3();
 
-	point.set(
-		CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
-		CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
-		CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
-	);
+		const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
 
-	return point;
+		point.set(
+			CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
+			CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
+			CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
+		);
 
-};
+		return point;
 
-CubicBezierCurve3.prototype.copy = function ( source ) {
+	}
+	copy( source ) {
 
-	Curve.prototype.copy.call( this, source );
+		super.copy( source );
 
-	this.v0.copy( source.v0 );
-	this.v1.copy( source.v1 );
-	this.v2.copy( source.v2 );
-	this.v3.copy( source.v3 );
+		this.v0.copy( source.v0 );
+		this.v1.copy( source.v1 );
+		this.v2.copy( source.v2 );
+		this.v3.copy( source.v3 );
 
-	return this;
+		return this;
 
-};
+	}
+	toJSON() {
 
-CubicBezierCurve3.prototype.toJSON = function () {
+		const data = super.toJSON();
 
-	const data = Curve.prototype.toJSON.call( this );
+		data.v0 = this.v0.toArray();
+		data.v1 = this.v1.toArray();
+		data.v2 = this.v2.toArray();
+		data.v3 = this.v3.toArray();
 
-	data.v0 = this.v0.toArray();
-	data.v1 = this.v1.toArray();
-	data.v2 = this.v2.toArray();
-	data.v3 = this.v3.toArray();
+		return data;
 
-	return data;
+	}
+	fromJSON( json ) {
 
-};
+		super.fromJSON( json );
 
-CubicBezierCurve3.prototype.fromJSON = function ( json ) {
+		this.v0.fromArray( json.v0 );
+		this.v1.fromArray( json.v1 );
+		this.v2.fromArray( json.v2 );
+		this.v3.fromArray( json.v3 );
 
-	Curve.prototype.fromJSON.call( this, json );
+		return this;
 
-	this.v0.fromArray( json.v0 );
-	this.v1.fromArray( json.v1 );
-	this.v2.fromArray( json.v2 );
-	this.v3.fromArray( json.v3 );
-
-	return this;
-
-};
+	}
 
+}
 
 export { CubicBezierCurve3 };

+ 87 - 91
src/extras/curves/EllipseCurve.js

@@ -1,157 +1,153 @@
 import { Curve } from '../core/Curve.js';
 import { Vector2 } from '../../math/Vector2.js';
 
-function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
+class EllipseCurve extends Curve {
 
-	Curve.call( this );
+	constructor( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
 
-	this.type = 'EllipseCurve';
+		super();
 
-	this.aX = aX || 0;
-	this.aY = aY || 0;
+		this.type = 'EllipseCurve';
+		Object.defineProperty( this, 'isEllipseCurve', { value: true } );
 
-	this.xRadius = xRadius || 1;
-	this.yRadius = yRadius || 1;
+		this.aX = aX || 0;
+		this.aY = aY || 0;
 
-	this.aStartAngle = aStartAngle || 0;
-	this.aEndAngle = aEndAngle || 2 * Math.PI;
+		this.xRadius = xRadius || 1;
+		this.yRadius = yRadius || 1;
 
-	this.aClockwise = aClockwise || false;
+		this.aStartAngle = aStartAngle || 0;
+		this.aEndAngle = aEndAngle || 2 * Math.PI;
 
-	this.aRotation = aRotation || 0;
+		this.aClockwise = aClockwise || false;
 
-}
-
-EllipseCurve.prototype = Object.create( Curve.prototype );
-EllipseCurve.prototype.constructor = EllipseCurve;
+		this.aRotation = aRotation || 0;
 
-EllipseCurve.prototype.isEllipseCurve = true;
+	}
+	getPoint( t, optionalTarget ) {
 
-EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
+		const point = optionalTarget || new Vector2();
 
-	const point = optionalTarget || new Vector2();
+		const twoPi = Math.PI * 2;
+		let deltaAngle = this.aEndAngle - this.aStartAngle;
+		const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
 
-	const twoPi = Math.PI * 2;
-	let deltaAngle = this.aEndAngle - this.aStartAngle;
-	const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
+		// ensures that deltaAngle is 0 .. 2 PI
+		while ( deltaAngle < 0 )
+			deltaAngle += twoPi;
+		while ( deltaAngle > twoPi )
+			deltaAngle -= twoPi;
 
-	// ensures that deltaAngle is 0 .. 2 PI
-	while ( deltaAngle < 0 ) deltaAngle += twoPi;
-	while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
+		if ( deltaAngle < Number.EPSILON ) {
 
-	if ( deltaAngle < Number.EPSILON ) {
+			if ( samePoints ) {
 
-		if ( samePoints ) {
+				deltaAngle = 0;
 
-			deltaAngle = 0;
+			} else {
 
-		} else {
+				deltaAngle = twoPi;
 
-			deltaAngle = twoPi;
+			}
 
 		}
 
-	}
+		if ( this.aClockwise === true && ! samePoints ) {
 
-	if ( this.aClockwise === true && ! samePoints ) {
+			if ( deltaAngle === twoPi ) {
 
-		if ( deltaAngle === twoPi ) {
+				deltaAngle = - twoPi;
 
-			deltaAngle = - twoPi;
+			} else {
 
-		} else {
+				deltaAngle = deltaAngle - twoPi;
 
-			deltaAngle = deltaAngle - twoPi;
+			}
 
 		}
 
-	}
+		const angle = this.aStartAngle + t * deltaAngle;
+		let x = this.aX + this.xRadius * Math.cos( angle );
+		let y = this.aY + this.yRadius * Math.sin( angle );
 
-	const angle = this.aStartAngle + t * deltaAngle;
-	let x = this.aX + this.xRadius * Math.cos( angle );
-	let y = this.aY + this.yRadius * Math.sin( angle );
+		if ( this.aRotation !== 0 ) {
 
-	if ( this.aRotation !== 0 ) {
+			const cos = Math.cos( this.aRotation );
+			const sin = Math.sin( this.aRotation );
 
-		const cos = Math.cos( this.aRotation );
-		const sin = Math.sin( this.aRotation );
-
-		const tx = x - this.aX;
-		const ty = y - this.aY;
-
-		// Rotate the point about the center of the ellipse.
-		x = tx * cos - ty * sin + this.aX;
-		y = tx * sin + ty * cos + this.aY;
-
-	}
+			const tx = x - this.aX;
+			const ty = y - this.aY;
 
-	return point.set( x, y );
+			// Rotate the point about the center of the ellipse.
+			x = tx * cos - ty * sin + this.aX;
+			y = tx * sin + ty * cos + this.aY;
 
-};
-
-EllipseCurve.prototype.copy = function ( source ) {
-
-	Curve.prototype.copy.call( this, source );
+		}
 
-	this.aX = source.aX;
-	this.aY = source.aY;
+		return point.set( x, y );
 
-	this.xRadius = source.xRadius;
-	this.yRadius = source.yRadius;
+	}
+	copy( source ) {
 
-	this.aStartAngle = source.aStartAngle;
-	this.aEndAngle = source.aEndAngle;
+		super.copy( source );
 
-	this.aClockwise = source.aClockwise;
+		this.aX = source.aX;
+		this.aY = source.aY;
 
-	this.aRotation = source.aRotation;
+		this.xRadius = source.xRadius;
+		this.yRadius = source.yRadius;
 
-	return this;
+		this.aStartAngle = source.aStartAngle;
+		this.aEndAngle = source.aEndAngle;
 
-};
+		this.aClockwise = source.aClockwise;
 
+		this.aRotation = source.aRotation;
 
-EllipseCurve.prototype.toJSON = function () {
+		return this;
 
-	const data = Curve.prototype.toJSON.call( this );
+	}
+	toJSON() {
 
-	data.aX = this.aX;
-	data.aY = this.aY;
+		const data = super.toJSON();
 
-	data.xRadius = this.xRadius;
-	data.yRadius = this.yRadius;
+		data.aX = this.aX;
+		data.aY = this.aY;
 
-	data.aStartAngle = this.aStartAngle;
-	data.aEndAngle = this.aEndAngle;
+		data.xRadius = this.xRadius;
+		data.yRadius = this.yRadius;
 
-	data.aClockwise = this.aClockwise;
+		data.aStartAngle = this.aStartAngle;
+		data.aEndAngle = this.aEndAngle;
 
-	data.aRotation = this.aRotation;
+		data.aClockwise = this.aClockwise;
 
-	return data;
+		data.aRotation = this.aRotation;
 
-};
+		return data;
 
-EllipseCurve.prototype.fromJSON = function ( json ) {
+	}
+	fromJSON( json ) {
 
-	Curve.prototype.fromJSON.call( this, json );
+		super.fromJSON( json );
 
-	this.aX = json.aX;
-	this.aY = json.aY;
+		this.aX = json.aX;
+		this.aY = json.aY;
 
-	this.xRadius = json.xRadius;
-	this.yRadius = json.yRadius;
+		this.xRadius = json.xRadius;
+		this.yRadius = json.yRadius;
 
-	this.aStartAngle = json.aStartAngle;
-	this.aEndAngle = json.aEndAngle;
+		this.aStartAngle = json.aStartAngle;
+		this.aEndAngle = json.aEndAngle;
 
-	this.aClockwise = json.aClockwise;
+		this.aClockwise = json.aClockwise;
 
-	this.aRotation = json.aRotation;
+		this.aRotation = json.aRotation;
 
-	return this;
+		return this;
 
-};
+	}
 
+}
 
 export { EllipseCurve };

+ 45 - 53
src/extras/curves/LineCurve.js

@@ -1,91 +1,83 @@
 import { Vector2 } from '../../math/Vector2.js';
 import { Curve } from '../core/Curve.js';
 
-function LineCurve( v1, v2 ) {
+class LineCurve {
 
-	Curve.call( this );
+	constructor( v1, v2 ) {
 
-	this.type = 'LineCurve';
+		super();
 
-	this.v1 = v1 || new Vector2();
-	this.v2 = v2 || new Vector2();
+		this.type = 'LineCurve';
+		Object.defineProperty( this, 'isLineCurve', { value: true } );
 
-}
-
-LineCurve.prototype = Object.create( Curve.prototype );
-LineCurve.prototype.constructor = LineCurve;
-
-LineCurve.prototype.isLineCurve = true;
-
-LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
-
-	const point = optionalTarget || new Vector2();
-
-	if ( t === 1 ) {
-
-		point.copy( this.v2 );
-
-	} else {
-
-		point.copy( this.v2 ).sub( this.v1 );
-		point.multiplyScalar( t ).add( this.v1 );
+		this.v1 = v1 || new Vector2();
+		this.v2 = v2 || new Vector2();
 
 	}
+	getPoint( t, optionalTarget ) {
 
-	return point;
+		const point = optionalTarget || new Vector2();
 
-};
+		if ( t === 1 ) {
 
-// Line curve is linear, so we can overwrite default getPointAt
+			point.copy( this.v2 );
 
-LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
+		} else {
 
-	return this.getPoint( u, optionalTarget );
+			point.copy( this.v2 ).sub( this.v1 );
+			point.multiplyScalar( t ).add( this.v1 );
 
-};
+		}
 
-LineCurve.prototype.getTangent = function ( t, optionalTarget ) {
+		return point;
 
-	const tangent = optionalTarget || new Vector2();
+	}
+	// Line curve is linear, so we can overwrite default getPointAt
+	getPointAt( u, optionalTarget ) {
 
-	tangent.copy( this.v2 ).sub( this.v1 ).normalize();
+		return this.getPoint( u, optionalTarget );
 
-	return tangent;
+	}
+	getTangent( t, optionalTarget ) {
 
-};
+		const tangent = optionalTarget || new Vector2();
 
-LineCurve.prototype.copy = function ( source ) {
+		tangent.copy( this.v2 ).sub( this.v1 ).normalize();
 
-	Curve.prototype.copy.call( this, source );
+		return tangent;
 
-	this.v1.copy( source.v1 );
-	this.v2.copy( source.v2 );
+	}
+	copy( source ) {
 
-	return this;
+		super.copy( source );
 
-};
+		this.v1.copy( source.v1 );
+		this.v2.copy( source.v2 );
 
-LineCurve.prototype.toJSON = function () {
+		return this;
 
-	const data = Curve.prototype.toJSON.call( this );
+	}
+	toJSON() {
 
-	data.v1 = this.v1.toArray();
-	data.v2 = this.v2.toArray();
+		const data = super.toJSON();
 
-	return data;
+		data.v1 = this.v1.toArray();
+		data.v2 = this.v2.toArray();
 
-};
+		return data;
 
-LineCurve.prototype.fromJSON = function ( json ) {
+	}
+	fromJSON( json ) {
 
-	Curve.prototype.fromJSON.call( this, json );
+		super.fromJSON( json );
 
-	this.v1.fromArray( json.v1 );
-	this.v2.fromArray( json.v2 );
+		this.v1.fromArray( json.v1 );
+		this.v2.fromArray( json.v2 );
 
-	return this;
+		return this;
 
-};
+	}
 
+}
 
 export { LineCurve };

+ 40 - 47
src/extras/curves/LineCurve3.js

@@ -1,81 +1,74 @@
 import { Vector3 } from '../../math/Vector3.js';
 import { Curve } from '../core/Curve.js';
 
-function LineCurve3( v1, v2 ) {
+class LineCurve3 extends Curve {
 
-	Curve.call( this );
+	constructor( v1, v2 ) {
 
-	this.type = 'LineCurve3';
+		super();
 
-	this.v1 = v1 || new Vector3();
-	this.v2 = v2 || new Vector3();
+		this.type = 'LineCurve3';
+		Object.defineProperty( this, 'isLineCurve3', { value: true } );
 
-}
+		this.v1 = v1 || new Vector3();
+		this.v2 = v2 || new Vector3();
 
-LineCurve3.prototype = Object.create( Curve.prototype );
-LineCurve3.prototype.constructor = LineCurve3;
+	}
+	getPoint( t, optionalTarget ) {
 
-LineCurve3.prototype.isLineCurve3 = true;
+		const point = optionalTarget || new Vector3();
 
-LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
+		if ( t === 1 ) {
 
-	const point = optionalTarget || new Vector3();
+			point.copy( this.v2 );
 
-	if ( t === 1 ) {
+		} else {
 
-		point.copy( this.v2 );
+			point.copy( this.v2 ).sub( this.v1 );
+			point.multiplyScalar( t ).add( this.v1 );
 
-	} else {
+		}
 
-		point.copy( this.v2 ).sub( this.v1 );
-		point.multiplyScalar( t ).add( this.v1 );
+		return point;
 
 	}
+	// Line curve is linear, so we can overwrite default getPointAt
+	getPointAt( u, optionalTarget ) {
 
-	return point;
-
-};
-
-// Line curve is linear, so we can overwrite default getPointAt
-
-LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
-
-	return this.getPoint( u, optionalTarget );
-
-};
+		return this.getPoint( u, optionalTarget );
 
-LineCurve3.prototype.copy = function ( source ) {
-
-	Curve.prototype.copy.call( this, source );
-
-	this.v1.copy( source.v1 );
-	this.v2.copy( source.v2 );
+	}
+	copy( source ) {
 
-	return this;
+		super.copy( source );
 
-};
+		this.v1.copy( source.v1 );
+		this.v2.copy( source.v2 );
 
-LineCurve3.prototype.toJSON = function () {
+		return this;
 
-	const data = Curve.prototype.toJSON.call( this );
+	}
+	toJSON() {
 
-	data.v1 = this.v1.toArray();
-	data.v2 = this.v2.toArray();
+		const data = super.toJSON();
 
-	return data;
+		data.v1 = this.v1.toArray();
+		data.v2 = this.v2.toArray();
 
-};
+		return data;
 
-LineCurve3.prototype.fromJSON = function ( json ) {
+	}
+	fromJSON( json ) {
 
-	Curve.prototype.fromJSON.call( this, json );
+		super.fromJSON( json );
 
-	this.v1.fromArray( json.v1 );
-	this.v2.fromArray( json.v2 );
+		this.v1.fromArray( json.v1 );
+		this.v2.fromArray( json.v2 );
 
-	return this;
+		return this;
 
-};
+	}
 
+}
 
 export { LineCurve3 };

+ 40 - 45
src/extras/curves/QuadraticBezierCurve.js

@@ -2,73 +2,68 @@ import { Curve } from '../core/Curve.js';
 import { QuadraticBezier } from '../core/Interpolations.js';
 import { Vector2 } from '../../math/Vector2.js';
 
-function QuadraticBezierCurve( v0, v1, v2 ) {
+class QuadraticBezierCurve extends Curve {
 
-	Curve.call( this );
+	constructor( v0, v1, v2 ) {
 
-	this.type = 'QuadraticBezierCurve';
+		super();
 
-	this.v0 = v0 || new Vector2();
-	this.v1 = v1 || new Vector2();
-	this.v2 = v2 || new Vector2();
+		this.type = 'QuadraticBezierCurve';
+		Object.defineProperty( this, 'isQuadraticBezierCurve', { value: true } );
 
-}
-
-QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
-QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
-
-QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
-
-QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
+		this.v0 = v0 || new Vector2();
+		this.v1 = v1 || new Vector2();
+		this.v2 = v2 || new Vector2();
 
-	const point = optionalTarget || new Vector2();
+	}
+	getPoint( t, optionalTarget ) {
 
-	const v0 = this.v0, v1 = this.v1, v2 = this.v2;
+		const point = optionalTarget || new Vector2();
 
-	point.set(
-		QuadraticBezier( t, v0.x, v1.x, v2.x ),
-		QuadraticBezier( t, v0.y, v1.y, v2.y )
-	);
+		const v0 = this.v0, v1 = this.v1, v2 = this.v2;
 
-	return point;
+		point.set(
+			QuadraticBezier( t, v0.x, v1.x, v2.x ),
+			QuadraticBezier( t, v0.y, v1.y, v2.y )
+		);
 
-};
+		return point;
 
-QuadraticBezierCurve.prototype.copy = function ( source ) {
+	}
+	copy( source ) {
 
-	Curve.prototype.copy.call( this, source );
+		super.copy( source );
 
-	this.v0.copy( source.v0 );
-	this.v1.copy( source.v1 );
-	this.v2.copy( source.v2 );
+		this.v0.copy( source.v0 );
+		this.v1.copy( source.v1 );
+		this.v2.copy( source.v2 );
 
-	return this;
+		return this;
 
-};
+	}
+	toJSON() {
 
-QuadraticBezierCurve.prototype.toJSON = function () {
+		const data = super.toJSON();
 
-	const data = Curve.prototype.toJSON.call( this );
+		data.v0 = this.v0.toArray();
+		data.v1 = this.v1.toArray();
+		data.v2 = this.v2.toArray();
 
-	data.v0 = this.v0.toArray();
-	data.v1 = this.v1.toArray();
-	data.v2 = this.v2.toArray();
+		return data;
 
-	return data;
+	}
+	fromJSON( json ) {
 
-};
+		super.fromJSON( json );
 
-QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
+		this.v0.fromArray( json.v0 );
+		this.v1.fromArray( json.v1 );
+		this.v2.fromArray( json.v2 );
 
-	Curve.prototype.fromJSON.call( this, json );
+		return this;
 
-	this.v0.fromArray( json.v0 );
-	this.v1.fromArray( json.v1 );
-	this.v2.fromArray( json.v2 );
-
-	return this;
-
-};
+	}
 
+}
 
 export { QuadraticBezierCurve };

+ 41 - 46
src/extras/curves/QuadraticBezierCurve3.js

@@ -2,74 +2,69 @@ import { Curve } from '../core/Curve.js';
 import { QuadraticBezier } from '../core/Interpolations.js';
 import { Vector3 } from '../../math/Vector3.js';
 
-function QuadraticBezierCurve3( v0, v1, v2 ) {
+class QuadraticBezierCurve3 extends Curve {
 
-	Curve.call( this );
+	constructor( v0, v1, v2 ) {
 
-	this.type = 'QuadraticBezierCurve3';
+		super();
 
-	this.v0 = v0 || new Vector3();
-	this.v1 = v1 || new Vector3();
-	this.v2 = v2 || new Vector3();
+		this.type = 'QuadraticBezierCurve3';
+		Object.defineProperty( this, 'isQuadraticBezierCurve3', { value: true } );
 
-}
-
-QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
-QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
-
-QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
-
-QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
+		this.v0 = v0 || new Vector3();
+		this.v1 = v1 || new Vector3();
+		this.v2 = v2 || new Vector3();
 
-	const point = optionalTarget || new Vector3();
+	}
+	getPoint( t, optionalTarget ) {
 
-	const v0 = this.v0, v1 = this.v1, v2 = this.v2;
+		const point = optionalTarget || new Vector3();
 
-	point.set(
-		QuadraticBezier( t, v0.x, v1.x, v2.x ),
-		QuadraticBezier( t, v0.y, v1.y, v2.y ),
-		QuadraticBezier( t, v0.z, v1.z, v2.z )
-	);
+		const v0 = this.v0, v1 = this.v1, v2 = this.v2;
 
-	return point;
+		point.set(
+			QuadraticBezier( t, v0.x, v1.x, v2.x ),
+			QuadraticBezier( t, v0.y, v1.y, v2.y ),
+			QuadraticBezier( t, v0.z, v1.z, v2.z )
+		);
 
-};
+		return point;
 
-QuadraticBezierCurve3.prototype.copy = function ( source ) {
+	}
+	copy( source ) {
 
-	Curve.prototype.copy.call( this, source );
+		super.copy( source );
 
-	this.v0.copy( source.v0 );
-	this.v1.copy( source.v1 );
-	this.v2.copy( source.v2 );
+		this.v0.copy( source.v0 );
+		this.v1.copy( source.v1 );
+		this.v2.copy( source.v2 );
 
-	return this;
+		return this;
 
-};
+	}
+	toJSON() {
 
-QuadraticBezierCurve3.prototype.toJSON = function () {
+		const data = super.toJSON();
 
-	const data = Curve.prototype.toJSON.call( this );
+		data.v0 = this.v0.toArray();
+		data.v1 = this.v1.toArray();
+		data.v2 = this.v2.toArray();
 
-	data.v0 = this.v0.toArray();
-	data.v1 = this.v1.toArray();
-	data.v2 = this.v2.toArray();
+		return data;
 
-	return data;
+	}
+	fromJSON( json ) {
 
-};
+		super.fromJSON( json );
 
-QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
+		this.v0.fromArray( json.v0 );
+		this.v1.fromArray( json.v1 );
+		this.v2.fromArray( json.v2 );
 
-	Curve.prototype.fromJSON.call( this, json );
+		return this;
 
-	this.v0.fromArray( json.v0 );
-	this.v1.fromArray( json.v1 );
-	this.v2.fromArray( json.v2 );
-
-	return this;
-
-};
+	}
 
+}
 
 export { QuadraticBezierCurve3 };

+ 48 - 53
src/extras/curves/SplineCurve.js

@@ -2,96 +2,91 @@ import { Curve } from '../core/Curve.js';
 import { CatmullRom } from '../core/Interpolations.js';
 import { Vector2 } from '../../math/Vector2.js';
 
-function SplineCurve( points ) {
+class SplineCurve extends Curve {
 
-	Curve.call( this );
+	constructor( points ) {
 
-	this.type = 'SplineCurve';
+		super();
 
-	this.points = points || [];
+		this.type = 'SplineCurve';
+		Object.defineProperty( this, 'isSplineCurve', { value: true } );
 
-}
-
-SplineCurve.prototype = Object.create( Curve.prototype );
-SplineCurve.prototype.constructor = SplineCurve;
+		this.points = points || [];
 
-SplineCurve.prototype.isSplineCurve = true;
+	}
+	getPoint( t, optionalTarget ) {
 
-SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
+		const point = optionalTarget || new Vector2();
 
-	const point = optionalTarget || new Vector2();
+		const points = this.points;
+		const p = ( points.length - 1 ) * t;
 
-	const points = this.points;
-	const p = ( points.length - 1 ) * t;
+		const intPoint = Math.floor( p );
+		const weight = p - intPoint;
 
-	const intPoint = Math.floor( p );
-	const weight = p - intPoint;
+		const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
+		const p1 = points[ intPoint ];
+		const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
+		const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
 
-	const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
-	const p1 = points[ intPoint ];
-	const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
-	const 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 )
+		);
 
-	point.set(
-		CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
-		CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
-	);
+		return point;
 
-	return point;
+	}
+	copy( source ) {
 
-};
+		Curve.prototype.copy.call( this, source );
 
-SplineCurve.prototype.copy = function ( source ) {
+		this.points = [];
 
-	Curve.prototype.copy.call( this, source );
+		for ( let i = 0, l = source.points.length; i < l; i ++ ) {
 
-	this.points = [];
+			const point = source.points[ i ];
 
-	for ( let i = 0, l = source.points.length; i < l; i ++ ) {
+			this.points.push( point.clone() );
 
-		const point = source.points[ i ];
+		}
 
-		this.points.push( point.clone() );
+		return this;
 
 	}
+	toJSON() {
 
-	return this;
-
-};
+		const data = Curve.prototype.toJSON.call( this );
 
-SplineCurve.prototype.toJSON = function () {
+		data.points = [];
 
-	const data = Curve.prototype.toJSON.call( this );
+		for ( let i = 0, l = this.points.length; i < l; i ++ ) {
 
-	data.points = [];
+			const point = this.points[ i ];
+			data.points.push( point.toArray() );
 
-	for ( let i = 0, l = this.points.length; i < l; i ++ ) {
+		}
 
-		const point = this.points[ i ];
-		data.points.push( point.toArray() );
+		return data;
 
 	}
+	fromJSON( json ) {
 
-	return data;
+		Curve.prototype.fromJSON.call( this, json );
 
-};
+		this.points = [];
 
-SplineCurve.prototype.fromJSON = function ( json ) {
+		for ( let i = 0, l = json.points.length; i < l; i ++ ) {
 
-	Curve.prototype.fromJSON.call( this, json );
+			const point = json.points[ i ];
+			this.points.push( new Vector2().fromArray( point ) );
 
-	this.points = [];
+		}
 
-	for ( let i = 0, l = json.points.length; i < l; i ++ ) {
-
-		const point = json.points[ i ];
-		this.points.push( new Vector2().fromArray( point ) );
+		return this;
 
 	}
 
-	return this;
-
-};
-
+}
 
 export { SplineCurve };