|
@@ -64,25 +64,33 @@ test( "recast/clone", function() {
|
|
|
test( "closestPointToPoint", function() {
|
|
|
var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
|
|
- // nearby the ray
|
|
|
+ // behind the ray
|
|
|
var b = a.closestPointToPoint( zero3 );
|
|
|
- ok( b.equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
|
|
|
+ ok( b.equals( one3 ), "Passed!" );
|
|
|
+
|
|
|
+ // front of the ray
|
|
|
+ var c = a.closestPointToPoint( new THREE.Vector3( 0, 0, 50 ) );
|
|
|
+ ok( c.equals( new THREE.Vector3( 1, 1, 50 ) ), "Passed!" );
|
|
|
|
|
|
// exactly on the ray
|
|
|
- var c = a.closestPointToPoint( one3 );
|
|
|
- ok( c.equals( one3 ), "Passed!" );
|
|
|
+ var d = a.closestPointToPoint( one3 );
|
|
|
+ ok( d.equals( one3 ), "Passed!" );
|
|
|
});
|
|
|
|
|
|
test( "distanceToPoint", function() {
|
|
|
var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
|
|
- // nearby the ray
|
|
|
+ // behind the ray
|
|
|
var b = a.distanceToPoint( zero3 );
|
|
|
- ok( b == Math.sqrt( 2 ), "Passed!" );
|
|
|
+ ok( b === Math.sqrt( 3 ), "Passed!" );
|
|
|
+
|
|
|
+ // front of the ray
|
|
|
+ var c = a.distanceToPoint( new THREE.Vector3( 0, 0, 50 ) );
|
|
|
+ ok( c === Math.sqrt( 2 ), "Passed!" );
|
|
|
|
|
|
// exactly on the ray
|
|
|
- var c = a.distanceToPoint( one3 );
|
|
|
- ok( c == 0, "Passed!" );
|
|
|
+ var d = a.distanceToPoint( one3 );
|
|
|
+ ok( d === 0, "Passed!" );
|
|
|
});
|
|
|
|
|
|
test( "isIntersectionSphere", function() {
|
|
@@ -94,7 +102,7 @@ test( "isIntersectionSphere", function() {
|
|
|
var f = new THREE.Sphere( two3, 1 );
|
|
|
|
|
|
ok( ! a.isIntersectionSphere( b ), "Passed!" );
|
|
|
- ok( a.isIntersectionSphere( c ), "Passed!" );
|
|
|
+ ok( ! a.isIntersectionSphere( c ), "Passed!" );
|
|
|
ok( a.isIntersectionSphere( d ), "Passed!" );
|
|
|
ok( ! a.isIntersectionSphere( e ), "Passed!" );
|
|
|
ok( ! a.isIntersectionSphere( f ), "Passed!" );
|
|
@@ -103,7 +111,7 @@ test( "isIntersectionSphere", function() {
|
|
|
test( "isIntersectionPlane", function() {
|
|
|
var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
|
|
- // parallel plane behind
|
|
|
+ // 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!" );
|
|
|
|
|
@@ -111,9 +119,9 @@ test( "isIntersectionPlane", function() {
|
|
|
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!" );
|
|
|
|
|
|
- // parallel plane infront
|
|
|
+ // 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.isIntersectionPlane( d ), "Passed!" );
|
|
|
|
|
|
// perpendical ray that overlaps exactly
|
|
|
var e = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), one3 );
|
|
@@ -129,15 +137,15 @@ test( "intersectPlane", function() {
|
|
|
|
|
|
// parallel plane behind
|
|
|
var b = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 1, 1, -1 ) );
|
|
|
- ok( a.intersectPlane( b ).equals( new THREE.Vector3( 1, 1, -1 ) ), "Passed!" );
|
|
|
+ ok( a.intersectPlane( b ) === null, "Passed!" );
|
|
|
|
|
|
// parallel plane coincident with origin
|
|
|
var c = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 1, 1, 0 ) );
|
|
|
- ok( a.intersectPlane( c ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
|
|
|
+ ok( a.intersectPlane( c ) === null, "Passed!" );
|
|
|
|
|
|
// parallel plane infront
|
|
|
var d = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 1, 1, 1 ) );
|
|
|
- ok( a.intersectPlane( d ).equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
|
|
|
+ ok( a.intersectPlane( d ).equals( a.origin ), "Passed!" );
|
|
|
|
|
|
// perpendical ray that overlaps exactly
|
|
|
var e = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), one3 );
|
|
@@ -145,7 +153,7 @@ test( "intersectPlane", function() {
|
|
|
|
|
|
// perpendical ray that doesn't overlap
|
|
|
var f = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3( 1, 0, 0 ), zero3 );
|
|
|
- ok( a.intersectPlane( f ) === undefined, "Passed!" );
|
|
|
+ ok( a.intersectPlane( f ) === null, "Passed!" );
|
|
|
});
|
|
|
|
|
|
|
|
@@ -174,19 +182,38 @@ test( "applyMatrix4", function() {
|
|
|
});
|
|
|
|
|
|
|
|
|
-test( "distanceSqAndPointToSegment4", function() {
|
|
|
+test( "distanceToSegment", function() {
|
|
|
var a = new THREE.Ray( one3.clone(), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
- var v0 = new THREE.Vector3( 3, 5, 50 );
|
|
|
- var v1 = new THREE.Vector3( 50, 50, 50 ); // just a far away point
|
|
|
var ptOnLine = new THREE.Vector3();
|
|
|
var ptOnSegment = new THREE.Vector3();
|
|
|
- var distSqr = a.distanceSqAndPointToSegment( v0, v1, ptOnLine, ptOnSegment );
|
|
|
- var m = new THREE.Matrix4();
|
|
|
+
|
|
|
+ //segment in front of the ray
|
|
|
+ var v0 = new THREE.Vector3( 3, 5, 50 );
|
|
|
+ var v1 = new THREE.Vector3( 50, 50, 50 ); // just a far away point
|
|
|
+ var distSqr = a.distanceToSegment( v0, v1, ptOnLine, ptOnSegment );
|
|
|
|
|
|
ok( ptOnSegment.distanceTo( v0 ) < 0.0001, "Passed!" );
|
|
|
ok( ptOnLine.distanceTo( new THREE.Vector3(1, 1, 50) ) < 0.0001, "Passed!" );
|
|
|
// ((3-1) * (3-1) + (5-1) * (5-1) = 4 + 16 = 20
|
|
|
- ok( distSqr === 20, "Passed!" );
|
|
|
+ ok( Math.abs( distSqr - 20 ) < 0.0001, "Passed!" );
|
|
|
+
|
|
|
+ //segment behind the ray
|
|
|
+ v0 = new THREE.Vector3( -50, -50, -50 ); // just a far away point
|
|
|
+ v1 = new THREE.Vector3( -3, -5, -4 );
|
|
|
+ distSqr = a.distanceToSegment( v0, v1, ptOnLine, ptOnSegment );
|
|
|
+
|
|
|
+ ok( ptOnSegment.distanceTo( v1 ) < 0.0001, "Passed!" );
|
|
|
+ ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
|
|
|
+ // ((-3-1) * (-3-1) + (-5-1) * (-5-1) + (-4-1) + (-4-1) = 16 + 36 + 25 = 77
|
|
|
+ ok( Math.abs( distSqr - 77 ) < 0.0001, "Passed!" );
|
|
|
+
|
|
|
+ //exact intersection between the ray and the segment
|
|
|
+ v0 = new THREE.Vector3( -50, -50, -50 );
|
|
|
+ v1 = new THREE.Vector3( 50, 50, 50 );
|
|
|
+ distSqr = a.distanceToSegment( v0, v1, ptOnLine, ptOnSegment );
|
|
|
+
|
|
|
+ ok( ptOnSegment.distanceTo( one3 ) < 0.0001, "Passed!" );
|
|
|
+ ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
|
|
|
+ ok( distSqr < 0.0001, "Passed!" );
|
|
|
});
|
|
|
|
|
|
-
|