UNPKG

@rickosborne/hexgrid

Version:

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

65 lines (64 loc) 2.31 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 axial_from_offset_exports = {}; __export(axial_from_offset_exports, { axialFromOffset: () => axialFromOffset }); module.exports = __toCommonJS(axial_from_offset_exports); var import_hex_system = require("./hex-system.cjs"); const SIMPLE_ROW_COL_KEY = Object.freeze({ [import_hex_system.EVEN_Q]: "col", [import_hex_system.EVEN_R]: "row", [import_hex_system.ODD_Q]: "col", [import_hex_system.ODD_R]: "row" }); const COMPLEX_ROW_COL_KEY = Object.freeze({ [import_hex_system.EVEN_Q]: "row", [import_hex_system.EVEN_R]: "col", [import_hex_system.ODD_Q]: "row", [import_hex_system.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 === import_hex_system.ODD_Q || system === import_hex_system.ODD_R) { bit = -bit; } let q; let r; const complexOut = complexIn - (simpleIn + bit) / 2; if (system === import_hex_system.ODD_R || system === import_hex_system.EVEN_R) { q = complexOut; r = simpleIn; } else { q = simpleIn; r = complexOut; } return { q, r, system: import_hex_system.AXIAL }; }, "axialFromOffset"); //# sourceMappingURL=axial-from-offset.cjs.map