Ver código fonte

Only default radius to -1, makeEmpty, and sphere that returns isEmpty will also produce an empty box3

samfoster 5 anos atrás
pai
commit
e222f9a214

+ 1 - 2
docs/api/en/math/Sphere.html

@@ -11,7 +11,6 @@
 		<h1>[name]</h1>
 
 		<p class="desc">A sphere defined by a center and radius.</p>
-		<p></p>
 
 		<h2>Constructor</h2>
 		<h3>[name]( [param:Vector3 center], [param:Float radius] )</h3>
@@ -77,7 +76,7 @@
 		<h3>[method:Boolean isEmpty]()</h3>
 		<p>
 		Checks to see if the sphere is empty (the radius set to a negative number).</br>
-		Spheres with a radius of 0 contain only their center point and are not considererd to be empty.
+		Spheres with a radius of 0 contain only their center point and are not considered to be empty.
 		</p>
 
 		<h3>[method:Sphere makeEmpty]()</h3>

+ 5 - 2
docs/api/zh/math/Sphere.html

@@ -71,10 +71,13 @@
 		</p>
 
 		<h3>[method:Boolean isEmpty]()</h3>
-		<p>检查球是否为空(the radius set to a negative number).</p>
+		<p>
+		检查球是否为空(the radius set to a negative number).
+		Spheres with a radius of 0 contain only their center point and are not considered to be empty.
+		</p>
 
 		<h3>[method:Sphere makeEmpty]()</h3>
-		<p>Makes the sphere empty by setting [page:.center center] to (0, 0, 0) and [page:.radius radius] to 0.</p>
+		<p>Makes the sphere empty by setting [page:.center center] to (0, 0, 0) and [page:.radius radius] to -1.</p>
 
 		<h3>[method:Boolean equals]( [param:Sphere sphere] )</h3>
 		<p>

+ 2 - 1
src/Three.Legacy.js

@@ -62,6 +62,7 @@ import { PointsMaterial } from './materials/PointsMaterial.js';
 import { ShaderMaterial } from './materials/ShaderMaterial.js';
 import { Box2 } from './math/Box2.js';
 import { Box3 } from './math/Box3.js';
+import { Sphere } from './math/Sphere.js';
 import { Color } from './math/Color.js';
 import { Frustum } from './math/Frustum.js';
 import { Line3 } from './math/Line3.js';
@@ -544,7 +545,7 @@ Object.assign( Box3.prototype, {
 
 Object.assign( Sphere.prototype, {
 
-	empty: function() {
+	empty: function () {
 
 		console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
 		return this.isEmpty();

+ 0 - 6
src/math/Box3.js

@@ -325,12 +325,6 @@ Object.assign( Box3.prototype, {
 
 	intersectsSphere: function ( sphere ) {
 
-		if( sphere.isEmpty() ) {
-
-			return false;
-
-		}
-
 		// Find the point on the AABB closest to the sphere center.
 		this.clampPoint( sphere.center, _vector );
 

+ 4 - 15
src/math/Sphere.js

@@ -11,7 +11,7 @@ var _box = new Box3();
 function Sphere( center, radius ) {
 
 	this.center = ( center !== undefined ) ? center : new Vector3();
-	this.radius = ( radius !== undefined ) ? radius : -1;
+	this.radius = ( radius !== undefined ) ? radius : - 1;
 
 }
 
@@ -78,7 +78,7 @@ Object.assign( Sphere.prototype, {
 	makeEmpty: function () {
 
 		this.center.set( 0, 0, 0 );
-		this.radius = -1;
+		this.radius = - 1;
 
 		return this;
 
@@ -86,12 +86,6 @@ Object.assign( Sphere.prototype, {
 
 	containsPoint: function ( point ) {
 
-		if( this.isEmpty() ) {
-
-			return false;
-
-		}
-
 		return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
 
 	},
@@ -104,12 +98,6 @@ Object.assign( Sphere.prototype, {
 
 	intersectsSphere: function ( sphere ) {
 
-		if( this.isEmpty() ) {
-
-			return false;
-
-		}
-
 		var radiusSum = this.radius + sphere.radius;
 
 		return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
@@ -161,8 +149,9 @@ Object.assign( Sphere.prototype, {
 
 		}
 
-		if( this.isEmpty() ) {
+		if ( this.isEmpty() ) {
 
+			// Empty sphere produces empty bounding box
 			target.makeEmpty();
 			return target;
 

+ 2 - 14
test/unit/src/math/Sphere.tests.js

@@ -25,7 +25,7 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Sphere();
 			assert.ok( a.center.equals( zero3 ), "Passed!" );
-			assert.ok( a.radius == 0, "Passed!" );
+			assert.ok( a.radius == - 1, "Passed!" );
 
 			var a = new Sphere( one3.clone(), 1 );
 			assert.ok( a.center.equals( one3 ), "Passed!" );
@@ -44,7 +44,7 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Sphere();
 			assert.ok( a.center.equals( zero3 ), "Passed!" );
-			assert.ok( a.radius == 0, "Passed!" );
+			assert.ok( a.radius == - 1, "Passed!" );
 
 			a.set( one3, 1 );
 			assert.ok( a.center.equals( one3 ), "Passed!" );
@@ -148,9 +148,6 @@ export default QUnit.module( 'Maths', () => {
 			a.set( zero3, 0 );
 			assert.ok( a.containsPoint( a.center ), "Passed!" );
 
-			a.makeEmpty();
-			assert.ok( !a.containsPoint( a.center ), "Passed" );
-
 		} );
 
 		QUnit.test( "distanceToPoint", ( assert ) => {
@@ -171,9 +168,6 @@ export default QUnit.module( 'Maths', () => {
 			assert.ok( a.intersectsSphere( b ), "Passed!" );
 			assert.ok( ! a.intersectsSphere( c ), "Passed!" );
 
-			a.makeEmpty();
-			assert.ok( !a.intersectsSphere( a ), "Passed!" );
-
 		} );
 
 		QUnit.test( "intersectsBox", ( assert ) => {
@@ -185,9 +179,6 @@ export default QUnit.module( 'Maths', () => {
 			assert.strictEqual( a.intersectsBox( box ), true, "Check unit sphere" );
 			assert.strictEqual( b.intersectsBox( box ), false, "Check shifted sphere" );
 
-			a.makeEmpty();
-			assert.strictEqual( a.intersectsBox( box ), false , "Check empty sphere");
-
 		} );
 
 		QUnit.test( "intersectsPlane", ( assert ) => {
@@ -201,9 +192,6 @@ export default QUnit.module( 'Maths', () => {
 			assert.ok( ! a.intersectsPlane( c ), "Passed!" );
 			assert.ok( ! a.intersectsPlane( d ), "Passed!" );
 
-			a.makeEmpty();
-			assert.ok( ! a.intersectsPlane( b ), "Passed!" );
-
 		} );
 
 		QUnit.test( "clampPoint", ( assert ) => {