Spaces:
Running
Running
File size: 1,531 Bytes
6cd9596 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
import { Vector2 } from '../../math/Vector2.js';
import { Curve } from '../core/Curve.js';
function LineCurve( v1, v2 ) {
Curve.call( this );
this.type = 'LineCurve';
this.v1 = v1 || new Vector2();
this.v2 = v2 || new Vector2();
}
LineCurve.prototype = Object.create( Curve.prototype );
LineCurve.prototype.constructor = LineCurve;
LineCurve.prototype.isLineCurve = true;
LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
var 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 );
}
return point;
};
// Line curve is linear, so we can overwrite default getPointAt
LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
return this.getPoint( u, optionalTarget );
};
LineCurve.prototype.getTangent = function ( /* t */ ) {
var tangent = this.v2.clone().sub( this.v1 );
return tangent.normalize();
};
LineCurve.prototype.copy = function ( source ) {
Curve.prototype.copy.call( this, source );
this.v1.copy( source.v1 );
this.v2.copy( source.v2 );
return this;
};
LineCurve.prototype.toJSON = function () {
var data = Curve.prototype.toJSON.call( this );
data.v1 = this.v1.toArray();
data.v2 = this.v2.toArray();
return data;
};
LineCurve.prototype.fromJSON = function ( json ) {
Curve.prototype.fromJSON.call( this, json );
this.v1.fromArray( json.v1 );
this.v2.fromArray( json.v2 );
return this;
};
export { LineCurve };
|