wrapping for pointy hexagons

This commit is contained in:
Gavin McDonald
2019-01-05 16:51:52 -05:00
parent 87c2fd9885
commit 28f9647c3a
3 changed files with 149 additions and 73 deletions

View File

@@ -35,7 +35,37 @@ function roundOff(hex) {
}
export default class Hex extends Point {
static offsetToCube (col, row) {
static qrToCube (q, r) {
return {
x: q,
y: computeY(q, r),
z: r,
};
}
static cubeToEvenR ({x, y, z}) {
const col = x + (z + (z & 1)) / 2;;
const row = z;
return {col, row};
}
static evenRToCube (col, row) {
const x = col - (row + (row & 1)) / 2;;
const z = row;
const y = -x - z;
return new Hex(x, y, z);
}
static cubeToEvenQ ({x, y, z}) {
const col = x;
const row = z + (x + (x & 1)) / 2;
return {col, row};
}
static evenQToCube (col, row) {
const x = col;
const z = row - (col + (col & 1)) / 2;
const y = -x - z;
@@ -137,11 +167,4 @@ export default class Hex extends Point {
this.y = computeY(this.x, this.z);
return this;
}
getOffsetHex () {
const col = this.x;
const row = this.z + (this.x + (this.x & 1)) / 2;
return {col, row};
}
}