提交 2b4373be 编写于 作者: B Ben Houston

+Box3.boundingSphere(), Sphere.bounds()->Sphere.boundingBox(), unit tests.

上级 a32ee687
...@@ -226,6 +226,17 @@ THREE.Box3.prototype = { ...@@ -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 ) { intersect: function ( box ) {
this.min.maxSelf( box.min ); this.min.maxSelf( box.min );
......
...@@ -85,7 +85,7 @@ THREE.Sphere.prototype = { ...@@ -85,7 +85,7 @@ THREE.Sphere.prototype = {
}, },
bounds: function ( optionalTarget ) { boundingBox: function ( optionalTarget ) {
var box = optionalTarget || new THREE.Box3(); var box = optionalTarget || new THREE.Box3();
......
...@@ -208,6 +208,16 @@ test( "isIntersectionBox", function() { ...@@ -208,6 +208,16 @@ test( "isIntersectionBox", function() {
ok( ! b.isIntersectionBox( c ), "Passed!" ); 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() { test( "intersect", function() {
var a = new THREE.Box3( zero3, zero3 ); var a = new THREE.Box3( zero3, zero3 );
var b = new THREE.Box3( zero3, one3 ); var b = new THREE.Box3( zero3, one3 );
......
...@@ -67,13 +67,13 @@ test( "clampPoint", function() { ...@@ -67,13 +67,13 @@ test( "clampPoint", function() {
ok( a.clampPoint( new THREE.Vector3( 1, 1, -3 ) ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" ); 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 ); 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 ) 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() { test( "transform", function() {
...@@ -83,7 +83,7 @@ test( "transform", function() { ...@@ -83,7 +83,7 @@ test( "transform", function() {
var t1 = new THREE.Vector3( 1, -2, 1 ); var t1 = new THREE.Vector3( 1, -2, 1 );
m.makeTranslation( t1 ); 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() { test( "translate", function() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册