diff --git a/src/core/Box2.js b/src/core/Box2.js index 4344298f1742bb16b6031e2a69f3ae74efeb453d..e80e45e94631dfd8c0e3c14a18abc215bdc0a5d9 100644 --- a/src/core/Box2.js +++ b/src/core/Box2.js @@ -177,7 +177,24 @@ THREE.Box2.prototype = { clampPoint: function ( point ) { - return new THREE.Vector2().copy( point ).maxSelf( this.min ).minSelf( this.max ); + var p = new THREE.Vector2().copy( point ); + + // this requires less if's then a point.minSelf( this.max ).maxSelf( this.min ) + if( p.x < this.min.x ) { + p.x = this.min.x; + } + else if( p.x > this.max.x ) { + p.x = this.max.x; + } + + if( p.y < this.min.y ) { + p.y = this.min.y; + } + else if( p.y > this.max.y ) { + p.y = this.max.y; + } + + return p; }, distanceToPoint: function ( point ) {