Sfoglia il codice sorgente

incorporate Line3 into Plane.

Ben Houston 12 anni fa
parent
commit
3c5986bf79
2 ha cambiato i file con 18 aggiunte e 17 eliminazioni
  1. 9 9
      src/math/Plane.js
  2. 9 8
      test/unit/math/Plane.js

+ 9 - 9
src/math/Plane.js

@@ -115,12 +115,12 @@ THREE.extend( THREE.Plane.prototype, {
 
 
 	},
 	},
 
 
-	isIntersectionLine: function ( startPoint, endPoint ) {
+	isIntersectionLine: function ( line ) {
 
 
 		// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
 		// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
 
 
-		var startSign = this.distanceToPoint( startPoint );
-		var endSign = this.distanceToPoint( endPoint );
+		var startSign = this.distanceToPoint( line.start );
+		var endSign = this.distanceToPoint( line.end );
 
 
 		return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
 		return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
 
 
@@ -130,20 +130,20 @@ THREE.extend( THREE.Plane.prototype, {
 
 
 		var v1 = new THREE.Vector3();
 		var v1 = new THREE.Vector3();
 
 
-		return function ( startPoint, endPoint, optionalTarget ) {
+		return function ( line, optionalTarget ) {
 
 
 			var result = optionalTarget || new THREE.Vector3();
 			var result = optionalTarget || new THREE.Vector3();
 
 
-			var direction = v1.subVectors( endPoint, startPoint );
+			var direction = line.delta( v1 );
 
 
 			var denominator = this.normal.dot( direction );
 			var denominator = this.normal.dot( direction );
 
 
 			if ( denominator == 0 ) {
 			if ( denominator == 0 ) {
 
 
 				// line is coplanar, return origin
 				// line is coplanar, return origin
-				if( this.distanceToPoint( startPoint ) == 0 ) {
+				if( this.distanceToPoint( line.start ) == 0 ) {
 
 
-					return result.copy( startPoint );
+					return result.copy( line.start );
 
 
 				}
 				}
 
 
@@ -152,7 +152,7 @@ THREE.extend( THREE.Plane.prototype, {
 
 
 			}
 			}
 
 
-			var t = - ( startPoint.dot( this.normal ) + this.constant ) / denominator;
+			var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
 
 
 			if( t < 0 || t > 1 ) {
 			if( t < 0 || t > 1 ) {
 
 
@@ -160,7 +160,7 @@ THREE.extend( THREE.Plane.prototype, {
 
 
 			}
 			}
 
 
-			return result.copy( direction ).multiplyScalar( t ).add( startPoint );
+			return result.copy( direction ).multiplyScalar( t ).add( line.start );
 
 
 		};
 		};
 
 

+ 9 - 8
test/unit/math/Plane.js

@@ -131,24 +131,25 @@ test( "distanceToSphere", function() {
 test( "isInterestionLine/intersectLine", function() {
 test( "isInterestionLine/intersectLine", function() {
 	var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
 	var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
 
 
-	ok( a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
-	ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	var l1 = new THREE.Line3( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) );
+	ok( a.isIntersectionLine( 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 );
 	a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), -3 );
 
 
-	ok( a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
-	ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ).equals( new THREE.Vector3( 3, 0, 0 ) ), "Passed!" );
+	ok( a.isIntersectionLine( 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 );
 	a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), -11 );
 
 
-	ok( ! a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
-	ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ) === undefined, "Passed!" );
+	ok( ! a.isIntersectionLine( l1 ), "Passed!" );
+	ok( a.intersectLine( l1 ) === undefined, "Passed!" );
 	
 	
 	a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 11 );
 	a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 11 );
 
 
-	ok( ! a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
-	ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ) === undefined, "Passed!" );
+	ok( ! a.isIntersectionLine( l1 ), "Passed!" );
+	ok( a.intersectLine( l1 ) === undefined, "Passed!" );
 
 
 });
 });