|
@@ -424,7 +424,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 ) );
|
|
@@ -437,11 +437,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 );
|
|
|
|
|
|
@@ -451,6 +457,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 );
|
|
@@ -532,13 +546,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 );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|