Skip to content

Commit 809593e

Browse files
committed
Vec3 and Vec4 can now take a Vec2, 3 or 4 as a valid type of the add, sub, mult and divide methods
1 parent d6fe678 commit 809593e

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

v3/src/math/Vector3.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var Vector3 = new Class({
3232
{
3333
this.x = src.x;
3434
this.y = src.y;
35-
this.z = src.z;
35+
this.z = src.z || 0;
3636

3737
return this;
3838
},
@@ -59,7 +59,7 @@ var Vector3 = new Class({
5959
{
6060
this.x += v.x;
6161
this.y += v.y;
62-
this.z += v.z;
62+
this.z += v.z || 0;
6363

6464
return this;
6565
},
@@ -68,7 +68,7 @@ var Vector3 = new Class({
6868
{
6969
this.x -= v.x;
7070
this.y -= v.y;
71-
this.z -= v.z;
71+
this.z -= v.z || 0;
7272

7373
return this;
7474
},
@@ -77,7 +77,7 @@ var Vector3 = new Class({
7777
{
7878
this.x *= v.x;
7979
this.y *= v.y;
80-
this.z *= v.z;
80+
this.z *= v.z || 1;
8181

8282
return this;
8383
},
@@ -95,7 +95,7 @@ var Vector3 = new Class({
9595
{
9696
this.x /= v.x;
9797
this.y /= v.y;
98-
this.z /= v.z;
98+
this.z /= v.z || 1;
9999

100100
return this;
101101
},
@@ -113,7 +113,7 @@ var Vector3 = new Class({
113113
{
114114
var dx = v.x - this.x;
115115
var dy = v.y - this.y;
116-
var dz = v.z - this.z;
116+
var dz = v.z - this.z || 0;
117117

118118
return Math.sqrt(dx * dx + dy * dy + dz * dz);
119119
},
@@ -122,7 +122,7 @@ var Vector3 = new Class({
122122
{
123123
var dx = v.x - this.x;
124124
var dy = v.y - this.y;
125-
var dz = v.z - this.z;
125+
var dz = v.z - this.z || 0;
126126

127127
return dx * dx + dy * dy + dz * dz;
128128
},

v3/src/math/Vector4.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ var Vector4 = new Class({
3434
{
3535
this.x = src.x;
3636
this.y = src.y;
37-
this.z = src.z;
38-
this.w = src.w;
37+
this.z = src.z || 0;
38+
this.w = src.w || 0;
3939

4040
return this;
4141
},
@@ -64,8 +64,8 @@ var Vector4 = new Class({
6464
{
6565
this.x += v.x;
6666
this.y += v.y;
67-
this.z += v.z;
68-
this.w += v.w;
67+
this.z += v.z || 0;
68+
this.w += v.w || 0;
6969

7070
return this;
7171
},
@@ -74,8 +74,8 @@ var Vector4 = new Class({
7474
{
7575
this.x -= v.x;
7676
this.y -= v.y;
77-
this.z -= v.z;
78-
this.w -= v.w;
77+
this.z -= v.z || 0;
78+
this.w -= v.w || 0;
7979

8080
return this;
8181
},
@@ -157,8 +157,8 @@ var Vector4 = new Class({
157157
{
158158
this.x *= v.x;
159159
this.y *= v.y;
160-
this.z *= v.z;
161-
this.w *= v.w;
160+
this.z *= v.z || 1;
161+
this.w *= v.w || 1;
162162

163163
return this;
164164
},
@@ -167,8 +167,8 @@ var Vector4 = new Class({
167167
{
168168
this.x /= v.x;
169169
this.y /= v.y;
170-
this.z /= v.z;
171-
this.w /= v.w;
170+
this.z /= v.z || 1;
171+
this.w /= v.w || 1;
172172

173173
return this;
174174
},
@@ -177,8 +177,8 @@ var Vector4 = new Class({
177177
{
178178
var dx = v.x - this.x;
179179
var dy = v.y - this.y;
180-
var dz = v.z - this.z;
181-
var dw = v.w - this.w;
180+
var dz = v.z - this.z || 0;
181+
var dw = v.w - this.w || 0;
182182

183183
return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
184184
},
@@ -187,8 +187,8 @@ var Vector4 = new Class({
187187
{
188188
var dx = v.x - this.x;
189189
var dy = v.y - this.y;
190-
var dz = v.z - this.z;
191-
var dw = v.w - this.w;
190+
var dz = v.z - this.z || 0;
191+
var dw = v.w - this.w || 0;
192192

193193
return dx * dx + dy * dy + dz * dz + dw * dw;
194194
},

0 commit comments

Comments
 (0)