UNPKG

@rickosborne/hexgrid

Version:

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

36 lines (35 loc) 964 B
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { cubeSubtract } from "./cube-subtract.mjs"; import { CUBE_NE, CUBE_SW } from "./cube.mjs"; import { CUBE_FLAT_N, CUBE_FLAT_NW, CUBE_FLAT_S, CUBE_FLAT_SE } from "./cube.mjs"; const cubeHeading = /* @__PURE__ */ __name((from, toward) => { const { q, r, s } = cubeSubtract(toward, from); if (q === 0 && r === 0 && s === 0) { return void 0; } const sq = Math.abs(s - q); const rs = Math.abs(r - s); const qr = Math.abs(q - r); const max = Math.max(sq, rs, qr); if (rs === max) { if (r - s < 0) { return CUBE_FLAT_N; } return CUBE_FLAT_S; } if (sq === max) { if (s - q < 0) { return CUBE_FLAT_SE; } return CUBE_FLAT_NW; } if (q - r < 0) { return CUBE_SW; } return CUBE_NE; }, "cubeHeading"); export { cubeHeading }; //# sourceMappingURL=cube-heading.mjs.map