Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "jscoord", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A simple Map coordinate system for NodeJS and potentially the browser.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,2 +22,13 @@ class JSCoord { | ||
this.z = z | ||
/** | ||
* The one variable you should modify. It can store any arbitrary data. | ||
*/ | ||
this.data = new Proxy({}, { | ||
set (o, p, v) { | ||
return o[p] = v | ||
}, | ||
get (o, p) { | ||
return o[p] | ||
} | ||
}) | ||
} | ||
@@ -105,2 +116,32 @@ /** | ||
} | ||
/** | ||
* Invert all axies. | ||
*/ | ||
inv () { | ||
this["x", "y", "z"] = [0 - this.x, 0 - this.y, 0 - this.z] | ||
return this | ||
} | ||
/** | ||
* Increase all axies by amount. | ||
* @param {Number} amount | ||
*/ | ||
incr (amount = 1) { | ||
this["x", "y", "z"] = [this.x += 1, this.y += 1, this.z += 1] | ||
return this | ||
} | ||
/** | ||
* Decrease all axies by amount. | ||
* @param {Number} amount | ||
*/ | ||
decr (amount = 1) { | ||
this["x", "y", "z"] = [this.x -= 1, this.y -= 1, this.z -= 1] | ||
return this | ||
} | ||
/** | ||
* Invert all axies. | ||
*/ | ||
inv () { | ||
this["x", "y", "z"] = [0 - this.x, 0 - this.y, 0 - this.z] | ||
return this | ||
} | ||
get array () { | ||
@@ -171,3 +212,3 @@ return [this.x, this.y, this.z] | ||
} | ||
} | ||
} | ||
/** | ||
@@ -184,12 +225,7 @@ * Resets x, y, z to 0. | ||
* Get value difference of 2 coordinate sets. | ||
* @param {Number} x | ||
* @param {Number} y | ||
* @param {Number} z | ||
* @param {Number[]} coordinates | ||
*/ | ||
rlt (x, y, z) { | ||
this.relativitySet = { | ||
x: x - this.x, | ||
y: y - this.y, | ||
z: z - this.z | ||
} | ||
rlt (...coordinates) { | ||
let x = coordinates[0][0] || coordinates[0], y = coordinates[0][1] || coordinates[1] || coordinates[0][0] || coordinates[0], z = coordinates[0][2] || coordinates[2] | ||
this.relativitySet = { x, y, z } | ||
return this | ||
@@ -201,3 +237,3 @@ } | ||
get rltJSON () { | ||
return this.relativitySet | ||
return { x: this.x - this.relativitySet.x, y: this.y - this.relativitySet.y, z: this.z - this.relativitySet.z } | ||
} | ||
@@ -208,3 +244,3 @@ /** | ||
get rltArray () { | ||
return [this.relativitySet.x, this.relativitySet.y, this.relativitySet.z] | ||
return [this.x - this.relativitySet.x, this.y - this.relativitySet.y, this.z - this.relativitySet.z] | ||
} | ||
@@ -218,9 +254,9 @@ /** | ||
if (set.toLowerCase() == "xy" || set.toLowerCase() == "yx") { | ||
return Math.atan(this.relativitySet.y / this.relativitySet.x) * 180 / Math.PI | ||
return Math.atan(this.y - this.relativitySet.y / this.x - this.relativitySet.x) * 180 / Math.PI | ||
} | ||
if (set.toLowerCase() == "yz" || set.toLowerCase() == "zy") { | ||
return Math.atan(this.relativitySet.z / this.relativitySet.y) * 180 / Math.PI | ||
return Math.atan(this.z - this.relativitySet.z / this.y - this.relativitySet.y) * 180 / Math.PI | ||
} | ||
if (set.toLowerCase() == "zx" || set.toLowerCase() == "xz") { | ||
return Math.atan(this.relativitySet.x / this.relativitySet.z) * 180 / Math.PI | ||
return Math.atan(this.x - this.relativitySet.x / this.z - this.relativitySet.z) * 180 / Math.PI | ||
} | ||
@@ -227,0 +263,0 @@ return undefined |
18094
335