Skip to content

Commit e2df06e

Browse files
committed
fix three missed conversions to closures. switch to extending math prototypes 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.
1 parent ceb6671 commit e2df06e

File tree

16 files changed

+81
-47
lines changed

16 files changed

+81
-47
lines changed

src/Three.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ String.prototype.trim = String.prototype.trim || function () {
4646
};
4747

4848

49+
THREE.extend = function ( target, other ) {
50+
51+
target = target || {};
52+
53+
for (var prop in other) {
54+
55+
if ( typeof other[prop] === 'object' ) {
56+
57+
target[prop] = THREE.extend( target[prop], other[prop] );
58+
59+
} else {
60+
61+
target[prop] = other[prop];
62+
63+
}
64+
65+
}
66+
67+
return target;
68+
69+
};
70+
4971
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
5072
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
5173

src/math/Box2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ THREE.Box2 = function ( min, max ) {
99

1010
};
1111

12-
THREE.Box2.prototype = {
12+
THREE.extend( THREE.Box2.prototype, {
1313

1414
constructor: THREE.Box2,
1515

@@ -259,4 +259,4 @@ THREE.Box2.prototype = {
259259

260260
}
261261

262-
};
262+
} );

src/math/Box3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ THREE.Box3 = function ( min, max ) {
99

1010
};
1111

12-
THREE.Box3.prototype = {
12+
THREE.extend( THREE.Box3.prototype, {
1313

1414
constructor: THREE.Box3,
1515

@@ -328,4 +328,4 @@ THREE.Box3.prototype = {
328328

329329
}
330330

331-
};
331+
} );

src/math/Color.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ THREE.Color = function ( value ) {
1010

1111
};
1212

13-
THREE.Color.prototype = {
13+
THREE.extend( THREE.Color.prototype, {
1414

1515
constructor: THREE.Color,
1616

@@ -390,7 +390,7 @@ THREE.Color.prototype = {
390390

391391
}
392392

393-
};
393+
} );
394394

395395
THREE.ColorKeywords = { "aliceblue": 0xF0F8FF, "antiquewhite": 0xFAEBD7, "aqua": 0x00FFFF, "aquamarine": 0x7FFFD4, "azure": 0xF0FFFF,
396396
"beige": 0xF5F5DC, "bisque": 0xFFE4C4, "black": 0x000000, "blanchedalmond": 0xFFEBCD, "blue": 0x0000FF, "blueviolet": 0x8A2BE2,

src/math/Frustum.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
1919

2020
};
2121

22-
THREE.Frustum.prototype = {
22+
THREE.extend( THREE.Frustum.prototype, {
2323

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

@@ -140,4 +140,4 @@ THREE.Frustum.prototype = {
140140

141141
}
142142

143-
};
143+
} );

src/math/Math.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,28 @@ THREE.Math = {
6767

6868
},
6969

70-
degToRad: function ( degrees ) {
70+
degToRad: function() {
7171

72-
return degrees * THREE.Math.__d2r;
72+
var degreeToRadiansFactor = Math.PI / 180;
7373

74-
},
74+
return function ( degrees ) {
75+
76+
return degrees * degreeToRadiansFactor;
77+
78+
};
79+
80+
}(),
81+
82+
radToDeg: function() {
83+
84+
var radianToDegreesFactor = 180 / Math.PI;
7585

76-
radToDeg: function ( radians ) {
86+
return function ( radians ) {
7787

78-
return radians * THREE.Math.__r2d;
88+
return radians * radianToDegreesFactor;
7989

80-
}
90+
};
8191

82-
};
92+
}()
8393

84-
THREE.Math.__d2r = Math.PI / 180;
85-
THREE.Math.__r2d = 180 / Math.PI;
94+
};

src/math/Matrix3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ THREE.Matrix3 = function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
1717
);
1818
};
1919

20-
THREE.Matrix3.prototype = {
20+
THREE.extend( THREE.Matrix3.prototype, {
2121

2222
constructor: THREE.Matrix3,
2323

@@ -214,4 +214,4 @@ THREE.Matrix3.prototype = {
214214

215215
}
216216

217-
};
217+
} );

src/math/Matrix4.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33
2525

2626
};
2727

