Skip to content

Commit

Permalink
Add getters for the x,y,z components of X.vector.
Browse files Browse the repository at this point in the history
The original x,y,z properties get optimized (as part of the closure library) during compilation. There was no way to export them as x,y,z without modifying the goog.math.Vec3 class.

Now the exported properties are called
X.vector.xx
X.vector.yy
X.vector.zz
  • Loading branch information
Daniel Haehn committed Feb 13, 2013
1 parent 818ab12 commit 672927b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
8 changes: 4 additions & 4 deletions math/testing/matrix_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ function testXmatrixMultiplyByVector() {

// multiplying the matrix by the vector should result in the vector since the
// matrix is the identity
vector = X.matrix.multiplyByVector(matrix, vector.x, vector.y, vector.z);
vector = X.matrix.multiplyByVector(matrix, vector.xx, vector.yy, vector.zz);

assertEquals(baseline.x, vector.x);
assertEquals(baseline.y, vector.y);
assertEquals(baseline.z, vector.z);
assertEquals(baseline.xx, vector.xx);
assertEquals(baseline.yy, vector.yy);
assertEquals(baseline.zz, vector.zz);

}

Expand Down
12 changes: 6 additions & 6 deletions math/testing/vector_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function testXvectorNormalize() {
// scaling with (1/magnitude = 0.2672612419124244)
// should result in
// x=0.2672612419124244, y=0.5345224838248488, z=0.8017837257372732
assertEquals(0.2672612419124244, vector.x);
assertEquals(0.5345224838248488, vector.y);
assertEquals(0.8017837257372732, vector.z);
assertEquals(0.2672612419124244, vector.xx);
assertEquals(0.5345224838248488, vector.yy);
assertEquals(0.8017837257372732, vector.zz);

}

Expand All @@ -27,9 +27,9 @@ function testXvectorNormalizeWithZeroMagnitude() {
// normalize the vector
vector.normalize();

assertEquals(0, vector.x);
assertEquals(0, vector.y);
assertEquals(0, vector.z);
assertEquals(0, vector.xx);
assertEquals(0, vector.yy);
assertEquals(0, vector.zz);

}

42 changes: 42 additions & 0 deletions math/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,48 @@ X.vector.cross = goog.math.Vec3.cross;
X.vector.distance = goog.math.Vec3.distance;
X.vector.lerp = goog.math.Vec3.lerp;

// now we need to make sure we can access the x,y,z
// components of a goog.math.Vec3 which might be renamed
// during the compilation. we don't want to modify the goog.math.Vec3
// class so this is the easiest workaround.
/**
* Get the x component of this vector.
*
* @return {number} The x component of this vector.
* @public
*/
X.vector.prototype.__defineGetter__('xx', function() {

return this.x;

});


/**
* Get the y component of this vector.
*
* @return {number} The y component of this vector.
* @public
*/
X.vector.prototype.__defineGetter__('yy', function() {

return this.y;

});


/**
* Get the z component of this vector.
*
* @return {number} The z component of this vector.
* @public
*/
X.vector.prototype.__defineGetter__('zz', function() {

return this.z;

});


goog.exportSymbol('X.vector', X.vector);
goog.exportSymbol('X.vector.prototype.clone', X.vector.prototype.clone);
Expand Down

0 comments on commit 672927b

Please sign in to comment.