@typed-tabletop-simulator/lib
Version:
Library with some helping modules for working with Tabletop Simulator
27 lines (26 loc) • 922 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const hexGrid_1 = require("./hexGrid");
class PointyHexGrid extends hexGrid_1.HexGrid {
positionToGrid = (point) => {
const q = ((Math.sqrt(3) / 3) * point.x - (1 / 3) * point.y) / this.size;
const r = ((2 / 3) * point.y) / this.size;
return { q: q, r: r };
};
gridToPosition = (coord) => {
const x = this.size * (Math.sqrt(3) * coord.q + (Math.sqrt(3) / 2) * coord.r);
const y = this.size * ((3 / 2) * coord.r);
return { x: x, y: y };
};
toOffset(coord) {
const q = coord.q + (coord.r - this.oddValue(coord.r)) / 2;
const r = coord.r;
return { q: q, r: r };
}
toAxial(coord) {
const q = coord.q - (coord.r - this.oddValue(coord.r)) / 2;
const r = coord.r;
return { q: q, r: r };
}
}
exports.default = PointyHexGrid;