Browse Source

Merge pull request #4851 from shapespark/Box3addPoint-remove

Remove duplicated Box3.addPoint.
Mr.doob 11 years ago
parent
commit
0f5f336dac
6 changed files with 37 additions and 94 deletions
  1. 0 9
      docs/api/math/Box3.html
  2. 1 1
      src/core/BufferGeometry.js
  3. 3 34
      src/math/Box2.js
  4. 3 50
      src/math/Box3.js
  5. 15 0
      test/unit/math/Box2.js
  6. 15 0
      test/unit/math/Box3.js

+ 0 - 9
docs/api/math/Box3.html

@@ -51,15 +51,6 @@
 		Sets the lower and upper (x, y, z) boundaries of this box.
 		</div>
 		
-		<h3>.addPoint([page:Vector3 point]) [page:Box3 this]</h3>
-		<div>
-		point -- [page:Vector3] to add to the box <br />
-		</div>
-		<div>
-		If the *point* is outside the bounds of the box, the bounds are expanded
-		so that the point is within the bounds.
-		</div>
-		
 		<h3>.applyMatrix4([page:Matrix4 matrix]) [page:Box3 this]</h3>
 		<div>
 		matrix -- The [page:Matrix4] to apply

+ 1 - 1
src/core/BufferGeometry.js

@@ -329,7 +329,7 @@ THREE.BufferGeometry.prototype = {
 				for ( var i = 0, il = positions.length; i < il; i += 3 ) {
 
 					vector.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
-					box.addPoint( vector );
+					box.expandByPoint( vector );
 
 				}
 

+ 3 - 34
src/math/Box2.js

@@ -24,42 +24,11 @@ THREE.Box2.prototype = {
 
 	setFromPoints: function ( points ) {
 
-		if ( points.length > 0 ) {
+		this.makeEmpty();
 
-			var point = points[ 0 ];
+		for ( var i = 0, il = points.length; i < il; i ++ ) {
 
-			this.min.copy( point );
-			this.max.copy( point );
-
-			for ( var i = 1, il = points.length; i < il; i ++ ) {
-
-				point = points[ i ];
-
-				if ( point.x < this.min.x ) {
-
-					this.min.x = point.x;
-
-				} else if ( point.x > this.max.x ) {
-
-					this.max.x = point.x;
-
-				}
-
-				if ( point.y < this.min.y ) {
-
-					this.min.y = point.y;
-
-				} else if ( point.y > this.max.y ) {
-
-					this.max.y = point.y;
-
-				}
-
-			}
-
-		} else {
-
-			this.makeEmpty();
+			this.expandByPoint( points[ i ] )
 
 		}
 

+ 3 - 50
src/math/Box3.js

@@ -23,60 +23,13 @@ THREE.Box3.prototype = {
 
 	},
 
-	addPoint: function ( point ) {
-
-		if ( point.x < this.min.x ) {
-
-			this.min.x = point.x;
-
-		} else if ( point.x > this.max.x ) {
-
-			this.max.x = point.x;
-
-		}
-
-		if ( point.y < this.min.y ) {
-
-			this.min.y = point.y;
-
-		} else if ( point.y > this.max.y ) {
-
-			this.max.y = point.y;
-
-		}
-
-		if ( point.z < this.min.z ) {
-
-			this.min.z = point.z;
-
-		} else if ( point.z > this.max.z ) {
-
-			this.max.z = point.z;
-
-		}
-		
-		return this;
-
-	},
-
 	setFromPoints: function ( points ) {
 
-		if ( points.length > 0 ) {
-
-			var point = points[ 0 ];
-
-			this.min.copy( point );
-			this.max.copy( point );
-
-			for ( var i = 1, il = points.length; i < il; i ++ ) {
+		this.makeEmpty();
 
-				this.addPoint( points[ i ] )
+		for ( var i = 0, il = points.length; i < il; i ++ ) {
 
-			}
-
-		} else {
-
-			this.makeEmpty();
+			this.expandByPoint( points[ i ] )
 
 		}
 

+ 15 - 0
test/unit/math/Box2.js

@@ -39,6 +39,21 @@ test( "set", function() {
 	ok( a.max.equals( one2 ), "Passed!" );
 });
 
+test( "setFromPoints", function() {
+	var a = new THREE.Box2();
+
+	a.setFromPoints( [ zero2, one2, two2 ] );
+	ok( a.min.equals( zero2 ), "Passed!" );
+	ok( a.max.equals( two2 ), "Passed!" );
+
+	a.setFromPoints( [ one2 ] );
+	ok( a.min.equals( one2 ), "Passed!" );
+	ok( a.max.equals( one2 ), "Passed!" );
+
+	a.setFromPoints( [] );
+	ok( a.empty(), "Passed!" );
+});
+
 test( "empty/makeEmpty", function() {
 	var a = new THREE.Box2();
 

+ 15 - 0
test/unit/math/Box3.js

@@ -39,6 +39,21 @@ test( "set", function() {
 	ok( a.max.equals( one3 ), "Passed!" );
 });
 
+test( "setFromPoints", function() {
+	var a = new THREE.Box3();
+
+	a.setFromPoints( [ zero3, one3, two3 ] );
+	ok( a.min.equals( zero3 ), "Passed!" );
+	ok( a.max.equals( two3 ), "Passed!" );
+
+	a.setFromPoints( [ one3 ] );
+	ok( a.min.equals( one3 ), "Passed!" );
+	ok( a.max.equals( one3 ), "Passed!" );
+
+	a.setFromPoints( [] );
+	ok( a.empty(), "Passed!" );
+});
+
 test( "empty/makeEmpty", function() {
 	var a = new THREE.Box3();