From 809593ea340dd8f133cd5513d0a5fd7f4ff471d2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 19 Sep 2017 00:45:03 +0100 Subject: [PATCH] Vec3 and Vec4 can now take a Vec2, 3 or 4 as a valid type of the add, sub, mult and divide methods --- v3/src/math/Vector3.js | 14 +++++++------- v3/src/math/Vector4.js | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/v3/src/math/Vector3.js b/v3/src/math/Vector3.js index aadad1b2b..e0aba1979 100644 --- a/v3/src/math/Vector3.js +++ b/v3/src/math/Vector3.js @@ -32,7 +32,7 @@ var Vector3 = new Class({ { this.x = src.x; this.y = src.y; - this.z = src.z; + this.z = src.z || 0; return this; }, @@ -59,7 +59,7 @@ var Vector3 = new Class({ { this.x += v.x; this.y += v.y; - this.z += v.z; + this.z += v.z || 0; return this; }, @@ -68,7 +68,7 @@ var Vector3 = new Class({ { this.x -= v.x; this.y -= v.y; - this.z -= v.z; + this.z -= v.z || 0; return this; }, @@ -77,7 +77,7 @@ var Vector3 = new Class({ { this.x *= v.x; this.y *= v.y; - this.z *= v.z; + this.z *= v.z || 1; return this; }, @@ -95,7 +95,7 @@ var Vector3 = new Class({ { this.x /= v.x; this.y /= v.y; - this.z /= v.z; + this.z /= v.z || 1; return this; }, @@ -113,7 +113,7 @@ var Vector3 = new Class({ { var dx = v.x - this.x; var dy = v.y - this.y; - var dz = v.z - this.z; + var dz = v.z - this.z || 0; return Math.sqrt(dx * dx + dy * dy + dz * dz); }, @@ -122,7 +122,7 @@ var Vector3 = new Class({ { var dx = v.x - this.x; var dy = v.y - this.y; - var dz = v.z - this.z; + var dz = v.z - this.z || 0; return dx * dx + dy * dy + dz * dz; }, diff --git a/v3/src/math/Vector4.js b/v3/src/math/Vector4.js index 96c5eda5f..b1dbeb57f 100644 --- a/v3/src/math/Vector4.js +++ b/v3/src/math/Vector4.js @@ -34,8 +34,8 @@ var Vector4 = new Class({ { this.x = src.x; this.y = src.y; - this.z = src.z; - this.w = src.w; + this.z = src.z || 0; + this.w = src.w || 0; return this; }, @@ -64,8 +64,8 @@ var Vector4 = new Class({ { this.x += v.x; this.y += v.y; - this.z += v.z; - this.w += v.w; + this.z += v.z || 0; + this.w += v.w || 0; return this; }, @@ -74,8 +74,8 @@ var Vector4 = new Class({ { this.x -= v.x; this.y -= v.y; - this.z -= v.z; - this.w -= v.w; + this.z -= v.z || 0; + this.w -= v.w || 0; return this; }, @@ -157,8 +157,8 @@ var Vector4 = new Class({ { this.x *= v.x; this.y *= v.y; - this.z *= v.z; - this.w *= v.w; + this.z *= v.z || 1; + this.w *= v.w || 1; return this; }, @@ -167,8 +167,8 @@ var Vector4 = new Class({ { this.x /= v.x; this.y /= v.y; - this.z /= v.z; - this.w /= v.w; + this.z /= v.z || 1; + this.w /= v.w || 1; return this; }, @@ -177,8 +177,8 @@ var Vector4 = new Class({ { var dx = v.x - this.x; var dy = v.y - this.y; - var dz = v.z - this.z; - var dw = v.w - this.w; + var dz = v.z - this.z || 0; + var dw = v.w - this.w || 0; return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw); }, @@ -187,8 +187,8 @@ var Vector4 = new Class({ { var dx = v.x - this.x; var dy = v.y - this.y; - var dz = v.z - this.z; - var dw = v.w - this.w; + var dz = v.z - this.z || 0; + var dw = v.w - this.w || 0; return dx * dx + dy * dy + dz * dz + dw * dw; },