UNPKG

@rickosborne/hexgrid

Version:

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

52 lines (51 loc) 1.57 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { EVEN_Q, EVEN_R, ODD_Q, ODD_R } from "./hex-system.mjs"; const SIMPLE_AXIAL_KEY = Object.freeze({ [EVEN_Q]: "q", [EVEN_R]: "r", [ODD_Q]: "q", [ODD_R]: "r" }); const COMPLEX_AXIAL_KEY = Object.freeze({ [EVEN_Q]: "r", [EVEN_R]: "q", [ODD_Q]: "r", [ODD_R]: "q" }); const offsetFromQRS = /* @__PURE__ */ __name((system, point) => { const simpleAxialKey = SIMPLE_AXIAL_KEY[system]; const simpleIn = point[simpleAxialKey]; const complexAxialKey = COMPLEX_AXIAL_KEY[system]; const complexIn = point[complexAxialKey]; let bit = simpleIn & 1; if (system === ODD_R || system === ODD_Q) { bit = -bit; } const complexOut = complexIn + (simpleIn + bit) / 2; let col; let row; if (system === ODD_R || system === EVEN_R) { col = complexOut; row = simpleIn; } else { col = simpleIn; row = complexOut; } return { col, row, system }; }, "offsetFromQRS"); const oddRFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(ODD_R, point), "oddRFromQRS"); const oddQFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(ODD_Q, point), "oddQFromQRS"); const evenRFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(EVEN_R, point), "evenRFromQRS"); const evenQFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(EVEN_Q, point), "evenQFromQRS"); export { evenQFromQRS, evenRFromQRS, oddQFromQRS, oddRFromQRS }; //# sourceMappingURL=offset-from-qrs.mjs.map