Browse Source

Box2/Box3: Return center/size when empty. See #9675.

Mr.doob 9 years ago
parent
commit
09c778964a
2 changed files with 3 additions and 3 deletions
  1. 2 2
      src/math/Box2.js
  2. 1 1
      src/math/Box3.js

+ 2 - 2
src/math/Box2.js

@@ -89,14 +89,14 @@ Box2.prototype = {
 	center: function ( optionalTarget ) {
 
 		var result = optionalTarget || new Vector2();
-		return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
+		return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
 
 	},
 
 	size: function ( optionalTarget ) {
 
 		var result = optionalTarget || new Vector2();
-		return result.subVectors( this.max, this.min );
+		return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
 
 	},
 

+ 1 - 1
src/math/Box3.js

@@ -211,7 +211,7 @@ Box3.prototype = {
 	size: function ( optionalTarget ) {
 
 		var result = optionalTarget || new Vector3();
-		return result.subVectors( this.max, this.min );
+		return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
 
 	},