JSCoord is a simple coordinate library for Javascript. It features basic mutation methods for X, Y and Z and also provides a "Map" feature, which means you can limit the size of each Set. Modify each axis value with the built-in methods or easily add custom methods with a simple API.
new JSCoord([x, y, z])
Create a new JSCoord Set.
let coords = new JSCoord([100, 100, 100])
.x
, .y
, .z
Get X, Y or Z value. Do NOT modify these variables, they can break your coordinate set.
coords.x
.incrX(amount)
, .incrY(amount)
, .incrZ(amount)
Increments the specified axis by amount
. If amount
parameter is not provided, increments by 1.
coords.incrX(10)
.decrX(amount)
, .frcrY(amount)
, .decrZ(amount)
Decrements the specified axis by amount
. If amount
parameter is not provided, decrements by 1.
coords.decrX(10)
.setX(amount)
, .setY(amount)
, .setZ(amount)
Sets the axis value to val
.
coords.setX(20)
.invX()
, .invY()
, .invZ()
"Inverts" the number, so it becomes its negative/positive version. 3 becomes -3, -3 becomes 3 and so on.
coords.invX()
.setMap(x, y, z)
Sets the maximum range for each axis. It sets the maximum to the provided number and the minimum to the negative of the provided number. Other methods will fail if they are out of range. This will fail if axis is above limit already.
coords.setMap(100, 100, 100)
.mapJSON
Get Map as Object.
coords.mapJSON // {x: 20, y: 0, z: 0}
.mapArray
Get Map as Array.
coords.mapArray // [x, y, z]
.JSON
Returns the X, Y and Z axis values as an object.
coords.JSON // {x: 20, y: 0, z: 0}
.array
Returns the X, Y and Z axis values as an array. .array[0]
contains the X axis, .array[1]
the Y axis and .array()[2]
the Z axis.
coords.array // [x, y, z]
.reset()
Resets all of the X, Y and Z values to 0.
coords.reset()
.rlt(x, y, z)
Resets all of the X, Y and Z values to 0.
coords.rlt(10, 20, 30)
.rltJSON
Get the relativity set as an object.
coords.rltJSON // {x: 1, y: 2, z: 3}
.rltArray
Get the relativity set as an array.
coords.rltArray // [x, y, z]
.getRltAngle()
Get the angle of 2 coordinate set values. set
is the 2 axies which should be used for calculation, can be xy
, yz
or zx
.
coords.getRltAngle("xy")
new CoordChunk(maxLength)
Create a new Coordinate Chunk.
let chunk = new CoordChunk(10)
.sets
Array in which Sets are stored. Do NOT modify this variable, it can break your coordinate set.
chunk.sets
.limit
Maximum length of chunk. Do NOT modify this variable, it can break your coordinate set.
chunk.limit
.addSet(coords)
Add a Set to the Chunk. coords
can be an Array with coordinate values ([x, y, z])
or a JSCoord instance. You can not have 2 of the same coordinate sets in the same chunk.
coords.addSet(new JSCoord([100, 100, 100])
.getSet(coords)
Find a Set by coordinates. Throws if Set could not be found.
coords.getSet([100, 100, 100])
.delSet(coords)
Delete a Set from the Chunk. coords
can be an Array with coordinate values or a JSCoord instance. Throws if Set could not be found.
coords.delSet([100, 100, 100])