wrapping for radial, hexagonal, maps
This commit is contained in:
14
src/hex.js
14
src/hex.js
@@ -78,7 +78,7 @@ export default class Hex extends Point {
|
||||
|
||||
if (arguments.length === 1) {
|
||||
const {q, r, s = -q - r} = arguments[0];
|
||||
const {x, y, z = -x - y} = arguments[0];
|
||||
const {x, z, y = -x - z} = arguments[0];
|
||||
|
||||
this.x = !isNaN(q) ? q : x;
|
||||
this.y = !isNaN(s) ? s : y;
|
||||
@@ -152,6 +152,14 @@ export default class Hex extends Point {
|
||||
return this;
|
||||
}
|
||||
|
||||
subtractHex (hex) {
|
||||
this.x -= hex.x;
|
||||
this.y -= hex.y;
|
||||
this.z -= hex.z;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
getAxial () {return {q: this.x, r: this.z};}
|
||||
|
||||
setAxial (newAxial) {
|
||||
@@ -167,4 +175,8 @@ export default class Hex extends Point {
|
||||
this.y = computeY(this.x, this.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
distance (hex) {
|
||||
return Math.max(Math.abs(this.x - hex.x), Math.abs(this.y - hex.y), Math.abs(this.z - hex.z));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user