浏览代码

many more unit tests passing, still ~30 failing.

Ben Houston 12 年之前
父节点
当前提交
c70714deb8
共有 8 个文件被更改,包括 93 次插入31 次删除
  1. 10 7
      src/core/Box2.js
  2. 9 6
      src/core/Box3.js
  3. 13 4
      src/core/Plane.js
  4. 13 3
      src/core/Sphere.js
  5. 42 5
      test/core/Box2.js
  6. 1 1
      test/core/Constants.js
  7. 2 2
      test/core/Plane.js
  8. 3 3
      test/core/Sphere.js

+ 10 - 7
src/core/Box2.js

@@ -11,10 +11,13 @@ THREE.Box2 = function ( min, max ) {
 		this.makeEmpty();
 
 	} else {
-
-		this.min = min || new THREE.Vector2();
-		this.max = max || new THREE.Vector2().copy( this.min ); // This is done on purpose so you can make a box using a single point and then expand it.
-
+		this.min = min.clone();
+		if( max === undefined ) {
+			this.max = new THREE.Vector2().copy( this.min ); // This is done on purpose so you can make a box using a single point and then expand it.
+		}
+		else {
+			this.max = max.clone();
+		}
 	}
 
 };
@@ -25,8 +28,8 @@ THREE.Box2.prototype = {
 
 	set: function ( min, max ) {
 
-		this.min = min;
-		this.max = max;
+		this.min.copy( min );
+		this.max.copy( max );
 
 		return this;
 	},
@@ -112,7 +115,7 @@ THREE.Box2.prototype = {
 
 	},
 
-	area: function () {
+	volume: function () {
 
 		return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y );
 

+ 9 - 6
src/core/Box3.js

@@ -11,10 +11,13 @@ THREE.Box3 = function ( min, max ) {
 		this.makeEmpty();
 
 	} else {
-
-		this.min = min || new THREE.Vector3();
-		this.max = max || new THREE.Vector3().copy( this.min ); // This is done on purpose so you can make a box using a single point and then expand it.
-
+		this.min = min.clone();
+		if( max === undefined ) {
+			this.max = new THREE.Vector3().copy( this.min ); // This is done on purpose so you can make a box using a single point and then expand it.
+		}
+		else {
+			this.max = max.clone();
+		}
 	}
 
 };
@@ -25,8 +28,8 @@ THREE.Box3.prototype = {
 
 	set: function ( min, max ) {
 
-		this.min = min;
-		this.max = max;
+		this.min.copy( min );
+		this.max.copy( max );
 
 		return this;
 

+ 13 - 4
src/core/Plane.js

@@ -4,8 +4,17 @@
 
 THREE.Plane = function ( normal, constant ) {
 
-	this.normal = normal || new THREE.Vector3();
-	this.constant = constant || 0;
+	if ( normal === undefined && constant === undefined ) {
+
+		this.normal = new THREE.Vector3();
+		this.constant = 0;
+
+	} else {
+
+		this.normal = normal.clone();
+		this.constant = constant || 0;
+
+	}
 
 };
 
@@ -15,7 +24,7 @@ THREE.Plane.prototype = {
 
 	set: function ( normal, constant ) {
 
-		this.normal = normal;
+		this.normal.copy( normal );
 		this.constant = constant;
 
 		return this;
@@ -33,7 +42,7 @@ THREE.Plane.prototype = {
 
 	setFromNormalAndCoplanarPoint: function ( normal, point ) {
 
-		this.normal = normal;
+		this.normal.copy( normal );
 		this.constant = - point.dot( normal );
 
 		return this;

+ 13 - 3
src/core/Sphere.js

@@ -4,9 +4,19 @@
 
 THREE.Sphere = function ( center, radius ) {
 
-	this.center = center || new THREE.Vector3();
-	this.radius = radius || 0;
 
+	if ( center === undefined && radius === undefined ) {
+
+		this.center = new THREE.Vector3();
+		this.radius = 0;
+
+	} else {
+
+		this.center = center.clone();
+		this.radius = radius || 0;
+
+	}
+	
 };
 
 THREE.Sphere.prototype = {
@@ -15,7 +25,7 @@ THREE.Sphere.prototype = {
 
 	set: function ( center, radius ) {
 
-		this.center = center;
+		this.center.copy( center );
 		this.radius = radius;
 
 		return this;

+ 42 - 5
test/core/Box2.js

@@ -4,6 +4,14 @@
 
 module( "Box2" );
 
+test( "verifyConstants=beginning", function() {
+	ok( negInf.equals( new THREE.Vector3( -Infinity, -Infinity ) ), "Passed!" );
+	ok( posInf.equals( new THREE.Vector3( Infinity, Infinity ) ), "Passed!" );
+	ok( zero.equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( one.equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+	ok( two.equals( new THREE.Vector3( 2, 2, 2 ) ), "Passed!" );
+});
+
 test( "constructor", function() {
 	var a = new THREE.Box2();
 	ok( a.min.equals( posInf ), "Passed!" );
@@ -15,9 +23,13 @@ test( "constructor", function() {
 
 	a = new THREE.Box2( zero, one );
 	ok( a.min.equals( zero ), "Passed!" );
+	console.log( "constructor");
+	console.log( a );
+	console.log( one );
 	ok( a.max.equals( one ), "Passed!" );
 });
 
+
 test( "copy", function() {
 	var a = new THREE.Box2( zero, one );
 	var b = new THREE.Box2().copy( a );
@@ -51,9 +63,12 @@ test( "empty/makeEmpty", function() {
 	ok( a.empty(), "Passed!" );
 });
 
-test( "area", function() {
+test( "volume", function() {
 	var a = new THREE.Box2( zero, one );
-	ok( a.area() == 1, "Passed!" );
+	ok( a.volume() == 1, "Passed!" );
+
+	a = new THREE.Box2( one.clone().negate(), zero );
+	ok( a.volume() == 1, "Passed!" );
 });
 
 test( "center", function() {
@@ -66,6 +81,14 @@ test( "center", function() {
 	ok( a.center().equals( midpoint ), "Passed!" );
 });
 
+test( "verifyConstants1", function() {
+	ok( negInf.equals( new THREE.Vector3( -Infinity, -Infinity ) ), "Passed!" );
+	ok( posInf.equals( new THREE.Vector3( Infinity, Infinity ) ), "Passed!" );
+	ok( zero.equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( one.equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+	ok( two.equals( new THREE.Vector3( 2, 2, 2 ) ), "Passed!" );
+});
+
 test( "size", function() {
 	var a = new THREE.Box2( zero );
 
@@ -86,8 +109,10 @@ test( "expandByPoint", function() {
 
 	a.expandByPoint( one.clone().negate() );
 	ok( a.size().equals( one.clone().multiplyScalar( 2 ) ), "Passed!" );
+	console.log( "expandByPoint" );
 	console.log( a );
 	console.log( a.center() );
+	console.log( zero  );
 	ok( a.center().equals( zero ), "Passed!" );
 });
 
@@ -155,7 +180,7 @@ test( "getParameter", function() {
 });
 
 test( "clampPoint", function() {
-	var a = new THREE.Box2( zero, one );
+	var a = new THREE.Box2( zero, zero );
 	var b = new THREE.Box2( one.clone().negate(), one );
 
 	ok( a.clampPoint( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
@@ -170,7 +195,7 @@ test( "clampPoint", function() {
 });
 
 test( "distanceToPoint", function() {
-	var a = new THREE.Box2( zero, one );
+	var a = new THREE.Box2( zero, zero );
 	var b = new THREE.Box2( one.clone().negate(), one );
 
 	ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
@@ -185,7 +210,7 @@ test( "distanceToPoint", function() {
 });
 
 test( "distanceToPoint", function() {
-	var a = new THREE.Box2( zero, one );
+	var a = new THREE.Box2( zero, zero );
 	var b = new THREE.Box2( one.clone().negate(), one );
 
 	ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
@@ -213,6 +238,10 @@ test( "isIntersection", function() {
 	ok( b.isIntersection( c ), "Passed!" );
 
 	b.translate( new THREE.Vector2( 2, 2 ) );
+	console.log( "isIntersection");
+	console.log( a );
+	console.log( b );
+	console.log( c );
 	ok( ! a.isIntersection( b ), "Passed!" );
 	ok( ! b.isIntersection( a ), "Passed!" );
 	ok( ! c.isIntersection( a ), "Passed!" );
@@ -265,3 +294,11 @@ test( "scale", function() {
 	ok( b.clone().scale( 2 ).equals( new THREE.Box2( zero, new THREE.Vector2( 2, 2 ) ) ), "Passed!" );
 	ok( d.clone().scale( 2 ).equals( new THREE.Box2( new THREE.Vector2( 2, 2 ).negate(), zero ) ), "Passed!" );
 });
+
+test( "verifyConstants-end", function() {
+	ok( negInf.equals( new THREE.Vector3( -Infinity, -Infinity ) ), "Passed!" );
+	ok( posInf.equals( new THREE.Vector3( Infinity, Infinity ) ), "Passed!" );
+	ok( zero.equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( one.equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+	ok( two.equals( new THREE.Vector3( 2, 2, 2 ) ), "Passed!" );
+});

+ 1 - 1
test/core/Constants.js

@@ -12,4 +12,4 @@ var posInf = new THREE.Vector3( Infinity, Infinity );
 
 var zero = new THREE.Vector3();
 var one = new THREE.Vector3( 1, 1, 1 );
-var two = new THREE.Vector3( 1, 1, 1 );
+var two = new THREE.Vector3( 2, 2, 2 );

+ 2 - 2
test/core/Plane.js

@@ -87,10 +87,10 @@ test( "flip", function() {
 });
 
 test( "normalize", function() {
-	var a = new THREE.Plane( two, 2 );
+	var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), 2 );
 	
 	a.normalize();
 	ok( a.normal.length() == 1, "Passed!" );
-	ok( a.normal.equals( one ), "Passed!" );
+	ok( a.normal.equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" );
 	ok( a.constant == 1, "Passed!" );
 });

+ 3 - 3
test/core/Sphere.js

@@ -11,7 +11,7 @@ test( "constructor", function() {
 
 	a = new THREE.Sphere( one, 1 );
 	ok( a.center.equals( one ), "Passed!" );
-	ok( a.radius == 0, "Passed!" );
+	ok( a.radius == 1, "Passed!" );
 });
 
 test( "copy", function() {
@@ -19,13 +19,13 @@ test( "copy", function() {
 	var b = new THREE.Sphere().copy( a );
 
 	ok( b.center.equals( one ), "Passed!" );
-	ok( b.radius == 0, "Passed!" );
+	ok( b.radius == 1, "Passed!" );
 
 	// ensure that it is a true copy
 	a.center = zero;
 	a.radius = 0;
 	ok( b.center.equals( one ), "Passed!" );
-	ok( b.radius == 0, "Passed!" );
+	ok( b.radius == 1, "Passed!" );
 });
 
 test( "set", function() {