|
@@ -0,0 +1,107 @@
|
|
|
|
+/**
|
|
|
|
+ * @author bhouston / http://exocortex.com
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+x = 2;
|
|
|
|
+y = 3;
|
|
|
|
+z = 4;
|
|
|
|
+w = 5;
|
|
|
|
+
|
|
|
|
+zero = new THREE.Vector3();
|
|
|
|
+one = new THREE.Vector3( 1, 1, 1 );
|
|
|
|
+two = new THREE.Vector3( 1, 1, 1 );
|
|
|
|
+
|
|
|
|
+module( "Plane" );
|
|
|
|
+
|
|
|
|
+test( "constructor", function() {
|
|
|
|
+ var a = new THREE.Plane();
|
|
|
|
+ ok( a.normal.x == 0, "Passed!" );
|
|
|
|
+ ok( a.normal.y == 0, "Passed!" );
|
|
|
|
+ ok( a.normal.z == 0, "Passed!" );
|
|
|
|
+ ok( a.constant == 0, "Passed!" );
|
|
|
|
+
|
|
|
|
+ console.log( one );
|
|
|
|
+
|
|
|
|
+ a = new THREE.Plane( one, 0 );
|
|
|
|
+ ok( a.normal.x == 1, "Passed!" );
|
|
|
|
+ ok( a.normal.y == 1, "Passed!" );
|
|
|
|
+ ok( a.normal.z == 1, "Passed!" );
|
|
|
|
+ ok( a.constant == 0, "Passed!" );
|
|
|
|
+
|
|
|
|
+ a = new THREE.Plane( one, 1 );
|
|
|
|
+ ok( a.normal.x == 1, "Passed!" );
|
|
|
|
+ ok( a.normal.y == 1, "Passed!" );
|
|
|
|
+ ok( a.normal.z == 1, "Passed!" );
|
|
|
|
+ ok( a.constant == 1, "Passed!" );
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+test( "copy", function() {
|
|
|
|
+ var a = new THREE.Plane( new THREE.Vector3( x, y, z ), w );
|
|
|
|
+ var b = new THREE.Plane().copy( a );
|
|
|
|
+ ok( b.normal.x == x, "Passed!" );
|
|
|
|
+ ok( b.normal.y == y, "Passed!" );
|
|
|
|
+ ok( b.normal.z == z, "Passed!" );
|
|
|
|
+ ok( b.constant == w, "Passed!" );
|
|
|
|
+
|
|
|
|
+ // ensure that it is a true copy
|
|
|
|
+ a.normal.x = 0;
|
|
|
|
+ a.normal.y = -1;
|
|
|
|
+ a.normal.z = -2;
|
|
|
|
+ a.constant = -3;
|
|
|
|
+ ok( b.normal.x == x, "Passed!" );
|
|
|
|
+ ok( b.normal.y == y, "Passed!" );
|
|
|
|
+ ok( b.normal.z == z, "Passed!" );
|
|
|
|
+ ok( b.constant == w, "Passed!" );
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+test( "set", function() {
|
|
|
|
+ var a = new THREE.Plane();
|
|
|
|
+ ok( a.normal.x == 0, "Passed!" );
|
|
|
|
+ ok( a.normal.y == 0, "Passed!" );
|
|
|
|
+ ok( a.normal.z == 0, "Passed!" );
|
|
|
|
+ ok( a.constant == 0, "Passed!" );
|
|
|
|
+
|
|
|
|
+ var b = a.clone().set( new THREE.Vector3( x, y, z ), w );
|
|
|
|
+ ok( b.normal.x == x, "Passed!" );
|
|
|
|
+ ok( b.normal.y == y, "Passed!" );
|
|
|
|
+ ok( b.normal.z == z, "Passed!" );
|
|
|
|
+ ok( b.constant == w, "Passed!" );
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+test( "setComponents", function() {
|
|
|
|
+ var a = new THREE.Plane();
|
|
|
|
+ ok( a.normal.x == 0, "Passed!" );
|
|
|
|
+ ok( a.normal.y == 0, "Passed!" );
|
|
|
|
+ ok( a.normal.z == 0, "Passed!" );
|
|
|
|
+ ok( a.constant == 0, "Passed!" );
|
|
|
|
+
|
|
|
|
+ var b = a.clone().setComponents( x, y, z , w );
|
|
|
|
+ ok( b.normal.x == x, "Passed!" );
|
|
|
|
+ ok( b.normal.y == y, "Passed!" );
|
|
|
|
+ ok( b.normal.z == z, "Passed!" );
|
|
|
|
+ ok( b.constant == w, "Passed!" );
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+test( "setFromNormalAndCoplanarPoint", function() {
|
|
|
|
+ var a = new THREE.Plane().setFromNormalAndCoplanarPoint( one, zero );
|
|
|
|
+
|
|
|
|
+ ok( a.normal.equals( one ), "Passed!" );
|
|
|
|
+ ok( a.constant == 0, "Passed!" );
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+test( "flip", function() {
|
|
|
|
+ var a = new THREE.Plane( one, 0 );
|
|
|
|
+
|
|
|
|
+ ok( a.normal.equals( one ), "Passed!" );
|
|
|
|
+ a.flip();
|
|
|
|
+ ok( a.normal.negate().equals( one ), "Passed!" );
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+test( "normalize", function() {
|
|
|
|
+ var a = new THREE.Plane( two, 2 );
|
|
|
|
+
|
|
|
|
+ a.normalize();
|
|
|
|
+ ok( a.normal.length() == 1, "Passed!" );
|
|
|
|
+ ok( a.normal.equals( one ), "Passed!" );
|
|
|
|
+ ok( a.constant == 1, "Passed!" );
|
|
|
|
+});
|