Skip to content

Commit

Permalink
vec2.length
Browse files Browse the repository at this point in the history
  • Loading branch information
sinisterchipmunk committed May 3, 2012
1 parent 3e38519 commit 13f9d46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gl-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,18 @@
dest[2] = z;
return dest;
};

/**
* Caclulates the length of a vec2
*
* @param {vec2} vec vec2 to calculate length of
*
* @returns {Number} Length of vec
*/
vec2.length = function (vec) {
var x = vec[0], y = vec[1];
return Math.sqrt(x * x + y * y);
};

/*
* Exports
Expand Down
4 changes: 4 additions & 0 deletions spec/javascripts/vec2_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe("vec2", function() {
});
});

describe("length", function() {
it("should return the correct value", function() { expect(vec2.length(vecA)).toBeEqualish(2.236067); });
});

describe("cross", function() {
describe("with dest given", function() {
beforeEach(function() { result = vec2.cross(vecA, vecB, dest); });
Expand Down

0 comments on commit 13f9d46

Please sign in to comment.