Skip to content

Commit

Permalink
Vector2: consume MathUtils.clamp internally
Browse files Browse the repository at this point in the history
  • Loading branch information
satelllte committed Nov 5, 2024
1 parent b54d466 commit 70ba7f5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/math/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ class Vector2 {

// 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.x = MathUtils.clamp( this.x, min.x, max.x );
this.y = MathUtils.clamp( this.y, min.y, max.y );

return this;

}

clampScalar( minVal, maxVal ) {

this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
this.x = MathUtils.clamp( this.x, minVal, maxVal );
this.y = MathUtils.clamp( this.y, minVal, maxVal );

return this;

Expand All @@ -260,7 +260,7 @@ class Vector2 {

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 ) );

}

Expand Down

0 comments on commit 70ba7f5

Please sign in to comment.