From c4072ef9db371596d1f25cf2378436f51f0fb145 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Sun, 2 Dec 2012 08:39:47 -0500 Subject: [PATCH] apply @gero3 's suggestion to Box2.clampPoint() as well. --- src/core/Box2.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/Box2.js b/src/core/Box2.js index 4344298f17..e80e45e946 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 ) { -- GitLab