|
@@ -1,3 +1,5 @@
|
|
|
|
|
+import * as MathUtils from './MathUtils.js';
|
|
|
|
|
+
|
|
|
class Vector4 {
|
|
class Vector4 {
|
|
|
|
|
|
|
|
constructor( x = 0, y = 0, z = 0, w = 1 ) {
|
|
constructor( x = 0, y = 0, z = 0, w = 1 ) {
|
|
@@ -463,10 +465,10 @@ class Vector4 {
|
|
|
|
|
|
|
|
// assumes min < max, componentwise
|
|
// assumes min < max, componentwise
|
|
|
|
|
|
|
|
- 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.z = Math.max( min.z, Math.min( max.z, this.z ) );
|
|
|
|
|
- this.w = Math.max( min.w, Math.min( max.w, this.w ) );
|
|
|
|
|
|
|
+ this.x = MathUtils.clamp( this.x, min.x, max.x );
|
|
|
|
|
+ this.y = MathUtils.clamp( this.y, min.y, max.y );
|
|
|
|
|
+ this.z = MathUtils.clamp( this.z, min.z, max.z );
|
|
|
|
|
+ this.w = MathUtils.clamp( this.w, min.w, max.w );
|
|
|
|
|
|
|
|
return this;
|
|
return this;
|
|
|
|
|
|
|
@@ -474,10 +476,10 @@ class Vector4 {
|
|
|
|
|
|
|
|
clampScalar( minVal, maxVal ) {
|
|
clampScalar( minVal, maxVal ) {
|
|
|
|
|
|
|
|
- this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
|
|
|
|
|
- this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
|
|
|
|
|
- this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
|
|
|
|
|
- this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
|
|
|
|
|
|
|
+ this.x = MathUtils.clamp( this.x, minVal, maxVal );
|
|
|
|
|
+ this.y = MathUtils.clamp( this.y, minVal, maxVal );
|
|
|
|
|
+ this.z = MathUtils.clamp( this.z, minVal, maxVal );
|
|
|
|
|
+ this.w = MathUtils.clamp( this.w, minVal, maxVal );
|
|
|
|
|
|
|
|
return this;
|
|
return this;
|
|
|
|
|
|
|
@@ -487,7 +489,7 @@ class Vector4 {
|
|
|
|
|
|
|
|
const length = this.length();
|
|
const length = this.length();
|
|
|
|
|
|
|
|
- return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
|
|
|
|
|
|
|
+ return this.divideScalar( length || 1 ).multiplyScalar( MathUtils.clamp( length, min, max ) );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|