UNPKG

@rickosborne/hexgrid

Version:

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

55 lines (54 loc) 2.25 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var offset_neighbor_exports = {}; __export(offset_neighbor_exports, { offsetNeighbor: () => offsetNeighbor }); module.exports = __toCommonJS(offset_neighbor_exports); var import_hex_system = require("./hex-system.cjs"); const DIRECTION_DIFFERENCES = Object.freeze({ [import_hex_system.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]] ], [import_hex_system.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]] ], [import_hex_system.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]] ], [import_hex_system.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 === import_hex_system.ODD_Q || offset.system === import_hex_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"); //# sourceMappingURL=offset-neighbor.cjs.map