Browse Source

cleaning up unit tests for Sphere, Box2, Box3, Plane.

Ben Houston 12 years ago
parent
commit
7c6a44ad02
7 changed files with 31 additions and 14 deletions
  1. 1 3
      src/core/Box3.js
  2. 3 4
      src/core/Plane.js
  3. 9 0
      src/core/Vector2.js
  4. 11 0
      src/core/Vector4.js
  5. 3 3
      test/core/Box2.js
  6. 2 2
      test/core/Box3.js
  7. 2 2
      test/core/Sphere.js

+ 1 - 3
src/core/Box3.js

@@ -7,9 +7,7 @@ THREE.Box3 = function ( min, max ) {
 	if( ! min && ! max ) {			
 		this.min = new THREE.Vector3();
 		this.max = new THREE.Vector3();
-		this.min.x = this.min.y = this.min.z = Infinity;
-		this.max.x = this.max.y = this.max.z = -Infinity;
-		console.log( this );
+		this.makeEmpty();
 	}
 	else {
 		this.min = min || new THREE.Vector3();

+ 3 - 4
src/core/Plane.js

@@ -39,8 +39,8 @@ THREE.Plane.prototype = {
 
 	setFromCoplanarPoints: function ( a, b, c ) {
 
-		var normal = THREE.Plane3.__v1.sub( b, a ).cross(
-			THREE.Plane3.__v2.sub( c, a ) );
+		var normal = THREE.Plane.__v1.sub( b, a ).cross(
+			THREE.Plane.__v2.sub( c, a ) );
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 		this.setFromNormalAndCoplanarPoint( normal, a );
@@ -124,8 +124,7 @@ THREE.Plane.prototype = {
 
 	clone: function () {
 
-		return new THREE.Plane3().copy( this );
-
+		return new THREE.Plane().copy( this );
 	}
 
 };

+ 9 - 0
src/core/Vector2.js

@@ -50,6 +50,15 @@ THREE.Vector2.prototype = {
 
 	},
 
+	addScalar: function ( s ) {
+
+		this.x += s;
+		this.y += s;
+
+		return this;
+
+	},
+
 	add: function ( a, b ) {
 
 		this.x = a.x + b.x;

+ 11 - 0
src/core/Vector4.js

@@ -73,6 +73,17 @@ THREE.Vector4.prototype = {
 
 	},
 
+	addScalar: function ( s ) {
+
+		this.x += s;
+		this.y += s;
+		this.z += s;
+		this.w += s;
+
+		return this;
+
+	},
+
 	add: function ( a, b ) {
 
 		this.x = a.x + b.x;

+ 3 - 3
test/core/Box2.js

@@ -1,4 +1,4 @@
-/**
+	/**
  * @author bhouston / http://exocortex.com
  */
 
@@ -107,7 +107,7 @@ test( "expandByScalar", function() {
 	ok( a.size().equals( zero ), "Passed!" );
 
 	a.expandByScalar( 1 );
-	ok( a.size().equals( oneone.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.size().equals( one.clone().multiplyScalar( 2 ) ), "Passed!" );
 	ok( a.center().equals( zero ), "Passed!" );
 });
 
@@ -207,7 +207,7 @@ test( "isIntersection", function() {
 	ok( c.isIntersection( a ), "Passed!" );
 	ok( b.isIntersection( c ), "Passed!" );
 
-	b.translate( one.clone().translate( new THREE.Vector2( 2, 2 ) ));
+	b.translate( new THREE.Vector2( 2, 2 ) );
 	ok( ! a.isIntersection( b ), "Passed!" );
 	ok( ! b.isIntersection( a ), "Passed!" );
 	ok( ! c.isIntersection( a ), "Passed!" );

+ 2 - 2
test/core/Box3.js

@@ -107,7 +107,7 @@ test( "expandByScalar", function() {
 	ok( a.size().equals( zero ), "Passed!" );
 
 	a.expandByScalar( 1 );
-	ok( a.size().equals( oneone.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.size().equals( one.clone().multiplyScalar( 2 ) ), "Passed!" );
 	ok( a.center().equals( zero ), "Passed!" );
 });
 
@@ -207,7 +207,7 @@ test( "isIntersection", function() {
 	ok( c.isIntersection( a ), "Passed!" );
 	ok( b.isIntersection( c ), "Passed!" );
 
-	b.translate( one.clone().translate( new THREE.Vector3( 2, 2, 2 ) ));
+	b.translate( new THREE.Vector3( 2, 2, 2 ) );
 	ok( ! a.isIntersection( b ), "Passed!" );
 	ok( ! b.isIntersection( a ), "Passed!" );
 	ok( ! c.isIntersection( a ), "Passed!" );

+ 2 - 2
test/core/Sphere.js

@@ -33,7 +33,7 @@ test( "set", function() {
 	ok( a.center.equals( zero ), "Passed!" );
 	ok( a.radius == 0, "Passed!" );
 
-	a.set( one, radius )
+	a.set( one, 1 )
 	ok( a.center.equals( one ), "Passed!" );
-	ok( a.radius == 0, "Passed!" );
+	ok( a.radius == 1, "Passed!" );
 });