提交 c70714de 编写于 作者: B Ben Houston

many more unit tests passing, still ~30 failing.

上级 3e20c628
...@@ -11,10 +11,13 @@ THREE.Box2 = function ( min, max ) { ...@@ -11,10 +11,13 @@ THREE.Box2 = function ( min, max ) {
this.makeEmpty(); this.makeEmpty();
} else { } else {
this.min = min.clone();
this.min = min || new THREE.Vector2(); if( max === undefined ) {
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.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 = { ...@@ -25,8 +28,8 @@ THREE.Box2.prototype = {
set: function ( min, max ) { set: function ( min, max ) {
this.min = min; this.min.copy( min );
this.max = max; this.max.copy( max );
return this; return this;
}, },
...@@ -112,7 +115,7 @@ THREE.Box2.prototype = { ...@@ -112,7 +115,7 @@ THREE.Box2.prototype = {
}, },
area: function () { volume: function () {
return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y ); return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y );
......
...@@ -11,10 +11,13 @@ THREE.Box3 = function ( min, max ) { ...@@ -11,10 +11,13 @@ THREE.Box3 = function ( min, max ) {
this.makeEmpty(); this.makeEmpty();
} else { } else {
this.min = min.clone();
this.min = min || new THREE.Vector3(); if( max === undefined ) {
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.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 = { ...@@ -25,8 +28,8 @@ THREE.Box3.prototype = {
set: function ( min, max ) { set: function ( min, max ) {
this.min = min; this.min.copy( min );
this.max = max; this.max.copy( max );
return this; return this;
......
...@@ -4,8 +4,17 @@ ...@@ -4,8 +4,17 @@
THREE.Plane = function ( normal, constant ) { THREE.Plane = function ( normal, constant ) {
this.normal = normal || new THREE.Vector3(); if ( normal === undefined && constant === undefined ) {
this.constant = constant || 0;
this.normal = new THREE.Vector3();
this.constant = 0;
} else {
this.normal = normal.clone();
this.constant = constant || 0;
}
}; };
...@@ -15,7 +24,7 @@ THREE.Plane.prototype = { ...@@ -15,7 +24,7 @@ THREE.Plane.prototype = {
set: function ( normal, constant ) { set: function ( normal, constant ) {
this.normal = normal; this.normal.copy( normal );
this.constant = constant; this.constant = constant;
return this; return this;
...@@ -33,7 +42,7 @@ THREE.Plane.prototype = { ...@@ -33,7 +42,7 @@ THREE.Plane.prototype = {
setFromNormalAndCoplanarPoint: function ( normal, point ) { setFromNormalAndCoplanarPoint: function ( normal, point ) {
this.normal = normal; this.normal.copy( normal );
this.constant = - point.dot( normal ); this.constant = - point.dot( normal );
return this; return this;
......
...@@ -4,9 +4,19 @@ ...@@ -4,9 +4,19 @@
THREE.Sphere = function ( center, radius ) { 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 = { THREE.Sphere.prototype = {
...@@ -15,7 +25,7 @@ THREE.Sphere.prototype = { ...@@ -15,7 +25,7 @@ THREE.Sphere.prototype = {
set: function ( center, radius ) { set: function ( center, radius ) {
this.center = center; this.center.copy( center );
this.radius = radius; this.radius = radius;
return this; return this;
......
...@@ -4,6 +4,14 @@ ...@@ -4,6 +4,14 @@
module( "Box2" ); 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() { test( "constructor", function() {
var a = new THREE.Box2(); var a = new THREE.Box2();
ok( a.min.equals( posInf ), "Passed!" ); ok( a.min.equals( posInf ), "Passed!" );
...@@ -15,9 +23,13 @@ test( "constructor", function() { ...@@ -15,9 +23,13 @@ test( "constructor", function() {
a = new THREE.Box2( zero, one ); a = new THREE.Box2( zero, one );
ok( a.min.equals( zero ), "Passed!" ); ok( a.min.equals( zero ), "Passed!" );
console.log( "constructor");
console.log( a );
console.log( one );
ok( a.max.equals( one ), "Passed!" ); ok( a.max.equals( one ), "Passed!" );
}); });
test( "copy", function() { test( "copy", function() {
var a = new THREE.Box2( zero, one ); var a = new THREE.Box2( zero, one );
var b = new THREE.Box2().copy( a ); var b = new THREE.Box2().copy( a );
...@@ -51,9 +63,12 @@ test( "empty/makeEmpty", function() { ...@@ -51,9 +63,12 @@ test( "empty/makeEmpty", function() {
ok( a.empty(), "Passed!" ); ok( a.empty(), "Passed!" );
}); });
test( "area", function() { test( "volume", function() {
var a = new THREE.Box2( zero, one ); 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() { test( "center", function() {
...@@ -66,6 +81,14 @@ test( "center", function() { ...@@ -66,6 +81,14 @@ test( "center", function() {
ok( a.center().equals( midpoint ), "Passed!" ); 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() { test( "size", function() {
var a = new THREE.Box2( zero ); var a = new THREE.Box2( zero );
...@@ -86,8 +109,10 @@ test( "expandByPoint", function() { ...@@ -86,8 +109,10 @@ test( "expandByPoint", function() {
a.expandByPoint( one.clone().negate() ); a.expandByPoint( one.clone().negate() );
ok( a.size().equals( one.clone().multiplyScalar( 2 ) ), "Passed!" ); ok( a.size().equals( one.clone().multiplyScalar( 2 ) ), "Passed!" );
console.log( "expandByPoint" );
console.log( a ); console.log( a );
console.log( a.center() ); console.log( a.center() );
console.log( zero );
ok( a.center().equals( zero ), "Passed!" ); ok( a.center().equals( zero ), "Passed!" );
}); });
...@@ -155,7 +180,7 @@ test( "getParameter", function() { ...@@ -155,7 +180,7 @@ test( "getParameter", function() {
}); });
test( "clampPoint", 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 ); var b = new THREE.Box2( one.clone().negate(), one );
ok( a.clampPoint( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" ); ok( a.clampPoint( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
...@@ -170,7 +195,7 @@ test( "clampPoint", function() { ...@@ -170,7 +195,7 @@ test( "clampPoint", function() {
}); });
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 ); var b = new THREE.Box2( one.clone().negate(), one );
ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" ); ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
...@@ -185,7 +210,7 @@ test( "distanceToPoint", function() { ...@@ -185,7 +210,7 @@ test( "distanceToPoint", function() {
}); });
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 ); var b = new THREE.Box2( one.clone().negate(), one );
ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" ); ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
...@@ -213,6 +238,10 @@ test( "isIntersection", function() { ...@@ -213,6 +238,10 @@ test( "isIntersection", function() {
ok( b.isIntersection( c ), "Passed!" ); ok( b.isIntersection( c ), "Passed!" );
b.translate( new THREE.Vector2( 2, 2 ) ); 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( ! a.isIntersection( b ), "Passed!" );
ok( ! b.isIntersection( a ), "Passed!" ); ok( ! b.isIntersection( a ), "Passed!" );
ok( ! c.isIntersection( a ), "Passed!" ); ok( ! c.isIntersection( a ), "Passed!" );
...@@ -265,3 +294,11 @@ test( "scale", function() { ...@@ -265,3 +294,11 @@ test( "scale", function() {
ok( b.clone().scale( 2 ).equals( new THREE.Box2( zero, new THREE.Vector2( 2, 2 ) ) ), "Passed!" ); 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!" ); 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!" );
});
...@@ -12,4 +12,4 @@ var posInf = new THREE.Vector3( Infinity, Infinity ); ...@@ -12,4 +12,4 @@ var posInf = new THREE.Vector3( Infinity, Infinity );
var zero = new THREE.Vector3(); var zero = new THREE.Vector3();
var one = new THREE.Vector3( 1, 1, 1 ); var one = new THREE.Vector3( 1, 1, 1 );
var two = new THREE.Vector3( 1, 1, 1 ); var two = new THREE.Vector3( 2, 2, 2 );
...@@ -87,10 +87,10 @@ test( "flip", function() { ...@@ -87,10 +87,10 @@ test( "flip", function() {
}); });
test( "normalize", 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(); a.normalize();
ok( a.normal.length() == 1, "Passed!" ); 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!" ); ok( a.constant == 1, "Passed!" );
}); });
...@@ -11,7 +11,7 @@ test( "constructor", function() { ...@@ -11,7 +11,7 @@ test( "constructor", function() {
a = new THREE.Sphere( one, 1 ); a = new THREE.Sphere( one, 1 );
ok( a.center.equals( one ), "Passed!" ); ok( a.center.equals( one ), "Passed!" );
ok( a.radius == 0, "Passed!" ); ok( a.radius == 1, "Passed!" );
}); });
test( "copy", function() { test( "copy", function() {
...@@ -19,13 +19,13 @@ test( "copy", function() { ...@@ -19,13 +19,13 @@ test( "copy", function() {
var b = new THREE.Sphere().copy( a ); var b = new THREE.Sphere().copy( a );
ok( b.center.equals( one ), "Passed!" ); ok( b.center.equals( one ), "Passed!" );
ok( b.radius == 0, "Passed!" ); ok( b.radius == 1, "Passed!" );
// ensure that it is a true copy // ensure that it is a true copy
a.center = zero; a.center = zero;
a.radius = 0; a.radius = 0;
ok( b.center.equals( one ), "Passed!" ); ok( b.center.equals( one ), "Passed!" );
ok( b.radius == 0, "Passed!" ); ok( b.radius == 1, "Passed!" );
}); });
test( "set", function() { test( "set", function() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册