Comparing version 0.2.4 to 0.2.5
@@ -1,2 +0,2 @@ | ||
{ | ||
u | ||
"name": "victor", | ||
@@ -8,3 +8,3 @@ "main": "build/victor.js", | ||
}, | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"homepage": "https://github.com/maxkueng/victor", | ||
@@ -11,0 +11,0 @@ "authors": [ |
22
index.js
@@ -736,3 +736,25 @@ exports = module.exports = Victor; | ||
/** | ||
* Projects a vector onto another vector, setting itself to the result. | ||
* | ||
* ### Examples: | ||
* var vec = new Victor(100, 0); | ||
* var vec2 = new Victor(100, 100); | ||
* | ||
* vec.projectOnto(vec2); | ||
* vec.toString(); | ||
* // => x:50, y:50 | ||
* | ||
* @param {Victor} vector The other vector you want to project this vector onto | ||
* @return {Victor} `this` for chaining capabilities | ||
* @api public | ||
*/ | ||
Victor.prototype.projectOnto = function (vec2) { | ||
var coeff = ( (this.x * vec2.x)+(this.y * vec2.y) ) / ((vec2.x*vec2.x)+(vec2.y*vec2.y)); | ||
this.x = coeff * vec2.x; | ||
this.y = coeff * vec2.y; | ||
return this; | ||
}; | ||
Victor.prototype.horizontalAngle = function () { | ||
@@ -739,0 +761,0 @@ return Math.atan2(this.y, this.x); |
{ | ||
"name": "victor", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "A JavaScript 2D vector class with methods for common vector operations", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26886
999