Skip to content

Commit

Permalink
added back aliases to vectors, and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed May 4, 2016
1 parent a57786f commit a4c4fa6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/goo/math/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Vector.setupAliases(Vector2.prototype, [['x'], ['y']]);
Vector.setupIndices(Vector2.prototype, 2);
// @endif

Vector.setupAliases(Vector2.prototype, [['u'], ['v']]);

/**
* Zero-vector (0, 0)
* @type {Vector2}
Expand Down
2 changes: 2 additions & 0 deletions src/goo/math/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Vector.setupAliases(Vector3.prototype, [['x'], ['y'], ['z']]);
Vector.setupIndices(Vector3.prototype, 3);
// @endif

Vector.setupAliases(Vector3.prototype, [['u', 'r'], ['v', 'g'], ['w', 'b']]);

/**
* Zero-vector (0, 0, 0)
* @type {Vector3}
Expand Down
2 changes: 2 additions & 0 deletions src/goo/math/Vector4.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Vector.setupAliases(Vector4.prototype, [['x'], ['y'], ['z'], ['w']]);
Vector.setupIndices(Vector4.prototype, 4);
// @endif

Vector.setupAliases(Vector4.prototype, [['r'], ['g'], ['b'], ['a']]);

/**
* Zero-vector (0, 0, 0, 0)
* @type {Vector4}
Expand Down
7 changes: 7 additions & 0 deletions test/unit/math/Vector2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ describe('Vector2', function () {

expect(a.x).toEqual(11);
expect(a.y).toEqual(22);
expect(a.u).toEqual(11);
expect(a.v).toEqual(22);
});

it('can be modified through aliases', function () {
var v1 = new Vector2();
v1.x = 11;
v1.y = 22;
expect(v1).toBeCloseToVector(new Vector2(11, 22));

var v2 = new Vector2();
v2.u = 22;
v2.v = 33;
expect(v2).toBeCloseToVector(new Vector2(22, 33));
});
});

Expand Down
20 changes: 20 additions & 0 deletions test/unit/math/Vector3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ describe('Vector3', function () {
expect(vector.x).toBeCloseTo(11);
expect(vector.y).toBeCloseTo(22);
expect(vector.z).toBeCloseTo(33);

expect(vector.u).toBeCloseTo(11);
expect(vector.v).toBeCloseTo(22);
expect(vector.w).toBeCloseTo(33);

expect(vector.r).toBeCloseTo(11);
expect(vector.g).toBeCloseTo(22);
expect(vector.b).toBeCloseTo(33);
});

it('can be modified through aliases', function () {
Expand All @@ -81,6 +89,18 @@ describe('Vector3', function () {
vector.z = 33;

expect(vector).toBeCloseToVector(new Vector3(11, 22, 33));

vector.u = 22;
vector.v = 33;
vector.w = 44;

expect(vector).toBeCloseToVector(new Vector3(22, 33, 44));

vector.r = 33;
vector.g = 44;
vector.b = 55;

expect(vector).toBeCloseToVector(new Vector3(33, 44, 55));
});
});

Expand Down
12 changes: 12 additions & 0 deletions test/unit/math/Vector4-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ describe('Vector4', function () {
expect(a.y).toEqual(2);
expect(a.z).toEqual(3);
expect(a.w).toEqual(4);

expect(a.r).toEqual(1);
expect(a.g).toEqual(2);
expect(a.b).toEqual(3);
expect(a.a).toEqual(4);
});

it('can be modified through aliases', function () {
Expand All @@ -87,6 +92,13 @@ describe('Vector4', function () {
a.w = 4;

expect(a).toBeCloseToVector(new Vector4(1, 2, 3, 4));

a.r = 2;
a.g = 3;
a.b = 4;
a.a = 5;

expect(a).toBeCloseToVector(new Vector4(2, 3, 4, 5));
});
});

Expand Down

0 comments on commit a4c4fa6

Please sign in to comment.