diff --git a/src/math/Box3.js b/src/math/Box3.js index 00999d7c57dbacc26493d7f8fc24ecf467fd7026..bed02f3e9bb8233ac17512c5ce13058d80661763 100644 --- a/src/math/Box3.js +++ b/src/math/Box3.js @@ -226,6 +226,17 @@ THREE.Box3.prototype = { }, + boundingSphere: function ( optionalTarget ) { + + var result = optionalTarget || new THREE.Sphere(); + + result.center = this.center(); + result.radius = this.size( THREE.Box3.__v0 ).length() * 0.5;; + + return result; + + }, + intersect: function ( box ) { this.min.maxSelf( box.min ); diff --git a/src/math/Sphere.js b/src/math/Sphere.js index aab56ed4630d1c0fbd727c30ff40bf539fc8c622..a322748ee0e0f3b12291a2e496500b03f450acef 100644 --- a/src/math/Sphere.js +++ b/src/math/Sphere.js @@ -85,7 +85,7 @@ THREE.Sphere.prototype = { }, - bounds: function ( optionalTarget ) { + boundingBox: function ( optionalTarget ) { var box = optionalTarget || new THREE.Box3(); diff --git a/test/math/Box3.js b/test/math/Box3.js index 8aa4a3241dc6c7474f2eb25e76beac1eac5383f3..700ee96e43db76011ba62449878dcc26d8fd331e 100644 --- a/test/math/Box3.js +++ b/test/math/Box3.js @@ -208,6 +208,16 @@ test( "isIntersectionBox", function() { ok( ! b.isIntersectionBox( c ), "Passed!" ); }); +test( "boundingSphere", function() { + var a = new THREE.Box3( zero3, zero3 ); + var b = new THREE.Box3( zero3, one3 ); + var c = new THREE.Box3( one3.clone().negate(), one3 ); + + ok( a.boundingSphere().equals( new THREE.Sphere( zero3, 0 ) ), "Passed!" ); + ok( b.boundingSphere().equals( new THREE.Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" ); + ok( c.boundingSphere().equals( new THREE.Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" ); +}); + test( "intersect", function() { var a = new THREE.Box3( zero3, zero3 ); var b = new THREE.Box3( zero3, one3 ); diff --git a/test/math/Sphere.js b/test/math/Sphere.js index a7117d1fd8c1c1cee236e33f8de0fabd5f7e8eb1..cdcd0ae058c94501a0c4e16d4c303de14e675d7d 100644 --- a/test/math/Sphere.js +++ b/test/math/Sphere.js @@ -67,13 +67,13 @@ test( "clampPoint", function() { ok( a.clampPoint( new THREE.Vector3( 1, 1, -3 ) ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" ); }); -test( "bounds", function() { +test( "boundingBox", function() { var a = new THREE.Sphere( one3, 1 ); - ok( a.bounds().equals( new THREE.Box3( zero3, two3 ) ), "Passed!" ); + ok( a.boundingBox().equals( new THREE.Box3( zero3, two3 ) ), "Passed!" ); a.set( zero3, 0 ) - ok( a.bounds().equals( new THREE.Box3( zero3, zero3 ) ), "Passed!" ); + ok( a.boundingBox().equals( new THREE.Box3( zero3, zero3 ) ), "Passed!" ); }); test( "transform", function() { @@ -83,7 +83,7 @@ test( "transform", function() { var t1 = new THREE.Vector3( 1, -2, 1 ); m.makeTranslation( t1 ); - ok( a.clone().transform( m ).bounds().equals( a.bounds().transform( m ) ), "Passed!" ); + ok( a.clone().transform( m ).boundingBox().equals( a.boundingBox().transform( m ) ), "Passed!" ); }); test( "translate", function() {