28-
THREE.Matrix4.prototype = {
28+
THREE.extend( THREE.Matrix4.prototype, {
2929

3030
constructor: THREE.Matrix4,
3131

@@ -657,7 +657,8 @@ THREE.Matrix4.prototype = {
657657

658658
var x = new THREE.Vector3(),
659659
y = new THREE.Vector3(),
660-
z = new THREE.Vector3();
660+
z = new THREE.Vector3(),
661+
matrix = new THREE.Matrix4();
661662

662663
return function ( translation, rotation, scale ) {
663664

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

683684
// scale the rotation part
684-
685-
var matrix = THREE.Matrix4.__m1;
686-
685+
687686
matrix.copy( this );
688687

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

11171116
}
11181117

1119-
};
1118+
} );

src/math/Plane.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ THREE.Plane = function ( normal, constant ) {
99

1010
};
1111

12-
THREE.Plane.prototype = {
12+
THREE.extend( THREE.Plane.prototype, {
1313

1414
constructor: THREE.Plane,
1515

@@ -219,4 +219,4 @@ THREE.Plane.prototype = {
219219

220220
}
221221

222-
};
222+
} );

src/math/Quaternion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ THREE.Quaternion = function( x, y, z, w ) {
1414

1515
};
1616

17-
THREE.Quaternion.prototype = {
17+
THREE.extend( THREE.Quaternion.prototype, {
1818

1919
constructor: THREE.Quaternion,
2020

@@ -339,7 +339,7 @@ THREE.Quaternion.prototype = {
339339

340340
}
341341

342-
}
342+
} );
343343

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

src/math/Ray.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ THREE.Ray = function ( origin, direction ) {
99

1010
};
1111

12-
THREE.Ray.prototype = {
12+
THREE.extend( THREE.Ray.prototype, {
1313

1414
constructor: THREE.Ray,
1515

@@ -39,13 +39,19 @@ THREE.Ray.prototype = {
3939

4040
},
4141

42-
recast: function ( t ) {
42+
recast: function() {
4343

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

46-
return this;
46+
return function ( t ) {
4747

48-
},
48+
this.origin.copy( this.at( t, v1 ) );
49+
50+
return this;
51+
52+
};
53+
54+
}(),
4955

5056
closestPointToPoint: function ( point, optionalTarget ) {
5157

@@ -157,4 +163,4 @@ THREE.Ray.prototype = {
157163

158164
}
159165

160-
};
166+
} );

src/math/Sphere.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ THREE.Sphere = function ( center, radius ) {
1010

1111
};
1212

13-
THREE.Sphere.prototype = {
13+
THREE.extend( THREE.Sphere.prototype, {
1414

1515
constructor: THREE.Sphere,
1616

@@ -133,4 +133,4 @@ THREE.Sphere.prototype = {
133133

134134
}
135135

136-
};
136+
} );

src/math/Triangle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ THREE.Triangle.containsPoint = function() {
9292

9393
}();
9494

95-
THREE.Triangle.prototype = {
95+
THREE.extend( THREE.Triangle.prototype, {
9696

9797
constructor: THREE.Triangle,
9898

@@ -187,4 +187,4 @@ THREE.Triangle.prototype = {
187187

188188
}
189189

190-
};
190+
} );

src/math/Vector2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ THREE.Vector2 = function ( x, y ) {
1212

1313
};
1414

15-
THREE.Vector2.prototype = {
15+
THREE.extend( THREE.Vector2.prototype, {
1616

1717
constructor: THREE.Vector2,
1818

@@ -301,4 +301,4 @@ THREE.Vector2.prototype = {
301301

302302
}
303303

304-
};
304+
} );

src/math/Vector3.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ THREE.Vector3 = function ( x, y, z ) {
1515

1616
};
1717

18-
19-
THREE.Vector3.prototype = {
18+
THREE.extend( THREE.Vector3.prototype, {
2019

2120
constructor: THREE.Vector3,
2221

@@ -741,5 +740,4 @@ THREE.Vector3.prototype = {
741740

742741
}
743742

744-
};
745-
743+
} );

src/math/Vector4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ THREE.Vector4 = function ( x, y, z, w ) {
1515

1616
};
1717

18-
THREE.Vector4.prototype = {
18+
THREE.extend( THREE.Vector4.prototype, {
1919

2020
constructor: THREE.Vector4,
2121

@@ -553,4 +553,4 @@ THREE.Vector4.prototype = {
553553

554554
}
555555

556-
};
556+
} );

0 commit comments

Comments
 (0)