UNPKG

@rickosborne/hexgrid

Version:

Rick Osborne's collection of hexagonal grid-related code.

46 lines (45 loc) 1.19 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { AXIAL, EVEN_Q, EVEN_R, ODD_Q, ODD_R } from "./hex-system.mjs"; const SIMPLE_ROW_COL_KEY = Object.freeze({ [EVEN_Q]: "col", [EVEN_R]: "row", [ODD_Q]: "col", [ODD_R]: "row" }); const COMPLEX_ROW_COL_KEY = Object.freeze({ [EVEN_Q]: "row", [EVEN_R]: "col", [ODD_Q]: "row", [ODD_R]: "col" }); const axialFromOffset = /* @__PURE__ */ __name((offset) => { const system = offset.system; const simpleRowColKey = SIMPLE_ROW_COL_KEY[system]; const complexRowColKey = COMPLEX_ROW_COL_KEY[system]; const simpleIn = offset[simpleRowColKey]; const complexIn = offset[complexRowColKey]; let bit = simpleIn & 1; if (system === ODD_Q || system === ODD_R) { bit = -bit; } let q; let r; const complexOut = complexIn - (simpleIn + bit) / 2; if (system === ODD_R || system === EVEN_R) { q = complexOut; r = simpleIn; } else { q = simpleIn; r = complexOut; } return { q, r, system: AXIAL }; }, "axialFromOffset"); export { axialFromOffset }; //# sourceMappingURL=axial-from-offset.mjs.map