UNPKG

@rickosborne/hexgrid

Version:

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

36 lines (35 loc) 1.26 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 DIRECTION_DIFFERENCES = Object.freeze({ [EVEN_Q]: [ [[1, 1], [1, 0], [0, -1], [-1, 0], [-1, 1], [0, 1]], [[1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [0, 1]] ], [EVEN_R]: [ [[1, 0], [1, -1], [0, -1], [-1, 0], [0, 1], [1, 1]], [[1, 0], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1]] ], [ODD_Q]: [ [[1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [0, 1]], [[1, 1], [1, 0], [0, -1], [-1, 0], [-1, 1], [0, 1]] ], [ODD_R]: [ [[1, 0], [0, -1], [-1, 1], [-1, 0], [-1, 1], [0, 1]], [[1, 0], [1, -1], [0, -1], [-1, 0], [0, 1], [1, 1]] ] }); const offsetNeighbor = /* @__PURE__ */ __name((offset, direction) => { const simpleKey = offset.system === ODD_Q || offset.system === EVEN_Q ? "col" : "row"; const bit = offset[simpleKey] & 1; const [colStep, rowStep] = DIRECTION_DIFFERENCES[offset.system][bit][direction]; return { col: offset.col + colStep, row: offset.row + rowStep, system: offset.system }; }, "offsetNeighbor"); export { offsetNeighbor }; //# sourceMappingURL=offset-neighbor.mjs.map