wrapping for pointy hexagons
This commit is contained in:
39
src/hex.js
39
src/hex.js
@@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user