|
@@ -732,7 +732,7 @@ Object.assign( Vector2.prototype, {
|
|
|
|
|
|
clamp: function ( min, max ) {
|
|
clamp: function ( min, max ) {
|
|
|
|
|
|
- // This function assumes min < max, if this assumption isn't true it will not operate correctly
|
|
|
|
|
|
+ // assumes min < max, componentwise
|
|
|
|
|
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
|
@@ -761,7 +761,7 @@ Object.assign( Vector2.prototype, {
|
|
|
|
|
|
var length = this.length();
|
|
var length = this.length();
|
|
|
|
|
|
- return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
|
|
|
|
|
|
+ return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
@@ -836,7 +836,7 @@ Object.assign( Vector2.prototype, {
|
|
|
|
|
|
normalize: function () {
|
|
normalize: function () {
|
|
|
|
|
|
- return this.divideScalar( this.length() );
|
|
|
|
|
|
+ return this.divideScalar( this.length() || 1 );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
@@ -873,7 +873,7 @@ Object.assign( Vector2.prototype, {
|
|
|
|
|
|
setLength: function ( length ) {
|
|
setLength: function ( length ) {
|
|
|
|
|
|
- return this.multiplyScalar( length / this.length() );
|
|
|
|
|
|
+ return this.normalize().multiplyScalar( length );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
@@ -1664,7 +1664,7 @@ Object.assign( Vector4.prototype, {
|
|
|
|
|
|
clamp: function ( min, max ) {
|
|
clamp: function ( min, max ) {
|
|
|
|
|
|
- // This function assumes min < max, if this assumption isn't true it will not operate correctly
|
|
|
|
|
|
+ // assumes min < max, componentwise
|
|
|
|
|
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
|
@@ -1677,11 +1677,17 @@ Object.assign( Vector4.prototype, {
|
|
|
|
|
|
clampScalar: function () {
|
|
clampScalar: function () {
|
|
|
|
|
|
- var min = new Vector4();
|
|
|
|
- var max = new Vector4();
|
|
|
|
|
|
+ var min, max;
|
|
|
|
|
|
return function clampScalar( minVal, maxVal ) {
|
|
return function clampScalar( minVal, maxVal ) {
|
|
|
|
|
|
|
|
+ if ( min === undefined ) {
|
|
|
|
+
|
|
|
|
+ min = new Vector4();
|
|
|
|
+ max = new Vector4();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
min.set( minVal, minVal, minVal, minVal );
|
|
min.set( minVal, minVal, minVal, minVal );
|
|
max.set( maxVal, maxVal, maxVal, maxVal );
|
|
max.set( maxVal, maxVal, maxVal, maxVal );
|
|
|
|
|
|
@@ -1691,6 +1697,14 @@ Object.assign( Vector4.prototype, {
|
|
|
|
|
|
}(),
|
|
}(),
|
|
|
|
|
|
|
|
+ clampLength: function ( min, max ) {
|
|
|
|
+
|
|
|
|
+ var length = this.length();
|
|
|
|
+
|
|
|
|
+ return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
floor: function () {
|
|
floor: function () {
|
|
|
|
|
|
this.x = Math.floor( this.x );
|
|
this.x = Math.floor( this.x );
|
|
@@ -1772,13 +1786,13 @@ Object.assign( Vector4.prototype, {
|
|
|
|
|
|
normalize: function () {
|
|
normalize: function () {
|
|
|
|
|
|
- return this.divideScalar( this.length() );
|
|
|
|
|
|
+ return this.divideScalar( this.length() || 1 );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
setLength: function ( length ) {
|
|
setLength: function ( length ) {
|
|
|
|
|
|
- return this.multiplyScalar( length / this.length() );
|
|
|
|
|
|
+ return this.normalize().multiplyScalar( length );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
@@ -2950,7 +2964,7 @@ Object.assign( Vector3.prototype, {
|
|
|
|
|
|
clamp: function ( min, max ) {
|
|
clamp: function ( min, max ) {
|
|
|
|
|
|
- // This function assumes min < max, if this assumption isn't true it will not operate correctly
|
|
|
|
|
|
+ // assumes min < max, componentwise
|
|
|
|
|
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
|
@@ -2980,7 +2994,7 @@ Object.assign( Vector3.prototype, {
|
|
|
|
|
|
var length = this.length();
|
|
var length = this.length();
|
|
|
|
|
|
- return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
|
|
|
|
|
|
+ return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
@@ -3062,13 +3076,13 @@ Object.assign( Vector3.prototype, {
|
|
|
|
|
|
normalize: function () {
|
|
normalize: function () {
|
|
|
|
|
|
- return this.divideScalar( this.length() );
|
|
|
|
|
|
+ return this.divideScalar( this.length() || 1 );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
setLength: function ( length ) {
|
|
setLength: function ( length ) {
|
|
|
|
|
|
- return this.multiplyScalar( length / this.length() );
|
|
|
|
|
|
+ return this.normalize().multiplyScalar( length );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|