Permalink
Browse files

vec2.set

  • Loading branch information...
1 parent 018e2c1 commit 37608600a87c1864a778f62800b54d8915298641 @sinisterchipmunk sinisterchipmunk committed May 2, 2012
Showing with 34 additions and 1 deletion.
  1. +14 −1 gl-matrix.js
  2. +20 −0 spec/javascripts/vec2_spec.js
View
@@ -2367,10 +2367,23 @@
vec2.dist = function (vecA, vecB) {
var x = vecB[0] - vecA[0],
y = vecB[1] - vecA[1];
-
return Math.sqrt(x*x + y*y);
};
+ /**
+ * Copies the values of one vec2 to another
+ *
+ * @param {vec2} vec vec2 containing values to copy
+ * @param {vec2} dest vec2 receiving copied values
+ *
+ * @returns {vec2} dest
+ */
+ vec2.set = function (vec, dest) {
+ dest[0] = vec[0];
+ dest[1] = vec[1];
+ return dest;
+ };
+
/*
* Exports
*/
@@ -3,6 +3,26 @@ describe("vec2", function() {
var vecA, vecB, result;
beforeEach(function() { vecA = [1, 2]; vecB = [3, 4]; dest = [0, 0]; });
+ describe("when Float32Array is not supported", function() {
+ beforeEach(function() { setMatrixArrayType(Array); });
+
+ it("should initialize to 0", function() {
+ vec = vec2.create();
+ expect(vec[0]).toEqual(0);
+ expect(vec[1]).toEqual(0);
+ });
+ });
+
+ describe("set", function() {
+ beforeEach(function() { vec = vec2.create() });
+
+ it("should assign values", function() {
+ vec2.set([1,2], vec);
+ expect(vec[0]).toEqual(1);
+ expect(vec[1]).toEqual(2);
+ });
+ });
+
describe("dist", function() {
beforeEach(function() { result = vec2.dist(vecA, vecB); });

0 comments on commit 3760860

Please sign in to comment.