Comparing version 0.1.2 to 0.1.4
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/maxkueng/victor", | ||
@@ -11,0 +11,0 @@ "authors": [ |
114
index.js
@@ -23,3 +23,27 @@ exports = module.exports = Victor; | ||
} | ||
/** | ||
* The X axis | ||
* | ||
* ### Examples: | ||
* var vec = new Victor.fromArray(42, 21); | ||
* | ||
* vec.x; | ||
* // => 42 | ||
* | ||
* @api public | ||
*/ | ||
this.x = x || 0; | ||
/** | ||
* The Y axis | ||
* | ||
* ### Examples: | ||
* var vec = new Victor.fromArray(42, 21); | ||
* | ||
* vec.y; | ||
* // => 21 | ||
* | ||
* @api public | ||
*/ | ||
this.y = y || 0; | ||
@@ -29,32 +53,2 @@ }; | ||
/** | ||
* # Properties | ||
*/ | ||
/** | ||
* The X axis | ||
* | ||
* ### Examples: | ||
* var vec = new Victor.fromArray(42, 21); | ||
* | ||
* vec.x; | ||
* // => 42 | ||
* | ||
* @api public | ||
*/ | ||
Victor.prototype.x = 0; | ||
/** | ||
* The Y axis | ||
* | ||
* ### Examples: | ||
* var vec = new Victor.fromArray(42, 21); | ||
* | ||
* vec.y; | ||
* // => 21 | ||
* | ||
* @api public | ||
*/ | ||
Victor.prototype.y = 0; | ||
/** | ||
* # Static | ||
@@ -116,3 +110,6 @@ */ | ||
Victor.mix = function (vecA, vecB, amount) { | ||
amount = amount || 0.5 | ||
if (typeof amount === 'undefined') { | ||
amount = 0.5; | ||
} | ||
var x = (1 - amount) * vecA.x + amount * vecB.x; | ||
@@ -436,7 +433,9 @@ var y = (1 - amount) * vecA.y + amount * vecB.y; | ||
Victor.prototype.normalize = function () { | ||
if (this.length() === 0) { | ||
var length = this.length(); | ||
if (length === 0) { | ||
this.x = 1; | ||
this.y = 0; | ||
} else { | ||
this.divide(this.length()); | ||
this.divide(length); | ||
} | ||
@@ -595,3 +594,6 @@ return this; | ||
Victor.prototype.mixX = function (vec, amount) { | ||
amount = amount || 0.5; | ||
if (typeof amount === 'undefined') { | ||
amount = 0.5; | ||
} | ||
this.x = (1 - amount) * this.x + amount * vec.x; | ||
@@ -618,3 +620,6 @@ return this; | ||
Victor.prototype.mixY = function (vec, amount) { | ||
amount = amount || 0.5; | ||
if (typeof amount === 'undefined') { | ||
amount = 0.5; | ||
} | ||
this.y = (1 - amount) * this.y + amount * vec.y; | ||
@@ -641,3 +646,2 @@ return this; | ||
Victor.prototype.mix = function (vec, amount) { | ||
amount = amount || 0.5; | ||
this.mixX(vec, amount); | ||
@@ -876,6 +880,24 @@ this.mixY(vec, amount); | ||
Victor.prototype.distance = function (vec) { | ||
return Math.sqrt(this.distanceSq(vec)); | ||
}; | ||
/** | ||
* Calculates the squared euclidean distance between this vector and another | ||
* | ||
* ### Examples: | ||
* var vec1 = new Victor(100, 50); | ||
* var vec2 = new Victor(200, 60); | ||
* | ||
* vec1.distanceSq(vec2); | ||
* // => 10100 | ||
* | ||
* @param {Victor} vector The second vector | ||
* @return {Number} Distance | ||
* @api public | ||
*/ | ||
Victor.prototype.distanceSq = function (vec) { | ||
var dx = this.distanceX(vec), | ||
dy = this.distanceY(vec); | ||
return Math.sqrt(dx * dx + dy * dy); | ||
return dx * dx + dy * dy; | ||
}; | ||
@@ -896,5 +918,21 @@ | ||
Victor.prototype.length = function () { | ||
return Math.sqrt(this.x * this.x + this.y * this.y); | ||
return Math.sqrt(this.lengthSq()); | ||
}; | ||
/** | ||
* Squared length / magnitude | ||
* | ||
* ### Examples: | ||
* var vec = new Victor(100, 50); | ||
* | ||
* vec.lengthSq(); | ||
* // => 12500 | ||
* | ||
* @return {Number} Length / Magnitude | ||
* @api public | ||
*/ | ||
Victor.prototype.lengthSq = function () { | ||
return this.x * this.x + this.y * this.y; | ||
}; | ||
Victor.prototype.magnitude = Victor.prototype.length; | ||
@@ -901,0 +939,0 @@ |
{ | ||
"name": "victor", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"description": "A JavaScript 2D vector class with methods for common vector operations", | ||
@@ -19,2 +19,3 @@ "keywords": [ | ||
}, | ||
"homepage": "http://victorjs.org/", | ||
"author": "Max Kueng <me@maxkueng.com> (http://maxkueng.com/)", | ||
@@ -21,0 +22,0 @@ "contributors": [ |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 63 instances 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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
2146831
70
946
1
63