UNPKG

@rickosborne/hexgrid

Version:

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

71 lines (70 loc) 2.8 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_from_qrs_exports = {}; __export(offset_from_qrs_exports, { evenQFromQRS: () => evenQFromQRS, evenRFromQRS: () => evenRFromQRS, oddQFromQRS: () => oddQFromQRS, oddRFromQRS: () => oddRFromQRS }); module.exports = __toCommonJS(offset_from_qrs_exports); var import_hex_system = require("./hex-system.cjs"); const SIMPLE_AXIAL_KEY = Object.freeze({ [import_hex_system.EVEN_Q]: "q", [import_hex_system.EVEN_R]: "r", [import_hex_system.ODD_Q]: "q", [import_hex_system.ODD_R]: "r" }); const COMPLEX_AXIAL_KEY = Object.freeze({ [import_hex_system.EVEN_Q]: "r", [import_hex_system.EVEN_R]: "q", [import_hex_system.ODD_Q]: "r", [import_hex_system.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 === import_hex_system.ODD_R || system === import_hex_system.ODD_Q) { bit = -bit; } const complexOut = complexIn + (simpleIn + bit) / 2; let col; let row; if (system === import_hex_system.ODD_R || system === import_hex_system.EVEN_R) { col = complexOut; row = simpleIn; } else { col = simpleIn; row = complexOut; } return { col, row, system }; }, "offsetFromQRS"); const oddRFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(import_hex_system.ODD_R, point), "oddRFromQRS"); const oddQFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(import_hex_system.ODD_Q, point), "oddQFromQRS"); const evenRFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(import_hex_system.EVEN_R, point), "evenRFromQRS"); const evenQFromQRS = /* @__PURE__ */ __name((point) => offsetFromQRS(import_hex_system.EVEN_Q, point), "evenQFromQRS"); //# sourceMappingURL=offset-from-qrs.cjs.map