wrapping for radial, hexagonal, maps

This commit is contained in:
Gavin McDonald
2019-01-06 15:34:56 -05:00
parent 28f9647c3a
commit 7c3ee5b475
3 changed files with 102 additions and 154 deletions

View File

@@ -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));
}
}