Skip to content

Commit

Permalink
Added vec2.copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Jones committed Aug 23, 2012
1 parent c4c1cf8 commit e9e0617
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Expand Up @@ -6,9 +6,6 @@ gem 'rake'
# https://github.com/pivotal/jasmine-gem
gem 'jasmine'

# https://github.com/cowboyd/therubyracer
gem 'therubyracer'

# https://github.com/sstephenson/sprockets
gem 'sprockets'

Expand Down
4 changes: 0 additions & 4 deletions Gemfile.lock
Expand Up @@ -16,7 +16,6 @@ GEM
selenium-webdriver (>= 0.1.3)
jasmine-core (1.2.0)
json (1.7.4)
libv8 (3.3.10.4)
libwebsocket (0.1.5)
addressable
multi_json (1.3.6)
Expand All @@ -41,8 +40,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
uglifier (1.2.7)
Expand All @@ -57,6 +54,5 @@ DEPENDENCIES
json
rake
sprockets
therubyracer
thor
uglifier
2 changes: 1 addition & 1 deletion dist/gl-matrix-min.js
Expand Up @@ -20,4 +20,4 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
(function(){"use strict";var e={};typeof exports=="undefined"?e.exports=window:e.exports=exports,function(e){(function(){var t={};t.create=function(){return new Float32Array(2)},t.clone=function(e){var t=new Float32Array(2);return t[0]=e[0],t[1]=e[1],t},t.fromValues=function(e,t){var n=new Float32Array(2);return n[0]=e,n[1]=t,n},t.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e},t.sub=t.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e},t.mul=t.multiply=function(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e},t.div=t.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e},t.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e},t.dist=t.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)},t.sqrDist=t.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},t.len=t.length=function(e){var t=e[0],n=e[1];return Math.sqrt(t*t+n*n)},t.sqrLen=t.squaredLength=function(e){var t=e[0],n=e[1];return t*t+n*n},t.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e},t.normalize=function(e,t){var n=t[0]*t[0]+t[1]*t[1];return n>0&&(n=Math.sqrt(n),e[0]=t[0]/n,e[1]=t[1]/n),e},t.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]},t.cross=function(e,t,n){var r=t[0]*n[1]-t[1]*n[0];return e[0]=e[1]=0,e[2]=r,e},t.lerp=function(e,t,n,r){var i=t[0],s=t[1];return e[0]=i+r*(n[0]-i),e[1]=s+r*(n[1]-s),e},t.str=function(e){return"vec2("+e[0]+", "+e[1]+")"},e.vec2=t})()}(e.exports)})();
(function(){"use strict";var e={};typeof exports=="undefined"?e.exports=window:e.exports=exports,function(e){(function(){var t={};t.create=function(){return new Float32Array(2)},t.clone=function(e){var t=new Float32Array(2);return t[0]=e[0],t[1]=e[1],t},t.fromValues=function(e,t){var n=new Float32Array(2);return n[0]=e,n[1]=t,n},t.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e},t.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e},t.sub=t.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e},t.mul=t.multiply=function(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e},t.div=t.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e},t.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e},t.dist=t.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)},t.sqrDist=t.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},t.len=t.length=function(e){var t=e[0],n=e[1];return Math.sqrt(t*t+n*n)},t.sqrLen=t.squaredLength=function(e){var t=e[0],n=e[1];return t*t+n*n},t.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e},t.normalize=function(e,t){var n=t[0]*t[0]+t[1]*t[1];return n>0&&(n=Math.sqrt(n),e[0]=t[0]/n,e[1]=t[1]/n),e},t.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]},t.cross=function(e,t,n){var r=t[0]*n[1]-t[1]*n[0];return e[0]=e[1]=0,e[2]=r,e},t.lerp=function(e,t,n,r){var i=t[0],s=t[1];return e[0]=i+r*(n[0]-i),e[1]=s+r*(n[1]-s),e},t.str=function(e){return"vec2("+e[0]+", "+e[1]+")"},e.vec2=t})()}(e.exports)})();
13 changes: 13 additions & 0 deletions dist/gl-matrix.js
Expand Up @@ -102,6 +102,19 @@
return out;
};

/**
* Copy the values from on vec2 to another
*
* @param {vec2} out the receiving vector
* @param {vec2} a the source vector
* @returns {vec2} out
*/
vec2.copy = function(out, a) {
out[0] = a[0];
out[1] = a[1];
return out;
};

/**
* Adds two vec2's
*
Expand Down
6 changes: 6 additions & 0 deletions spec/gl-matrix/vec2-spec.js
Expand Up @@ -40,6 +40,12 @@ describe("vec2", function() {
beforeEach(function() { result = vec2.fromValues(1, 2); });
it("should return a 2 element array initialized to the values passed", function() { expect(result).toBeEqualish([1, 2]); });
});

describe("copy", function() {
beforeEach(function() { result = vec2.copy(out, vecA); });
it("should place values into out", function() { expect(out).toBeEqualish([1, 2]); });
it("should return out", function() { expect(result).toBe(out); });
});

describe("add", function() {
describe("with a separate output vector", function() {
Expand Down
13 changes: 13 additions & 0 deletions src/gl-matrix/vec2.js
Expand Up @@ -64,6 +64,19 @@
return out;
};

/**
* Copy the values from on vec2 to another
*
* @param {vec2} out the receiving vector
* @param {vec2} a the source vector
* @returns {vec2} out
*/
vec2.copy = function(out, a) {
out[0] = a[0];
out[1] = a[1];
return out;
};

/**
* Adds two vec2's
*
Expand Down

0 comments on commit e9e0617

Please sign in to comment.