Skip to content

Commit

Permalink
fix three missed conversions to closures. switch to extending math pr…
Browse files Browse the repository at this point in the history
…ototypes rather than replacing them. This is to ensure that types created in closures within a type's prototype definition get their prototype updated with the full definition.
  • Loading branch information
bhouston committed Jan 17, 2013
1 parent ceb6671 commit e2df06e
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 47 deletions.
22 changes: 22 additions & 0 deletions src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ String.prototype.trim = String.prototype.trim || function () {
};


THREE.extend = function ( target, other ) {

target = target || {};

for (var prop in other) {

if ( typeof other[prop] === 'object' ) {

target[prop] = THREE.extend( target[prop], other[prop] );

} else {

target[prop] = other[prop];

}

}

return target;

};

// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

Expand Down
4 changes: 2 additions & 2 deletions src/math/Box2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ THREE.Box2 = function ( min, max ) {

};

THREE.Box2.prototype = {
THREE.extend( THREE.Box2.prototype, {

constructor: THREE.Box2,

Expand Down Expand Up @@ -259,4 +259,4 @@ THREE.Box2.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Box3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ THREE.Box3 = function ( min, max ) {

};

THREE.Box3.prototype = {
THREE.extend( THREE.Box3.prototype, {

constructor: THREE.Box3,

Expand Down Expand Up @@ -328,4 +328,4 @@ THREE.Box3.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ THREE.Color = function ( value ) {

};

THREE.Color.prototype = {
THREE.extend( THREE.Color.prototype, {

constructor: THREE.Color,

Expand Down Expand Up @@ -390,7 +390,7 @@ THREE.Color.prototype = {

}

};
} );

THREE.ColorKeywords = { "aliceblue": 0xF0F8FF, "antiquewhite": 0xFAEBD7, "aqua": 0x00FFFF, "aquamarine": 0x7FFFD4, "azure": 0xF0FFFF,
"beige": 0xF5F5DC, "bisque": 0xFFE4C4, "black": 0x000000, "blanchedalmond": 0xFFEBCD, "blue": 0x0000FF, "blueviolet": 0x8A2BE2,
Expand Down
4 changes: 2 additions & 2 deletions src/math/Frustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {

};

THREE.Frustum.prototype = {
THREE.extend( THREE.Frustum.prototype, {

set: function ( p0, p1, p2, p3, p4, p5 ) {

Expand Down Expand Up @@ -140,4 +140,4 @@ THREE.Frustum.prototype = {

}

};
} );
27 changes: 18 additions & 9 deletions src/math/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,28 @@ THREE.Math = {

},

degToRad: function ( degrees ) {
degToRad: function() {

return degrees * THREE.Math.__d2r;
var degreeToRadiansFactor = Math.PI / 180;

},
return function ( degrees ) {

return degrees * degreeToRadiansFactor;

};

}(),

radToDeg: function() {

var radianToDegreesFactor = 180 / Math.PI;

radToDeg: function ( radians ) {
return function ( radians ) {

return radians * THREE.Math.__r2d;
return radians * radianToDegreesFactor;

}
};

};
}()

THREE.Math.__d2r = Math.PI / 180;
THREE.Math.__r2d = 180 / Math.PI;
};
4 changes: 2 additions & 2 deletions src/math/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ THREE.Matrix3 = function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
);
};

THREE.Matrix3.prototype = {
THREE.extend( THREE.Matrix3.prototype, {

constructor: THREE.Matrix3,

Expand Down Expand Up @@ -214,4 +214,4 @@ THREE.Matrix3.prototype = {

}

};
} );
11 changes: 5 additions & 6 deletions src/math/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33

};

THREE.Matrix4.prototype = {
THREE.extend( THREE.Matrix4.prototype, {

constructor: THREE.Matrix4,

Expand Down Expand Up @@ -657,7 +657,8 @@ THREE.Matrix4.prototype = {

var x = new THREE.Vector3(),
y = new THREE.Vector3(),
z = new THREE.Vector3();
z = new THREE.Vector3(),
matrix = new THREE.Matrix4();

return function ( translation, rotation, scale ) {

Expand All @@ -681,9 +682,7 @@ THREE.Matrix4.prototype = {
translation.z = te[14];

// scale the rotation part

var matrix = THREE.Matrix4.__m1;


matrix.copy( this );

matrix.elements[0] /= scale.x;
Expand Down Expand Up @@ -1116,4 +1115,4 @@ THREE.Matrix4.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ THREE.Plane = function ( normal, constant ) {

};

THREE.Plane.prototype = {
THREE.extend( THREE.Plane.prototype, {

constructor: THREE.Plane,

Expand Down Expand Up @@ -219,4 +219,4 @@ THREE.Plane.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ THREE.Quaternion = function( x, y, z, w ) {

};

THREE.Quaternion.prototype = {
THREE.extend( THREE.Quaternion.prototype, {

constructor: THREE.Quaternion,

Expand Down Expand Up @@ -339,7 +339,7 @@ THREE.Quaternion.prototype = {

}

}
} );

THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {

Expand Down
18 changes: 12 additions & 6 deletions src/math/Ray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ THREE.Ray = function ( origin, direction ) {

};

THREE.Ray.prototype = {
THREE.extend( THREE.Ray.prototype, {

constructor: THREE.Ray,

Expand Down Expand Up @@ -39,13 +39,19 @@ THREE.Ray.prototype = {

},

recast: function ( t ) {
recast: function() {

this.origin.copy( this.at( t, THREE.Ray.__v1 ) );
var v1 = new THREE.Vector3();

return this;
return function ( t ) {

},
this.origin.copy( this.at( t, v1 ) );

return this;

};

}(),

closestPointToPoint: function ( point, optionalTarget ) {

Expand Down Expand Up @@ -157,4 +163,4 @@ THREE.Ray.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Sphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ THREE.Sphere = function ( center, radius ) {

};

THREE.Sphere.prototype = {
THREE.extend( THREE.Sphere.prototype, {

constructor: THREE.Sphere,

Expand Down Expand Up @@ -133,4 +133,4 @@ THREE.Sphere.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ THREE.Triangle.containsPoint = function() {

}();

THREE.Triangle.prototype = {
THREE.extend( THREE.Triangle.prototype, {

constructor: THREE.Triangle,

Expand Down Expand Up @@ -187,4 +187,4 @@ THREE.Triangle.prototype = {

}

};
} );
4 changes: 2 additions & 2 deletions src/math/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ THREE.Vector2 = function ( x, y ) {

};

THREE.Vector2.prototype = {
THREE.extend( THREE.Vector2.prototype, {

constructor: THREE.Vector2,

Expand Down Expand Up @@ -301,4 +301,4 @@ THREE.Vector2.prototype = {

}

};
} );
6 changes: 2 additions & 4 deletions src/math/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ THREE.Vector3 = function ( x, y, z ) {

};


THREE.Vector3.prototype = {
THREE.extend( THREE.Vector3.prototype, {

constructor: THREE.Vector3,

Expand Down Expand Up @@ -741,5 +740,4 @@ THREE.Vector3.prototype = {

}

};

} );
4 changes: 2 additions & 2 deletions src/math/Vector4.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ THREE.Vector4 = function ( x, y, z, w ) {

};

THREE.Vector4.prototype = {
THREE.extend( THREE.Vector4.prototype, {

constructor: THREE.Vector4,

Expand Down Expand Up @@ -553,4 +553,4 @@ THREE.Vector4.prototype = {

}

};
} );

0 comments on commit e2df06e

Please sign in to comment.