diff --git a/src/math/Box2.js b/src/math/Box2.js index 7529cb3ea33be54673cdcbb52f3d5160b9d1783d..a96d6ca4354560ec990c2b99b68f2acdd68e3ec7 100644 --- a/src/math/Box2.js +++ b/src/math/Box2.js @@ -237,15 +237,6 @@ THREE.Box2.prototype = { }, - scale: function ( factor ) { - - var sizeDeltaHalf = this.size().multiplyScalar( ( factor - 1 ) * 0.5 ); - this.expandByVector( sizeDeltaHalf ); - - return this; - - }, - equals: function ( box ) { return box.min.equals( this.min ) && box.max.equals( this.max ); diff --git a/src/math/Box3.js b/src/math/Box3.js index 10804cca468016d37dc54efd3da851c6d2602bb3..00999d7c57dbacc26493d7f8fc24ecf467fd7026 100644 --- a/src/math/Box3.js +++ b/src/math/Box3.js @@ -244,19 +244,31 @@ THREE.Box3.prototype = { }, - translate: function ( offset ) { - - this.min.addSelf( offset ); - this.max.addSelf( offset ); + transform: function ( matrix ) { + + // NOTE: I am using a binary pattern to specify all 2^3 combinations below + var newPoints = [ + matrix.multiplyVector3( THREE.Box3.__v0.set( this.min.x, this.min.y, this.min.z ) ), // 000 + matrix.multiplyVector3( THREE.Box3.__v1.set( this.min.x, this.min.y, this.max.z ) ), // 001 + matrix.multiplyVector3( THREE.Box3.__v2.set( this.min.x, this.max.y, this.min.z ) ), // 010 + matrix.multiplyVector3( THREE.Box3.__v3.set( this.min.x, this.max.y, this.max.z ) ), // 011 + matrix.multiplyVector3( THREE.Box3.__v4.set( this.max.x, this.min.y, this.min.z ) ), // 100 + matrix.multiplyVector3( THREE.Box3.__v5.set( this.max.x, this.min.y, this.max.z ) ), // 101 + matrix.multiplyVector3( THREE.Box3.__v6.set( this.max.x, this.max.y, this.min.z ) ), // 110 + matrix.multiplyVector3( THREE.Box3.__v7.set( this.max.x, this.max.y, this.max.z ) ) // 111 + ]; + + this.makeEmpty(); + this.setFromPoints( newPoints ); return this; }, - scale: function ( factor ) { + translate: function ( offset ) { - var sizeDeltaHalf = this.size().multiplyScalar( ( factor - 1 ) * 0.5 ); - this.expandByVector( sizeDeltaHalf ); + this.min.addSelf( offset ); + this.max.addSelf( offset ); return this; @@ -276,4 +288,11 @@ THREE.Box3.prototype = { }; +THREE.Box3.__v0 = new THREE.Vector3(); THREE.Box3.__v1 = new THREE.Vector3(); +THREE.Box3.__v2 = new THREE.Vector3(); +THREE.Box3.__v3 = new THREE.Vector3(); +THREE.Box3.__v4 = new THREE.Vector3(); +THREE.Box3.__v5 = new THREE.Vector3(); +THREE.Box3.__v6 = new THREE.Vector3(); +THREE.Box3.__v7 = new THREE.Vector3(); diff --git a/test/core/Box2.js b/test/math/Box2.js similarity index 93% rename from test/core/Box2.js rename to test/math/Box2.js index 775dfa2ad0095a677c14586bf7ebbbf519d05ecb..d6a992df6b67b78fded244f9e0e4b4a8559c9afa 100644 --- a/test/core/Box2.js +++ b/test/math/Box2.js @@ -242,16 +242,4 @@ test( "translate", function() { ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" ); ok( d.clone().translate( one2 ).equals( b ), "Passed!" ); ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" ); -}); - -test( "scale", function() { - var a = new THREE.Box2( zero2, zero2 ); - var b = new THREE.Box2( zero2, one2 ); - var c = new THREE.Box2( one2.clone().negate(), one2 ); - var d = new THREE.Box2( one2.clone().negate(), zero2 ); - - ok( a.clone().scale( 0 ).equals( a ), "Passed!" ); - ok( c.clone().scale( 0 ).equals( a ), "Passed!" ); - ok( b.clone().scale( 3 ).equals( new THREE.Box2( new THREE.Vector2( -1, -1, -1 ), new THREE.Vector2( 2, 2, 2 ) ) ), "Passed!" ); - ok( d.clone().scale( 3 ).equals( new THREE.Box2( new THREE.Vector2( 2, 2, 2 ).negate(), new THREE.Vector2( 1, 1, 1 ) ) ), "Passed!" ); -}); +}); \ No newline at end of file diff --git a/test/core/Box3.js b/test/math/Box3.js similarity index 93% rename from test/core/Box3.js rename to test/math/Box3.js index 3b7f5e66a56f28ac5dcd7c19044c81d60e018faf..00ba65a7f847bc304a542ae8414cd36cabc97a22 100644 --- a/test/core/Box3.js +++ b/test/math/Box3.js @@ -232,26 +232,36 @@ test( "union", function() { ok( b.clone().union( c ).equals( c ), "Passed!" ); }); -test( "translate", function() { +var compareBox = function ( a, b, threshold ) { + threshold = threshold || 0.0001; + return ( a.min.distanceTo( b.min ) < threshold && + a.max.distanceTo( b.max ) < threshold ); +}; + +test( "transform", function() { var a = new THREE.Box3( zero3, zero3 ); var b = new THREE.Box3( zero3, one3 ); var c = new THREE.Box3( one3.clone().negate(), one3 ); var d = new THREE.Box3( one3.clone().negate(), zero3 ); - ok( a.clone().translate( one3 ).equals( new THREE.Box3( one3, one3 ) ), "Passed!" ); - ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" ); - ok( d.clone().translate( one3 ).equals( b ), "Passed!" ); - ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" ); + var m = new THREE.Matrix4(); + + var t1 = new THREE.Vector3( 1, -2, 1 ); + m.makeTranslation( t1.x, t1.y, t1.z ); + ok( compareBox( a.clone().transform( m ), a.clone().translate( t1 ) ), "Passed!" ); + ok( compareBox( b.clone().transform( m ), b.clone().translate( t1 ) ), "Passed!" ); + ok( compareBox( c.clone().transform( m ), c.clone().translate( t1 ) ), "Passed!" ); + ok( compareBox( d.clone().transform( m ), d.clone().translate( t1 ) ), "Passed!" ); }); -test( "scale", function() { +test( "translate", function() { var a = new THREE.Box3( zero3, zero3 ); var b = new THREE.Box3( zero3, one3 ); var c = new THREE.Box3( one3.clone().negate(), one3 ); var d = new THREE.Box3( one3.clone().negate(), zero3 ); - ok( a.clone().scale( 0 ).equals( a ), "Passed!" ); - ok( c.clone().scale( 0 ).equals( a ), "Passed!" ); - ok( b.clone().scale( 3 ).equals( new THREE.Box3( new THREE.Vector3( -1, -1, -1 ), new THREE.Vector3( 2, 2, 2 ) ) ), "Passed!" ); - ok( d.clone().scale( 3 ).equals( new THREE.Box3( new THREE.Vector3( 2, 2, 2 ).negate(), new THREE.Vector3( 1, 1, 1 ) ) ), "Passed!" ); + ok( a.clone().translate( one3 ).equals( new THREE.Box3( one3, one3 ) ), "Passed!" ); + ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" ); + ok( d.clone().translate( one3 ).equals( b ), "Passed!" ); + ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" ); }); diff --git a/test/core/Constants.js b/test/math/Constants.js similarity index 100% rename from test/core/Constants.js rename to test/math/Constants.js diff --git a/test/core/Plane.js b/test/math/Plane.js similarity index 100% rename from test/core/Plane.js rename to test/math/Plane.js diff --git a/test/core/Ray.js b/test/math/Ray.js similarity index 96% rename from test/core/Ray.js rename to test/math/Ray.js index 00bc85c6c0ccf2e4926e10b881ba8c707cc4c834..e4f45623ddcf5e9a29c3c15df1025855174e11ef 100644 --- a/test/core/Ray.js +++ b/test/math/Ray.js @@ -149,26 +149,26 @@ test( "intersectPlane", function() { }); -test( "transformSelf", function() { +test( "transform", function() { var a = new THREE.Ray( one3, new THREE.Vector3( 0, 0, 1 ) ); var m = new THREE.Matrix4().identity(); - ok( a.clone().transformSelf( m ).equals( a ), "Passed!" ); + ok( a.clone().transform( m ).equals( a ), "Passed!" ); a = new THREE.Ray( zero3, new THREE.Vector3( 0, 0, 1 ) ); m.rotateByAxis( new THREE.Vector3( 0, 0, 1 ), Math.PI ); - ok( a.clone().transformSelf( m ).equals( a ), "Passed!" ); + ok( a.clone().transform( m ).equals( a ), "Passed!" ); m.identity().rotateX( Math.PI ); var b = a.clone(); b.direction.negate(); - var a2 = a.clone().transformSelf( m ); + var a2 = a.clone().transform( m ); ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" ); ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" ); a.origin = new THREE.Vector3( 0, 0, 1 ); b.origin = new THREE.Vector3( 0, 0, -1 ); - var a2 = a.clone().transformSelf( m ); + var a2 = a.clone().transform( m ); ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" ); ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" ); }); diff --git a/test/core/Sphere.js b/test/math/Sphere.js similarity index 100% rename from test/core/Sphere.js rename to test/math/Sphere.js diff --git a/test/core/Triangle.js b/test/math/Triangle.js similarity index 100% rename from test/core/Triangle.js rename to test/math/Triangle.js diff --git a/test/core/Vector2.js b/test/math/Vector2.js similarity index 100% rename from test/core/Vector2.js rename to test/math/Vector2.js diff --git a/test/core/Vector3.js b/test/math/Vector3.js similarity index 100% rename from test/core/Vector3.js rename to test/math/Vector3.js diff --git a/test/core/Vector4.js b/test/math/Vector4.js similarity index 100% rename from test/core/Vector4.js rename to test/math/Vector4.js diff --git a/test/sources.html b/test/sources.html index ee0f3682af7f31c79b8287607c615443d26e2177..7f1a510edd213aa47f03e0d67061037277ea4070 100644 --- a/test/sources.html +++ b/test/sources.html @@ -26,16 +26,16 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/test/three-math.html b/test/three-math.html index 4011695c3e20a150f4e6c64bc9f5e26151b61e25..dd2f1c64d2ec29207bc476fbc38663caeac20c2d 100644 --- a/test/three-math.html +++ b/test/three-math.html @@ -15,16 +15,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/three.html b/test/three.html index 72317aad39739903a23ea5429c5d469a824824d1..39ed785f49bf23bd2da084aa00fb951b810978ac 100644 --- a/test/three.html +++ b/test/three.html @@ -15,16 +15,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/three.min.html b/test/three.min.html index a05eccc87fecd103c3679b370d587fddd8474b30..0f2a46cadfa40eec5eb4ee8583e4dbd0234aaf11 100644 --- a/test/three.min.html +++ b/test/three.min.html @@ -15,16 +15,16 @@ - - - - - - - - - - + + + + + + + + + +