Skip to content

Commit adaa3d0

Browse files
committed
update math constructors to not copy when provided explicit initial values per @mrdoob: mrdoob#2902 (comment)
1 parent 9fb65f6 commit adaa3d0

12 files changed

Lines changed: 112 additions & 124 deletions

File tree

src/math/Box2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
THREE.Box2 = function ( min, max ) {
66

7-
this.min = min !== undefined ? min.clone() : new THREE.Vector2( Infinity, Infinity );
8-
this.max = max !== undefined ? max.clone() : new THREE.Vector2( -Infinity, -Infinity );
7+
this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
8+
this.max = ( max !== undefined ) ? max : new THREE.Vector2( -Infinity, -Infinity );
99

1010
};
1111

src/math/Box3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
THREE.Box3 = function ( min, max ) {
66

7-
this.min = min !== undefined ? min.clone() : new THREE.Vector3( Infinity, Infinity, Infinity );
8-
this.max = max !== undefined ? max.clone() : new THREE.Vector3( -Infinity, -Infinity, -Infinity );
7+
this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
8+
this.max = ( max !== undefined ) ? max : new THREE.Vector3( -Infinity, -Infinity, -Infinity );
99

1010
};
1111

src/math/Frustum.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
88

99
this.planes = [
1010

11-
( p0 !== undefined ) ? p0.clone() : new THREE.Plane(),
12-
( p1 !== undefined ) ? p1.clone() : new THREE.Plane(),
13-
( p2 !== undefined ) ? p2.clone() : new THREE.Plane(),
14-
( p3 !== undefined ) ? p3.clone() : new THREE.Plane(),
15-
( p4 !== undefined ) ? p4.clone() : new THREE.Plane(),
16-
( p5 !== undefined ) ? p5.clone() : new THREE.Plane()
11+
( p0 !== undefined ) ? p0 : new THREE.Plane(),
12+
( p1 !== undefined ) ? p1 : new THREE.Plane(),
13+
( p2 !== undefined ) ? p2 : new THREE.Plane(),
14+
( p3 !== undefined ) ? p3 : new THREE.Plane(),
15+
( p4 !== undefined ) ? p4 : new THREE.Plane(),
16+
( p5 !== undefined ) ? p5 : new THREE.Plane()
1717

1818
];
1919

src/math/Plane.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
THREE.Plane = function ( normal, constant ) {
66

7-
this.normal = normal !== undefined ? normal.clone() : new THREE.Vector3( 1, 0, 0 );
8-
this.constant = constant !== undefined ? constant : 0;
7+
this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
8+
this.constant = ( constant !== undefined ) ? constant : 0;
99

1010
};
1111

src/math/Ray.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
THREE.Ray = function ( origin, direction ) {
66

7-
8-
this.origin = origin !== undefined ? origin.clone() : new THREE.Vector3();
9-
this.direction = direction !== undefined ? direction.clone() : new THREE.Vector3();
7+
this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
8+
this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
109

1110
};
1211

src/math/Sphere.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
THREE.Sphere = function ( center, radius ) {
77

8-
this.center = center === undefined ? new THREE.Vector3() : center.clone();
9-
this.radius = radius === undefined ? 0 : radius;
8+
this.center = ( center !== undefined ) ? center : new THREE.Vector3();
9+
this.radius = ( radius !== undefined ) ? radius : 0;
1010

1111
};
1212

src/math/Triangle.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,9 @@
55

66
THREE.Triangle = function ( a, b, c ) {
77

8-
this.a = new THREE.Vector3();
9-
this.b = new THREE.Vector3();
10-
this.c = new THREE.Vector3();
11-
12-
if( a !== undefined && b !== undefined && c !== undefined ) {
13-
14-
this.a.copy( a );
15-
this.b.copy( b );
16-
this.c.copy( c );
17-
18-
}
8+
this.a = ( a !== undefined ) ? a : new THREE.Vector3();
9+
this.b = ( b !== undefined ) ? b : new THREE.Vector3();
10+
this.c = ( c !== undefined ) ? c : new THREE.Vector3();
1911

2012
};
2113

