提交 916ce9c6 编写于 作者: M Mr.doob

Renamed isIntersection* to intersects*. See #7376.

上级 47264fc6
......@@ -22,7 +22,7 @@
max -- Upper (x, y) boundary of the box.
</div>
<div>
Creates a box bounded by min and max.
Creates a box bounded by min and max.
</div>
......@@ -33,12 +33,12 @@
<h3>[property:Vector2 min]</h3>
<div>
Lower (x, y) boundary of this box.
</div>
</div>
<h3>[property:Vector2 max]</h3>
<div>
Upper (x, y) boundary of this box.
</div>
</div>
<h2>Methods</h2>
......@@ -70,7 +70,7 @@
Clamps *point* within the bounds of this box.
</div>
<h3>[method:Boolean isIntersectionBox]([page:Box2 box])</h3>
<h3>[method:Boolean intersectsBox]([page:Box2 box])</h3>
<div>
box -- Box to check for intersection against.
</div>
......@@ -99,7 +99,7 @@
box -- Box that will be unioned with this box.
</div>
<div>
Unions this box with *box* setting the upper bound of this box to the greater of the
Unions this box with *box* setting the upper bound of this box to the greater of the
two boxes' upper bounds and the lower bound of this box to the lesser of the two boxes'
lower bounds.
</div>
......@@ -108,7 +108,7 @@
<div>
point -- [page:Vector2]<br/>
optionalTarget -- [page:Vector2]<br/>
</div>
<div>
Returns a point as a proportion of this box's width and height.
......@@ -139,7 +139,7 @@
</div>
<div>
Returns true if this box includes the entirety of *box*. If this and *box* overlap exactly,</br>
this function also returns true.
this function also returns true.
</div>
<h3>[method:Box2 translate]([page:Vector2 offset]) [page:Box2 this]</h3>
......@@ -177,7 +177,7 @@
</div>
<div>
Expands this box equilaterally by *vector*. The width of this box will be
expanded by the x component of *vector* in both directions. The height of
expanded by the x component of *vector* in both directions. The height of
this box will be expanded by the y component of *vector* in both directions.
</div>
......@@ -222,7 +222,7 @@
<h3>[method:Box2 setFromCenterAndSize]([page:Vector2 center], [page:Vector2 size]) [page:Box2 this]</h3>
<div>
center -- Desired center position of the box. <br />
size -- Desired x and y dimensions of the box.
size -- Desired x and y dimensions of the box.
</div>
<div>
Centers this box on *center* and sets this box's width and height to the values specified
......
......@@ -22,7 +22,7 @@
max -- Upper (x, y, z) boundary of the box.
</div>
<div>
Creates a box bounded by min and max.
Creates a box bounded by min and max.
</div>
<h2>Properties</h2>
......@@ -37,7 +37,7 @@
<h3>[property:Vector3 max]</h3>
<div>
Upper (x, y, z) boundary of this box.
</div>
</div>
<h2>Methods</h2>
......@@ -51,7 +51,7 @@
<div>
Sets the lower and upper (x, y, z) boundaries of this box.
</div>
<h3>[method:Box3 applyMatrix4]([page:Matrix4 matrix]) [page:Box3 this]</h3>
<div>
matrix -- The [page:Matrix4] to apply
......@@ -69,7 +69,7 @@
Clamps *point* within the bounds of this box.
</div>
<h3>[method:Boolean isIntersectionBox]([page:Box3 box])</h3>
<h3>[method:Boolean intersectsBox]([page:Box3 box])</h3>
<div>
box -- Box to check for intersection against.
</div>
......@@ -84,7 +84,7 @@
<div>
Sets the upper and lower bounds of this box to include all of the points in *points*.
</div>
<h3>[method:Box3 setFromObject]([page:Object3D object]) [page:Box3 this]</h3>
<div>
object -- [page:Object3D] to compute the bounding box for.
......@@ -93,8 +93,8 @@
Computes the world-axis-aligned bounding box of an object (including its children),
accounting for both the object's, and childrens', world transforms
</div>
<h3>[method:Vector3 size]([page:Vector3 optionalTarget])</h3>
<div>
......@@ -109,7 +109,7 @@
box -- Box that will be unioned with this box.
</div>
<div>
Unions this box with *box* setting the upper bound of this box to the greater of the
Unions this box with *box* setting the upper bound of this box to the greater of the
two boxes' upper bounds and the lower bound of this box to the lesser of the two boxes'
lower bounds.
</div>
......@@ -139,7 +139,7 @@
</div>
<div>
Returns true if this box includes the entirety of *box*. If this and *box* overlap exactly,</br>
this function also returns true.
this function also returns true.
</div>
<h3>[method:Boolean containsPoint]([page:Vector3 point])</h3>
......@@ -149,7 +149,7 @@
<div>
Returns true if the specified point lies within the boundaries of this box.
</div>
<h3>[method:Box3 translate]([page:Vector3 offset]) [page:Box3 this]</h3>
<div>
offset -- Direction and distance of offset.
......@@ -186,7 +186,7 @@
<div>
Expands the boundaries of this box to include *point*.
</div>
<h3>[method:Box3 expandByScalar]([page:float scalar]) [page:Box3 this]</h3>
<div>
scalar -- Distance to expand.
......@@ -195,14 +195,14 @@
Expands each dimension of the box by *scalar*. If negative, the dimensions of the box <br/>
will be contracted.
</div>
<h3>[method:Box3 expandByVector]([page:Vector3 vector]) [page:Box3 this]</h3>
<div>
vector -- Amount to expand this box in each dimension.
</div>
<div>
Expands this box equilaterally by *vector*. The width of this box will be
expanded by the x component of *vector* in both directions. The height of
expanded by the x component of *vector* in both directions. The height of
this box will be expanded by the y component of *vector* in both directions.
The depth of this box will be expanded by the z component of *vector* in
both directions.
......@@ -249,7 +249,7 @@
<h3>[method:Box3 setFromCenterAndSize]([page:Vector3 center], [page:Vector3 size]) [page:Box3 this]</h3>
<div>
center -- Desired center position of the box. <br />
size -- Desired x and y dimensions of the box.
size -- Desired x and y dimensions of the box.
</div>
<div>
Centers this box on *center* and sets this box's width and height to the values specified
......
......@@ -28,7 +28,7 @@
<h3>[property:Vector3 normal]</h3>
<h3>[property:Float constant]</h3>
<h2>Methods</h2>
......@@ -62,9 +62,9 @@
</div>
<div>
Apply a Matrix4 to the plane. The second parameter is optional.
<code>
var optionalNormalMatrix = new THREE.Matrix3().getNormalMatrix( matrix )
var optionalNormalMatrix = new THREE.Matrix3().getNormalMatrix( matrix )
</code>
</div>
......@@ -77,7 +77,7 @@
Returns a vector in the same direction as the Plane's normal, but the magnitude is passed point's original distance to the plane.
</div>
<h3>[method:Boolean isIntersectionLine]([page:Line3 line])</h3>
<h3>[method:Boolean intersectsLine]([page:Line3 line])</h3>
<div>
line -- [page:Line3]
</div>
......
......@@ -30,12 +30,12 @@
<h3>[property:Vector3 origin]</h3>
<div>
The origin of the [page:Ray].
</div>
</div>
<h3>[property:Vector3 direction]</h3>
<div>
The direction of the [page:Ray]. This must be normalized (with [page:Vector3].normalize) for the methods to operate properly.
</div>
</div>
<h2>Methods</h2>
......@@ -77,7 +77,7 @@
<div>
Copy the properties of the provided [page:Ray], then return this [page:Ray].
</div>
<h3>.distanceSqToSegment([page:Vector3 v0], [page:Vector3 v1], [page:Vector3 optionalPointOnRay] = null, [page:Vector3 optionalPointOnSegment] = null) [page:Float]</h3>
<div>
v0 -- [page:Vector3] The start of the line segment.
......@@ -129,7 +129,7 @@
<div>
Intersect this [page:Ray] with a [page:Box3], returning the intersection point or *null* if there is no intersection.
</div>
<h3>.intersectPlane([page:Plane plane], [page:Vector3 optionalTarget] = null) [page:Vector3]?</h3>
<div>
plane -- [page:Plane] The [page:Plane] to intersect with.<br />
......@@ -139,7 +139,7 @@
Intersect this [page:Ray] with a [page:Plane], returning the intersection point or *null* if there is no intersection.
</div>
function ( a, b, c, backfaceCulling, optionalTarget )
<h3>.intersectTriangle([page:Vector3 a], [page:Vector3 b], [page:Vector3 c], [page:Boolean backfaceCulling], [page:Vector3 optionalTarget] = null) [page:Vector3]?</h3>
<div>
a, b, c -- [page:Vector3] The [page:Vector3] points on the triangle.<br />
......@@ -149,8 +149,8 @@
<div>
Intersect this [page:Ray] with a triangle, returning the intersection point or *null* if there is no intersection.
</div>
<h3>[method:Boolean isIntersectionBox]([page:Box3 box])</h3>
<h3>[method:Boolean intersectsBox]([page:Box3 box])</h3>
<div>
box -- [page:Box3] The [page:Box3] to intersect with.
</div>
......@@ -158,7 +158,7 @@
Return whether or not this [page:Ray] intersects with the [page:Box3].
</div>
<h3>[method:Boolean isIntersectionPlane]([page:Plane plane])</h3>
<h3>[method:Boolean intersectsPlane]([page:Plane plane])</h3>
<div>
plane -- [page:Plane] The [page:Plane] to intersect with.
</div>
......@@ -166,7 +166,7 @@
Return whether or not this [page:Ray] intersects with the [page:Plane].
</div>
<h3>[method:Boolean isIntersectionSphere]([page:Sphere sphere])</h3>
<h3>[method:Boolean intersectsSphere]([page:Sphere sphere])</h3>
<div>
sphere -- [page:Sphere] The [page:Sphere] to intersect with.
</div>
......
......@@ -363,7 +363,7 @@ THREE.CanvasRenderer = function ( parameters ) {
_v2.positionScreen
] );
if ( _clipBox.isIntersectionBox( _elemBox ) === true ) {
if ( _clipBox.intersectsBox( _elemBox ) === true ) {
renderLine( _v1, _v2, element, material );
......@@ -395,7 +395,7 @@ THREE.CanvasRenderer = function ( parameters ) {
_v3.positionScreen
] );
if ( _clipBox.isIntersectionBox( _elemBox ) === true ) {
if ( _clipBox.intersectsBox( _elemBox ) === true ) {
renderFace3( _v1, _v2, _v3, 0, 1, 2, element, material );
......
......@@ -223,7 +223,7 @@ THREE.Projector = function () {
_points3[ 1 ] = v2.positionScreen;
_points3[ 2 ] = v3.positionScreen;
return _clipBox.isIntersectionBox( _boundingBox.setFromPoints( _points3 ) );
return _clipBox.intersectsBox( _boundingBox.setFromPoints( _points3 ) );
}
......
......@@ -170,7 +170,7 @@ THREE.SVGRenderer = function () {
_elemBox.setFromPoints( [ _v1.positionScreen, _v2.positionScreen ] );
if ( _clipBox.isIntersectionBox( _elemBox ) === true ) {
if ( _clipBox.intersectsBox( _elemBox ) === true ) {
renderLine( _v1, _v2, element, material );
......@@ -194,7 +194,7 @@ THREE.SVGRenderer = function () {
_v3.positionScreen
] );
if ( _clipBox.isIntersectionBox( _elemBox ) === true ) {
if ( _clipBox.intersectsBox( _elemBox ) === true ) {
renderFace3( _v1, _v2, _v3, element, material );
......
......@@ -51,7 +51,7 @@ THREE.Box2.prototype = {
};
}(),
clone: function () {
return new this.constructor().copy( this );
......@@ -165,7 +165,7 @@ THREE.Box2.prototype = {
},
isIntersectionBox: function ( box ) {
intersectsBox: function ( box ) {
// using 6 splitting planes to rule out intersections.
......@@ -180,6 +180,14 @@ THREE.Box2.prototype = {
},
isIntersectionBox: function ( box ) {
console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
return this.intersectsBox( box );
},
clampPoint: function ( point, optionalTarget ) {
var result = optionalTarget || new THREE.Vector2();
......
......@@ -231,7 +231,7 @@ THREE.Box3.prototype = {
},
isIntersectionBox: function ( box ) {
intersectsBox: function ( box ) {
// using 6 splitting planes to rule out intersections.
......@@ -247,11 +247,19 @@ THREE.Box3.prototype = {
},
isIntersectionSphere: ( function () {
isIntersectionBox: function ( box ) {
console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
return this.intersectsBox( box );
},
intersectsSphere: ( function () {
var closestPoint;
return function isIntersectionSphere( sphere ) {
return function intersectsSphere( sphere ) {
if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
......@@ -265,6 +273,14 @@ THREE.Box3.prototype = {
} )(),
isIntersectionSphere: function ( sphere ) {
console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
return this.intersectsSphere( sphere );
},
clampPoint: function ( point, optionalTarget ) {
var result = optionalTarget || new THREE.Vector3();
......
......@@ -122,17 +122,6 @@ THREE.Plane.prototype = {
},
isIntersectionLine: function ( line ) {
// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
var startSign = this.distanceToPoint( line.start );
var endSign = this.distanceToPoint( line.end );
return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
},
intersectLine: function () {
var v1 = new THREE.Vector3();
......@@ -173,6 +162,24 @@ THREE.Plane.prototype = {
}(),
intersectsLine: function ( line ) {
// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
var startSign = this.distanceToPoint( line.start );
var endSign = this.distanceToPoint( line.end );
return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
},
isIntersectionLine: function ( line ) {
console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
return this.intersectsLine( line );
},
coplanarPoint: function ( optionalTarget ) {
......
......@@ -232,13 +232,6 @@ THREE.Ray.prototype = {
}(),
isIntersectionSphere: function ( sphere ) {
return this.distanceToPoint( sphere.center ) <= sphere.radius;
},
intersectSphere: function () {
// from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
......@@ -280,35 +273,24 @@ THREE.Ray.prototype = {
}(),
isIntersectionPlane: function ( plane ) {
// check if the ray lies on the plane first
var distToPoint = plane.distanceToPoint( this.origin );
if ( distToPoint === 0 ) {
return true;
}
var denominator = plane.normal.dot( this.direction );
intersectsSphere: function ( sphere ) {
if ( denominator * distToPoint < 0 ) {
return this.distanceToPoint( sphere.center ) <= sphere.radius;
return true;
},
}
isIntersectionSphere: function ( sphere ) {
// ray origin is behind the plane (and is pointing behind it)
console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
return false;
return this.intersectsSphere( sphere );
},
distanceToPlane: function ( plane ) {
var denominator = plane.normal.dot( this.direction );
if ( denominator === 0 ) {
// line is coplanar, return origin
......@@ -346,17 +328,41 @@ THREE.Ray.prototype = {
},
isIntersectionBox: function () {
var v = new THREE.Vector3();
return function ( box ) {
intersectsPlane: function ( plane ) {
return this.intersectBox( box, v ) !== null;
// check if the ray lies on the plane first
};
var distToPoint = plane.distanceToPoint( this.origin );
}(),
if ( distToPoint === 0 ) {
return true;
}
var denominator = plane.normal.dot( this.direction );
if ( denominator * distToPoint < 0 ) {
return true;
}
// ray origin is behind the plane (and is pointing behind it)
return false;
},
isIntersectionPlane: function ( plane ) {
console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
return this.intersectsPlane( plane );
},
intersectBox: function ( box, optionalTarget ) {
......@@ -429,6 +435,26 @@ THREE.Ray.prototype = {
},
intersectsBox: ( function () {
var v = new THREE.Vector3();
return function ( box ) {
return this.intersectBox( box, v ) !== null;
};
} )(),
isIntersectionBox: function ( box ) {
console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
return this.intersectsBox( box );
},
intersectTriangle: function () {
// Compute the offset origin, edges, and normal.
......
......@@ -92,22 +92,15 @@ THREE.Sphere.prototype = {
intersectsSphere: function ( sphere ) {
console.warn( 'THREE.Sphere: .intersectsSphere() has been renamed to .isIntersectionSphere().' );
return this.isIntersectionSphere( sphere );
},
isIntersectionSphere: function ( sphere ) {
var radiusSum = this.radius + sphere.radius;
return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
},
isIntersectionBox: function ( box ) {
intersectsBox: function ( box ) {
return box.isIntersectionSphere( this );
return box.intersectsSphere( this );
},
......
......@@ -43,11 +43,7 @@ THREE.Line.prototype.raycast = ( function () {
sphere.copy( geometry.boundingSphere );
sphere.applyMatrix4( this.matrixWorld );
if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
return;
}
if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
inverseMatrix.getInverse( this.matrixWorld );
ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
......
......@@ -169,7 +169,7 @@ THREE.Mesh.prototype.raycast = ( function () {
sphere.copy( geometry.boundingSphere );
sphere.applyMatrix4( matrixWorld );
if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) return;
if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
// Check boundingBox before continuing
......@@ -178,7 +178,7 @@ THREE.Mesh.prototype.raycast = ( function () {
if ( geometry.boundingBox !== null ) {
if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) return;
if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
}
......
......@@ -32,11 +32,7 @@ THREE.Points.prototype.raycast = ( function () {
if ( geometry.boundingBox !== null ) {
if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
return;
}
if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
}
......
......@@ -189,23 +189,23 @@ test( "distanceToPoint", function() {
ok( b.distanceToPoint( new THREE.Vector2( -2, -2 ) ) == Math.sqrt( 2 ), "Passed!" );
});
test( "isIntersectionBox", function() {
test( "intersectsBox", function() {
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
var b = new THREE.Box2( zero2.clone(), one2.clone() );
var c = new THREE.Box2( one2.clone().negate(), one2.clone() );
ok( a.isIntersectionBox( a ), "Passed!" );
ok( a.isIntersectionBox( b ), "Passed!" );
ok( a.isIntersectionBox( c ), "Passed!" );
ok( a.intersectsBox( a ), "Passed!" );
ok( a.intersectsBox( b ), "Passed!" );
ok( a.intersectsBox( c ), "Passed!" );
ok( b.isIntersectionBox( a ), "Passed!" );
ok( c.isIntersectionBox( a ), "Passed!" );
ok( b.isIntersectionBox( c ), "Passed!" );
ok( b.intersectsBox( a ), "Passed!" );
ok( c.intersectsBox( a ), "Passed!" );
ok( b.intersectsBox( c ), "Passed!" );
b.translate( new THREE.Vector2( 2, 2 ) );
ok( ! a.isIntersectionBox( b ), "Passed!" );
ok( ! b.isIntersectionBox( a ), "Passed!" );
ok( ! b.isIntersectionBox( c ), "Passed!" );
ok( ! a.intersectsBox( b ), "Passed!" );
ok( ! b.intersectsBox( a ), "Passed!" );
ok( ! b.intersectsBox( c ), "Passed!" );
});
test( "intersect", function() {
......
......@@ -204,23 +204,23 @@ test( "distanceToPoint", function() {
ok( b.distanceToPoint( new THREE.Vector3( -2, -2, -2 ) ) == Math.sqrt( 3 ), "Passed!" );
});
test( "isIntersectionBox", function() {
test( "intersectsBox", function() {
var a = new THREE.Box3( zero3.clone(), zero3.clone() );
var b = new THREE.Box3( zero3.clone(), one3.clone() );
var c = new THREE.Box3( one3.clone().negate(), one3.clone() );
ok( a.isIntersectionBox( a ), "Passed!" );
ok( a.isIntersectionBox( b ), "Passed!" );
ok( a.isIntersectionBox( c ), "Passed!" );
ok( a.intersectsBox( a ), "Passed!" );
ok( a.intersectsBox( b ), "Passed!" );
ok( a.intersectsBox( c ), "Passed!" );
ok( b.isIntersectionBox( a ), "Passed!" );
ok( c.isIntersectionBox( a ), "Passed!" );
ok( b.isIntersectionBox( c ), "Passed!" );
ok( b.intersectsBox( a ), "Passed!" );
ok( c.intersectsBox( a ), "Passed!" );
ok( b.intersectsBox( c ), "Passed!" );
b.translate( new THREE.Vector3( 2, 2, 2 ) );
ok( ! a.isIntersectionBox( b ), "Passed!" );
ok( ! b.isIntersectionBox( a ), "Passed!" );
ok( ! b.isIntersectionBox( c ), "Passed!" );
ok( ! a.intersectsBox( b ), "Passed!" );
ok( ! b.intersectsBox( a ), "Passed!" );
ok( ! b.intersectsBox( c ), "Passed!" );
});
test( "getBoundingSphere", function() {
......
......@@ -81,14 +81,14 @@ test( "setComponents", function() {
test( "setFromNormalAndCoplanarPoint", function() {
var normal = one3.clone().normalize();
var a = new THREE.Plane().setFromNormalAndCoplanarPoint( normal, zero3 );
ok( a.normal.equals( normal ), "Passed!" );
ok( a.constant == 0, "Passed!" );
});
test( "normalize", function() {
var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), 2 );
a.normalize();
ok( a.normal.length() == 1, "Passed!" );
ok( a.normal.equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" );
......@@ -97,7 +97,7 @@ test( "normalize", function() {
test( "negate/distanceToPoint", function() {
var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), -2 );
a.normalize();
ok( a.distanceToPoint( new THREE.Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
ok( a.distanceToPoint( new THREE.Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
......@@ -109,7 +109,7 @@ test( "negate/distanceToPoint", function() {
test( "distanceToPoint", function() {
var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), -2 );
a.normalize();
ok( a.distanceToPoint( a.projectPoint( zero3.clone() ) ) === 0, "Passed!" );
ok( a.distanceToPoint( new THREE.Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
......@@ -119,7 +119,7 @@ test( "distanceToSphere", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
var b = new THREE.Sphere( new THREE.Vector3( 2, 0, 0 ), 1 );
ok( a.distanceToSphere( b ) === 1, "Passed!" );
a.set( new THREE.Vector3( 1, 0, 0 ), 2 );
......@@ -132,23 +132,23 @@ test( "isInterestionLine/intersectLine", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
var l1 = new THREE.Line3( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) );
ok( a.isIntersectionLine( l1 ), "Passed!" );
ok( a.intersectsLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), -3 );
ok( a.isIntersectionLine( l1 ), "Passed!" );
ok( a.intersectsLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ).equals( new THREE.Vector3( 3, 0, 0 ) ), "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), -11 );
ok( ! a.isIntersectionLine( l1 ), "Passed!" );
ok( ! a.intersectsLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ) === undefined, "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 11 );
ok( ! a.isIntersectionLine( l1 ), "Passed!" );
ok( ! a.intersectsLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ) === undefined, "Passed!" );
});
......@@ -162,7 +162,7 @@ test( "projectPoint", function() {
a = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), -1 );
ok( a.projectPoint( new THREE.Vector3( 0, 0, 0 ) ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" );
ok( a.projectPoint( new THREE.Vector3( 0, 1, 0 ) ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" );
});
test( "orthoPoint", function() {
......
......@@ -109,7 +109,7 @@ test( "distanceSqToPoint", function() {
ok( d === 0, "Passed!" );
});
test( "isIntersectionSphere", function() {
test( "intersectsSphere", function() {
var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) );
var b = new THREE.Sphere( zero3, 0.5 );
var c = new THREE.Sphere( zero3, 1.5 );
......@@ -117,17 +117,17 @@ test( "isIntersectionSphere", function() {
var e = new THREE.Sphere( two3, 0.1 );
var f = new THREE.Sphere( two3, 1 );
ok( ! a.isIntersectionSphere( b ), "Passed!" );
ok( ! a.isIntersectionSphere( c ), "Passed!" );
ok( a.isIntersectionSphere( d ), "Passed!" );
ok( ! a.isIntersectionSphere( e ), "Passed!" );
ok( ! a.isIntersectionSphere( f ), "Passed!" );
ok( ! a.intersectsSphere( b ), "Passed!" );
ok( ! a.intersectsSphere( c ), "Passed!" );
ok( a.intersectsSphere( d ), "Passed!" );
ok( ! a.intersectsSphere( e ), "Passed!" );
ok( ! a.intersectsSphere( f ), "Passed!" );
});
test( "intersectSphere", function() {
var TOL = 0.0001;
// ray a0 origin located at ( 0, 0, 0 ) and points outward in negative-z direction
var a0 = new THREE.Ray( zero3.clone(), new THREE.Vector3( 0, 0, -1 ) );
// ray a1 origin located at ( 1, 1, 1 ) and points left in negative-x direction
......@@ -136,75 +136,75 @@ test( "intersectSphere", function() {
// sphere (radius of 2) located behind ray a0, should result in null
var b = new THREE.Sphere( new THREE.Vector3( 0, 0, 3 ), 2 );
ok( a0.intersectSphere( b ) === null, "Passed!" );
// sphere (radius of 2) located in front of, but too far right of ray a0, should result in null
var b = new THREE.Sphere( new THREE.Vector3( 3, 0, -1 ), 2 );
ok( a0.intersectSphere( b ) === null, "Passed!" );
// sphere (radius of 2) located below ray a1, should result in null
var b = new THREE.Sphere( new THREE.Vector3( 1, -2, 1 ), 2 );
ok( a1.intersectSphere( b ) === null, "Passed!" );
// sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1
// sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1
var b = new THREE.Sphere( new THREE.Vector3( -1, 1, 1 ), 1 );
ok( a1.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 1, 1 ) ) < TOL, "Passed!" );
// sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1
// sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1
var b = new THREE.Sphere( new THREE.Vector3( 0, 0, -2 ), 1 );
ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -1 ) ) < TOL, "Passed!" );
// sphere (radius of 2) located in front & right of ray a0, should result in intersection at 0, 0, -1, or left-most edge of sphere
// sphere (radius of 2) located in front & right of ray a0, should result in intersection at 0, 0, -1, or left-most edge of sphere
var b = new THREE.Sphere( new THREE.Vector3( 2, 0, -1 ), 2 );
ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -1 ) ) < TOL, "Passed!" );
// same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss
// same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss
var b = new THREE.Sphere( new THREE.Vector3( 2.01, 0, -1 ), 2 );
ok( a0.intersectSphere( b ) === null, "Passed!" );
// following tests are for situations where the ray origin is inside the sphere
// sphere (radius of 1) center located at ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 1,
// sphere (radius of 1) center located at ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 1,
// is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -1
// thus keeping the intersection point always in front of the ray.
var b = new THREE.Sphere( zero3.clone(), 1 );
ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -1 ) ) < TOL, "Passed!" );
// sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5,
// sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5,
// is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -3
// thus keeping the intersection point always in front of the ray.
var b = new THREE.Sphere( new THREE.Vector3( 0, 0, 1 ), 4 );
ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -3 ) ) < TOL, "Passed!" );
// sphere (radius of 4) center located in front of ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 3,
// sphere (radius of 4) center located in front of ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 3,
// is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -5
// thus keeping the intersection point always in front of the ray.
var b = new THREE.Sphere( new THREE.Vector3( 0, 0, -1 ), 4 );
ok( a0.intersectSphere( b ).distanceTo( new THREE.Vector3( 0, 0, -5 ) ) < TOL, "Passed!" );
});
test( "isIntersectionPlane", function() {
test( "intersectsPlane", function() {
var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) );
// parallel plane in front of the ray
var b = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), one3.clone().sub( new THREE.Vector3( 0, 0, -1 ) ) );
ok( a.isIntersectionPlane( b ), "Passed!" );
ok( a.intersectsPlane( b ), "Passed!" );
// parallel plane coincident with origin
var c = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), one3.clone().sub( new THREE.Vector3( 0, 0, 0 ) ) );
ok( a.isIntersectionPlane( c ), "Passed!" );
ok( a.intersectsPlane( c ), "Passed!" );
// parallel plane behind the ray
var d = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), one3.clone().sub( new THREE.Vector3( 0, 0, 1 ) ) );
ok( ! a.isIntersectionPlane( d ), "Passed!" );
ok( ! a.intersectsPlane( d ), "Passed!" );
// perpendical ray that overlaps exactly
var e = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), one3 );
ok( a.isIntersectionPlane( e ), "Passed!" );
ok( a.intersectsPlane( e ), "Passed!" );
// perpendical ray that doesn't overlap
var f = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), zero3 );
ok( ! a.isIntersectionPlane( f ), "Passed!" );
ok( ! a.intersectsPlane( f ), "Passed!" );
});
test( "intersectPlane", function() {
......@@ -295,39 +295,37 @@ test( "distanceSqToSegment", function() {
test( "intersectBox", function() {
var TOL = 0.0001;
var box = new THREE.Box3( new THREE.Vector3( -1, -1, -1 ), new THREE.Vector3( 1, 1, 1 ) );
var a = new THREE.Ray( new THREE.Vector3( -2, 0, 0 ), new THREE.Vector3( 1, 0, 0) );
//ray should intersect box at -1,0,0
ok( a.isIntersectionBox(box) === true, "Passed!" );
ok( a.intersectsBox(box) === true, "Passed!" );
ok( a.intersectBox(box).distanceTo( new THREE.Vector3( -1, 0, 0 ) ) < TOL, "Passed!" );
var b = new THREE.Ray( new THREE.Vector3( -2, 0, 0 ), new THREE.Vector3( -1, 0, 0) );
//ray is point away from box, it should not intersect
ok( b.isIntersectionBox(box) === false, "Passed!" );
ok( b.intersectsBox(box) === false, "Passed!" );
ok( b.intersectBox(box) === null, "Passed!" );
var c = new THREE.Ray( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 1, 0, 0) );
// ray is inside box, should return exit point
ok( c.isIntersectionBox(box) === true, "Passed!" );
ok( c.intersectsBox(box) === true, "Passed!" );
ok( c.intersectBox(box).distanceTo( new THREE.Vector3( 1, 0, 0 ) ) < TOL, "Passed!" );
var d = new THREE.Ray( new THREE.Vector3( 0, 2, 1 ), new THREE.Vector3( 0, -1, -1).normalize() );
//tilted ray should intersect box at 0,1,0
ok( d.isIntersectionBox(box) === true, "Passed!" );
ok( d.intersectBox(box).distanceTo( new THREE.Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
ok( d.intersectsBox(box) === true, "Passed!" );
ok( d.intersectBox(box).distanceTo( new THREE.Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
var e = new THREE.Ray( new THREE.Vector3( 1, -2, 1 ), new THREE.Vector3( 0, 1, 0).normalize() );
//handle case where ray is coplanar with one of the boxes side - box in front of ray
ok( e.isIntersectionBox(box) === true, "Passed!" );
ok( e.intersectBox(box).distanceTo( new THREE.Vector3( 1, -1, 1 ) ) < TOL, "Passed!" );
ok( e.intersectsBox(box) === true, "Passed!" );
ok( e.intersectBox(box).distanceTo( new THREE.Vector3( 1, -1, 1 ) ) < TOL, "Passed!" );
var f = new THREE.Ray( new THREE.Vector3( 1, -2, 0 ), new THREE.Vector3( 0, -1, 0).normalize() );
//handle case where ray is coplanar with one of the boxes side - box behind ray
ok( f.isIntersectionBox(box) === false, "Passed!" );
ok( f.intersectBox(box) == null, "Passed!" );
});
ok( f.intersectsBox(box) === false, "Passed!" );
ok( f.intersectBox(box) == null, "Passed!" );
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册