{"_id":"vector2d","_rev":"40-955f3354ee40c9b92807a6a45e8d7eff","name":"vector2d","description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","dist-tags":{"latest":"2.0.2"},"versions":{"0.0.1":{"name":"vector2d","keywords":["vector","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32 or standard Array based vectors","main":".index.js","author":{"name":"Evan Shortiss"},"version":"0.0.1","repository":{"type":"git","url":"git@github.com:evanshortiss/vec2d.git"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"dependencies":{"commander":"1.2.0"},"engines":{"node":">=0.8.8"},"_id":"vector2d@0.0.1","dist":{"shasum":"d52d001a0ea7b46f466264ac50b935a4277fcb29","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-0.0.1.tgz"},"_npmVersion":"1.1.59","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"0.0.2":{"name":"vector2d","keywords":["vector","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32 or standard Array based vectors","main":"./vec2d.js","author":{"name":"Evan Shortiss"},"version":"0.0.2","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"dependencies":{"commander":"1.2.0"},"engines":{"node":">=0.8.8"},"_id":"vector2d@0.0.2","dist":{"shasum":"1527bd1dcd2c213dc467f543a546f59802ad6f50","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-0.0.2.tgz"},"_npmVersion":"1.1.59","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"0.0.3":{"name":"vector2d","keywords":["vector","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","main":"./vec2d.js","author":{"name":"Evan Shortiss"},"version":"0.0.3","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"dependencies":{"commander":"1.2.0"},"engines":{"node":">=0.8.8"},"_id":"vector2d@0.0.3","dist":{"shasum":"da865e4be42ad91160b9e9c7cbb588437b687b0d","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-0.0.3.tgz"},"_npmVersion":"1.1.59","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"1.0.0":{"name":"vector2d","keywords":["vector","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","main":"./build/vec2d.js","author":{"name":"Evan Shortiss"},"version":"1.0.0","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"devDependencies":{"grunt":"~0.4.2","grunt-contrib-jshint":"~0.8.0","grunt-contrib-nodeunit":"~0.2.0","grunt-contrib-uglify":"~0.3.1","grunt-contrib-concat":"~0.3.0","grunt-mocha-test":"~0.8.2","grunt-text-replace":"~0.3.10"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"dependencies":{"commander":"1.2.0"},"engines":{"node":">=0.8.8"},"homepage":"https://github.com/evanshortiss/vec2d","_id":"vector2d@1.0.0","dist":{"shasum":"ba8fb3f1f7956824f74053244fae25a3221fd734","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-1.0.0.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"1.1.0":{"name":"vector2d","keywords":["physics","math","vectors","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","main":"./build/vec2d.js","author":{"name":"Evan Shortiss"},"version":"1.1.0","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"devDependencies":{"commander":"1.2.0","grunt":"~0.4.2","grunt-contrib-jshint":"~0.8.0","grunt-contrib-nodeunit":"~0.2.0","grunt-contrib-uglify":"~0.3.1","grunt-contrib-concat":"~0.3.0","grunt-mocha-test":"~0.8.2","grunt-text-replace":"~0.3.10","jsdoc":"~3.3.0-alpha3"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"engines":{"node":">=0.8.8"},"homepage":"https://github.com/evanshortiss/vec2d","_id":"vector2d@1.1.0","dist":{"shasum":"e1f8117e12200f6f2bb8e1ca460066163510fc87","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-1.1.0.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"2.0.0":{"name":"vector2d","keywords":["physics","math","vectors","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","main":"./src/Vec2D.js","author":{"name":"Evan Shortiss"},"version":"2.0.0","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"testling":{"harness":"mocha-bdd","files":"test/*.js","browsers":["ie/8..latest","chrome/22..latest","firefox/16..latest","safari/4..latest","opera/11.0..latest","iphone/6..latest","ipad/6..latest","android-browser/latest"]},"devDependencies":{"mocha":"1.18.2","grunt":"~0.4.2","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.3.1","grunt-mocha-test":"~0.8.2","browserify":"^4.1.5","grunt-browserify":"^2.1.0"},"scripts":{"test":"mocha --ui bdd"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"engines":{"node":">=0.8.8"},"homepage":"https://github.com/evanshortiss/vec2d","_id":"vector2d@2.0.0","dist":{"shasum":"ddcf2f13fa8a216c1ee7e651b11ac6c5738a9fcb","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-2.0.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"2.0.1":{"name":"vector2d","keywords":["physics","math","vectors","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","main":"./src/Vec2D.js","author":{"name":"Evan Shortiss"},"version":"2.0.1","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"testling":{"harness":"mocha-bdd","files":"test/*.js","browsers":["ie/8..latest","chrome/22..latest","firefox/16..latest","safari/4..latest","opera/11.0..latest","iphone/6..latest","ipad/6..latest","android-browser/latest"]},"devDependencies":{"mocha":"1.18.2","grunt":"~0.4.2","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.3.1","grunt-mocha-test":"~0.8.2","browserify":"^4.1.5","grunt-browserify":"^2.1.0"},"scripts":{"test":"grunt build && mocha --ui bdd"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"engines":{"node":">=0.8.8"},"homepage":"https://github.com/evanshortiss/vec2d","_id":"vector2d@2.0.1","dist":{"shasum":"0fd548b73184b7f45a8d19946c422e1b9b546520","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-2.0.1.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]},"2.0.2":{"name":"vector2d","keywords":["physics","math","vectors","2d","float","float32","Float32Array"],"description":"2D Vector library offering Float32Array, Object or standard Array based vectors.","main":"./src/Vec2D.js","author":{"name":"Evan Shortiss"},"version":"2.0.2","repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"testling":{"harness":"mocha-bdd","files":"test/*.js","browsers":["ie/8..latest","chrome/22..latest","firefox/16..latest","safari/4..latest","opera/11.0..latest","iphone/6..latest","ipad/6..latest","android-browser/latest"]},"devDependencies":{"mocha":"1.18.2","grunt":"~0.4.2","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.3.1","grunt-mocha-test":"~0.8.2","browserify":"^4.1.5","grunt-browserify":"^2.1.0"},"scripts":{"test":"grunt build && mocha --ui bdd"},"directories":{"test":"./test"},"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"},"licenses":[{"type":"MIT"}],"engines":{"node":">=0.8.8"},"homepage":"https://github.com/evanshortiss/vec2d","_id":"vector2d@2.0.2","dist":{"shasum":"2aba1d1f48efecbe46a07eeccb35c76b255daa65","tarball":"http://registry.npmjs.org/vector2d/-/vector2d-2.0.2.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"evanshortiss","email":"evanshortiss@gmail.com"},"maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}]}},"readme":"Vec2D - 2D Vector Library for JavaScript\n===\n\n## Browser Support\n[![browser support](https://ci.testling.com/evanshortiss/vec2d.png)\n](https://ci.testling.com/evanshortiss/vec2d)\n\nFull API support is available in the browsers listed in green above. Browsers marked in red generally support the library, but do not support Float32Vectors so simply don't use these and you'll be fine.\n\n## Version 2.0.0+ Breaking Changes\nVersion 2.0.0 has been updated to remove my manual build steps in favour of using the awesome [browserify](http://browserify.org/).\n\nAs of version 2.0.0 all methods on the Vec2D object have been removed, only the classes *ArrayVector*, *Float32Vector* and *ObjectVector* are left. I made this choice to ensure it's always explicitly known which type of Vector is being created and to make the library easier to work with.\n\n## About\nAn easy to use 2D Vector library with 3 methods of Vector representation to allow you to squeeze out as much performance as possible.\n\nVec2D provides 3 main modes of Vector representations (classes):\n\n* ArrayVector\n* Float32Vector\n* ObjectVector\n\nRegardless of class used all library functions can be used in the same manner and developers will not need to worry about the vector representation. You should also be able to mix vector types as the interface and base class used is consistent across the types with only the underlying data structure used to store the axes being modified.\n\nThe mode used depends on use case, for example if you plan to create many vectors in each frame of a game, but perform very few operations on them then ArrayVector might be fastest. Float32Arrays can be used for faster operations on vectors, but creating these is expensive so it is important to choose the best vector representation for your application.\n\n## Usage\n\n### Node.js\nTo install:\n\n```bash\n  $ npm install vector2d\n```\n\nTo use:\n\n```javascript\n  // Usage in node.js application if installed via npm\n  var Vec2D = require('vector2d');\n```\n\n### Browser\nJust include a script tag as you'd expect:\n\n```javascript\n<script src=\"path/to/vec2d.js\" type=\"text/javascript\"></script>\n```\n\n\n## Performance\n\nPerformance can be gauged by running the command below. This currently only operates in a node environment so you need to run it from a terminal.\n\n```bash\n  ~/workspaces/vec2d$ node performance/index.js\n\n  Tests are averaged from 5 passes/runs on a set of 100000 vectors. Please wait...\n\n  Float32Vector:\n  \"generate (e.g new Float32Vector)\", 1222ms\n  \"add\", 33ms\n  \"subtract\", 32.6ms\n  \"round\", 4.6ms\n  \"abs\", 3ms\n  \"magnitude\", 3ms\n  \"clone\", 1056.6ms\n  \"zero\", 2.8ms\n  \"reverse\", 3ms\n  \"toString\", 10.6ms\n  \"multiplyByScalar\", 4ms\n  \"normalise\", 6.6ms\n\n  ArrayVector:\n  \"generate (e.g new Vector)\", 31ms\n  \"add\", 59.2ms\n  \"subtract\", 40.2ms\n  \"round\", 7ms\n  \"abs\", 4.4ms\n  \"magnitude\", 5.2ms\n  \"clone\", 7ms\n  \"zero\", 2.8ms\n  \"reverse\", 5.8ms\n  \"toString\", 12.6ms\n  \"multiplyByScalar\", 7.4ms\n  \"normalise\", 13ms\n\n  ObjectVector:\n  \"generate (e.g new ObjectVector)\", 103ms\n  \"add\", 54ms\n  \"subtract\", 55ms\n  \"round\", 25.6ms\n  \"abs\", 6.8ms\n  \"magnitude\", 6ms\n  \"clone\", 25.8ms\n  \"zero\", 3ms\n  \"reverse\", 16.4ms\n  \"toString\", 13.4ms\n  \"multiplyByScalar\", 6.4ms\n  \"normalise\", 16.8ms\n```\n\n## Library Function Structure\nTo avoid garbage collection and allow for faster operation all vector instance methods will modify the existing vector where possible. If you want to produce a new vector as a result of an operation do not use instance methods. The example below demonstrates this.\n\n\n```javascript\n  // Create a vector\n  var v0 = Vec2D.ObjectVector(23, 150);\n  var v1 = Vec2D.ObjectVector(23, 150);\n  var v2 = Vec2D.ObjectVector(13, -50);\n\n  // Add v1 and v0 to produce a new Vector\n  var result = v0.clone().add(v1);\n  // Prints \"(46, 300)\"\n  result.toString();\n  // Prints \"(23, 150)\"\n  v0.toString();\n\n  // Add v1 to v0 using instance method.\n  v0.add(v1);\n  // Prints \"(46, 300)\" as the underlying vector has been modified\n  v0.toString();\n\n  // Will return -14402\n  v2.dot(v0)\n```\n\n## API\n\n### Instance Methods\nVectors returned by calling **Vec2D.ObjectVector/ArrayVector/Float32Vector(x, y)** have the following methods accessible on them. All instance methods modify the underlying vector where appropriate. For example calling *multiplyByScalar* will multiply the vector x and y components by the provided number and return the updated underlying vector itself (a reference to *this*) rather than a new instance. The benefit if this is that less objects are created meaning improved performance and methods can be chained.\n\nSo, what if I don't want to modify the underlying vector you ask!? Simple *v.clone()*, checkout the example below.\n\n```javascript\n  var av0 = Vec2D.ArrayVector(10, 0),\n    av1 = Vec2D.ArrayVector(0, 5);\n\n  // Methods are chainable where you'd expect\n  var result = av0.clone().add(av1);\n  result.toString(); // (10, 5)\n\n  // It hasn't changed!\n  av0.toString(); // (10, 0)\n```\n\n##### setAxes(x, y)\n\n##### getX()\n\n##### setX(x)\n\n##### getY()\n\n##### setY(y)\n\n##### toString()\nConvert vector to a String with format \"(0, 0)\"\n\n##### toArray()\nConvert vector to standard JavaScript Array [2.823, 1.541]\n\n##### toObject()\nCovert vector to a JSON object with format { x: 1.4, y: 8 }.\n\n##### add(vector)\nModify this vector by adding the provided vector to it.\n\n##### subtract(vector)\nModify this vector by subtracting the provided vector from it.\n\n##### equals(vector)\nCheck does this vector equal the provided vector.\n\n##### mulV(vector)\nMultiply this vector by provided vector.\n\n##### divV(vector)\nDivide this vector by provided vector.\n\n##### mulS(number)\nMultiply this vector by a number.\n\n##### divS(number)\nDivide this vector by a number.\n\n##### dot(vector)\nReturns dot product from this vector and the provided vector.\n\n##### cross(vector)\nReturns cross product from this vector and the provided vector.\n\n##### reverse()\nReverse the values in this vector.\n\n##### abs()\nConvert stored values to absolute values.\n\n##### distance(vec)\nFind the distance between this vector and the provided _vec_;\n\n##### zero()\nSet vector values to 0.\n\n##### rotate(radians)\nRotate vector by provided radians.\n\n##### clone()\nReturns a clone of this vector.\n\n##### normalise() / normalize() / unit()\n\n##### magnitude() / length()\n\n##### lengthSq()\n\n","maintainers":[{"name":"evanshortiss","email":"evanshortiss@gmail.com"}],"time":{"modified":"2014-05-18T20:05:26.811Z","created":"2013-07-19T23:16:29.930Z","0.0.1":"2013-07-19T23:16:36.001Z","0.0.2":"2013-07-21T21:28:34.876Z","0.0.3":"2013-07-26T17:13:53.126Z","1.0.0":"2014-01-22T23:14:15.536Z","1.1.0":"2014-01-26T00:10:03.582Z","2.0.0":"2014-05-18T00:39:11.475Z","2.0.1":"2014-05-18T16:15:33.802Z","2.0.2":"2014-05-18T20:05:26.811Z"},"author":{"name":"Evan Shortiss"},"repository":{"type":"git","url":"https://github.com/evanshortiss/vec2d.git"},"readmeFilename":"README.md","homepage":"https://github.com/evanshortiss/vec2d","keywords":["physics","math","vectors","2d","float","float32","Float32Array"],"bugs":{"url":"https://github.com/evanshortiss/vec2d/issues"}}