test/unit/math/Box2.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ test( "constructor", function() {
99
ok( a.min.equals( posInf2 ), "Passed!" );
1010
ok( a.max.equals( negInf2 ), "Passed!" );
1111

12-
a = new THREE.Box2( zero2, zero2 );
12+
a = new THREE.Box2( zero2.clone(), zero2.clone() );
1313
ok( a.min.equals( zero2 ), "Passed!" );
1414
ok( a.max.equals( zero2 ), "Passed!" );
1515

16-
a = new THREE.Box2( zero2, one2 );
16+
a = new THREE.Box2( zero2.clone(), one2.clone() );
1717
ok( a.min.equals( zero2 ), "Passed!" );
1818
ok( a.max.equals( one2 ), "Passed!" );
1919
});
2020

2121
test( "copy", function() {
22-
var a = new THREE.Box2( zero2, one2 );
22+
var a = new THREE.Box2( zero2.clone(), one2.clone() );
2323
var b = new THREE.Box2().copy( a );
2424
ok( b.min.equals( zero2 ), "Passed!" );
2525
ok( b.max.equals( one2 ), "Passed!" );
@@ -44,15 +44,15 @@ test( "empty/makeEmpty", function() {
4444

4545
ok( a.empty(), "Passed!" );
4646

47-
var a = new THREE.Box2( zero2, one2 );
47+
var a = new THREE.Box2( zero2.clone(), one2.clone() );
4848
ok( ! a.empty(), "Passed!" );
4949

5050
a.makeEmpty();
5151
ok( a.empty(), "Passed!" );
5252
});
5353

5454
test( "center", function() {
55-
var a = new THREE.Box2( zero2, zero2 );
55+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
5656

5757
ok( a.center().equals( zero2 ), "Passed!" );
5858

@@ -62,16 +62,16 @@ test( "center", function() {
6262
});
6363

6464
test( "size", function() {
65-
var a = new THREE.Box2( zero2, zero2 );
65+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
6666

6767
ok( a.size().equals( zero2 ), "Passed!" );
6868

69-
a = new THREE.Box2( zero2, one2 );
69+
a = new THREE.Box2( zero2.clone(), one2.clone() );
7070
ok( a.size().equals( one2 ), "Passed!" );
7171
});
7272

7373
test( "expandByPoint", function() {
74-
var a = new THREE.Box2( zero2, zero2 );
74+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
7575

7676
a.expandByPoint( zero2 );
7777
ok( a.size().equals( zero2 ), "Passed!" );
@@ -85,7 +85,7 @@ test( "expandByPoint", function() {
8585
});
8686

8787
test( "expandByVector", function() {
88-
var a = new THREE.Box2( zero2, zero2 );
88+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
8989

9090
a.expandByVector( zero2 );
9191
ok( a.size().equals( zero2 ), "Passed!" );
@@ -96,7 +96,7 @@ test( "expandByVector", function() {
9696
});
9797

9898
test( "expandByScalar", function() {
99-
var a = new THREE.Box2( zero2, zero2 );
99+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
100100

101101
a.expandByScalar( 0 );
102102
ok( a.size().equals( zero2 ), "Passed!" );
@@ -107,7 +107,7 @@ test( "expandByScalar", function() {
107107
});
108108

109109
test( "containsPoint", function() {
110-
var a = new THREE.Box2( zero2, zero2 );
110+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
111111

112112
ok( a.containsPoint( zero2 ), "Passed!" );
113113
ok( ! a.containsPoint( one2 ), "Passed!" );
@@ -119,9 +119,9 @@ test( "containsPoint", function() {
119119
});
120120

121121
test( "containsBox", function() {
122-
var a = new THREE.Box2( zero2, zero2 );
123-
var b = new THREE.Box2( zero2, one2 );
124-
var c = new THREE.Box2( one2.clone().negate(), one2 );
122+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
123+
var b = new THREE.Box2( zero2.clone(), one2.clone() );
124+
var c = new THREE.Box2( one2.clone().negate(), one2.clone() );
125125

126126
ok( a.containsBox( a ), "Passed!" );
127127
ok( ! a.containsBox( b ), "Passed!" );
@@ -133,8 +133,8 @@ test( "containsBox", function() {
133133
});
134134

135135
test( "getParameter", function() {
136-
var a = new THREE.Box2( zero2, one2 );
137-
var b = new THREE.Box2( one2.clone().negate(), one2 );
136+
var a = new THREE.Box2( zero2.clone(), one2.clone() );
137+
var b = new THREE.Box2( one2.clone().negate(), one2.clone() );
138138

139139
ok( a.getParameter( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
140140
ok( a.getParameter( new THREE.Vector2( 1, 1 ) ).equals( new THREE.Vector2( 1, 1 ) ), "Passed!" );
@@ -145,8 +145,8 @@ test( "getParameter", function() {
145145
});
146146

147147
test( "clampPoint", function() {
148-
var a = new THREE.Box2( zero2, zero2 );
149-
var b = new THREE.Box2( one2.clone().negate(), one2 );
148+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
149+
var b = new THREE.Box2( one2.clone().negate(), one2.clone() );
150150

151151
ok( a.clampPoint( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
152152
ok( a.clampPoint( new THREE.Vector2( 1, 1 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
@@ -160,8 +160,8 @@ test( "clampPoint", function() {
160160
});
161161

162162
test( "distanceToPoint", function() {
163-
var a = new THREE.Box2( zero2, zero2 );
164-
var b = new THREE.Box2( one2.clone().negate(), one2 );
163+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
164+
var b = new THREE.Box2( one2.clone().negate(), one2.clone() );
165165

166166
ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
167167
ok( a.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
@@ -175,8 +175,8 @@ test( "distanceToPoint", function() {
175175
});
176176

177177
test( "distanceToPoint", function() {
178-
var a = new THREE.Box2( zero2, zero2 );
179-
var b = new THREE.Box2( one2.clone().negate(), one2 );
178+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
179+
var b = new THREE.Box2( one2.clone().negate(), one2.clone() );
180180

181181
ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
182182
ok( a.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
@@ -190,9 +190,9 @@ test( "distanceToPoint", function() {
190190
});
191191

192192
test( "isIntersectionBox", function() {
193-
var a = new THREE.Box2( zero2, zero2 );
194-
var b = new THREE.Box2( zero2, one2 );
195-
var c = new THREE.Box2( one2.clone().negate(), one2 );
193+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
194+
var b = new THREE.Box2( zero2.clone(), one2.clone() );
195+
var c = new THREE.Box2( one2.clone().negate(), one2.clone() );
196196

197197
ok( a.isIntersectionBox( a ), "Passed!" );
198198
ok( a.isIntersectionBox( b ), "Passed!" );
@@ -209,9 +209,9 @@ test( "isIntersectionBox", function() {
209209
});
210210

211211
test( "intersect", function() {
212-
var a = new THREE.Box2( zero2, zero2 );
213-
var b = new THREE.Box2( zero2, one2 );
214-
var c = new THREE.Box2( one2.clone().negate(), one2 );
212+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
213+
var b = new THREE.Box2( zero2.clone(), one2.clone() );
214+
var c = new THREE.Box2( one2.clone().negate(), one2.clone() );
215215

216216
ok( a.clone().intersect( a ).equals( a ), "Passed!" );
217217
ok( a.clone().intersect( b ).equals( a ), "Passed!" );
@@ -222,9 +222,9 @@ test( "intersect", function() {
222222
});
223223

224224
test( "union", function() {
225-
var a = new THREE.Box2( zero2, zero2 );
226-
var b = new THREE.Box2( zero2, one2 );
227-
var c = new THREE.Box2( one2.clone().negate(), one2 );
225+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
226+
var b = new THREE.Box2( zero2.clone(), one2.clone() );
227+
var c = new THREE.Box2( one2.clone().negate(), one2.clone() );
228228

229229
ok( a.clone().union( a ).equals( a ), "Passed!" );
230230
ok( a.clone().union( b ).equals( b ), "Passed!" );
@@ -233,10 +233,10 @@ test( "union", function() {
233233
});
234234

235235
test( "translate", function() {
236-
var a = new THREE.Box2( zero2, zero2 );
237-
var b = new THREE.Box2( zero2, one2 );
238-
var c = new THREE.Box2( one2.clone().negate(), one2 );
239-
var d = new THREE.Box2( one2.clone().negate(), zero2 );
236+
var a = new THREE.Box2( zero2.clone(), zero2.clone() );
237+
var b = new THREE.Box2( zero2.clone(), one2.clone() );
238+
var c = new THREE.Box2( one2.clone().negate(), one2.clone() );
239+
var d = new THREE.Box2( one2.clone().negate(), zero2.clone() );
240240

241241
ok( a.clone().translate( one2 ).equals( new THREE.Box2( one2, one2 ) ), "Passed!" );
242242
ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );

0 commit comments

Comments
 (0)