Browse Source

initial Plane unit tests. problems with higher scope variables being utilized between modules.

Ben Houston 12 years ago
parent
commit
7c097f8373
3 changed files with 109 additions and 1 deletions
  1. 1 1
      test/core/Box2.js
  2. 107 0
      test/core/Plane.js
  3. 1 0
      test/testsuite.html

+ 1 - 1
test/core/Box2.js

@@ -11,7 +11,7 @@ var negInf = new THREE.Vector3( -Infinity, -Infinity );
 var posInf = new THREE.Vector3( Infinity, Infinity );
 var posInf = new THREE.Vector3( Infinity, Infinity );
 
 
 var zero = new THREE.Vector3();
 var zero = new THREE.Vector3();
-var one = new THREE.Vector3( 1, 1 );
+var one = new THREE.Vector3( 1, 1, 1 );
 
 
 module( "Box2" );
 module( "Box2" );
 
 

+ 107 - 0
test/core/Plane.js

@@ -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!" );
+});

+ 1 - 0
test/testsuite.html

@@ -14,5 +14,6 @@
   <script src="core/Vector4.js"></script>
   <script src="core/Vector4.js"></script>
   <script src="core/Box2.js"></script>
   <script src="core/Box2.js"></script>
   <script src="core/Box3.js"></script>
   <script src="core/Box3.js"></script>
+  <script src="core/Plane.js"></script>
 </body>
 </body>
 </html>
 </html>