@rickosborne/hexgrid
Version:
Rick Osborne's collection of hexagonal grid-related code.
32 lines (31 loc) • 1.27 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { cubeRound } from "./cube-round.mjs";
import { cubeFromQR } from "./cube.mjs";
import { SQRT_3_3 } from "./hex-system.mjs";
const MAG_2_3 = 2 / 3;
const flatQRSFromPixel = /* @__PURE__ */ __name(({ x, y }, builder, scale = 1) => {
const q = MAG_2_3 * x / scale;
const r = (SQRT_3_3 * y - x / 3) / scale;
const round = cubeRound(cubeFromQR(q, r));
return builder(round.q, round.r);
}, "flatQRSFromPixel");
const pointyQRSFromPixel = /* @__PURE__ */ __name(({ x, y }, builder, scale = 1) => {
const q = (SQRT_3_3 * x - y / 3) / scale;
const r = MAG_2_3 * y / scale;
const round = cubeRound(cubeFromQR(q, r));
return builder(round.q, round.r);
}, "pointyQRSFromPixel");
const qrsFromPixel = /* @__PURE__ */ __name(({ x, y }, { orientation: { b0, b1, b2, b3 }, origin: { x: cx, y: cy }, size: { x: scaleX, y: scaleY } }, builder) => {
const x0 = (x - cx) / scaleX;
const y0 = (y - cy) / scaleY;
const q = b0 * x0 + b1 * y0;
const r = b2 * x0 + b3 * y0;
return builder(q, r);
}, "qrsFromPixel");
export {
flatQRSFromPixel,
pointyQRSFromPixel,
qrsFromPixel
};
//# sourceMappingURL=qrs-from-pixel.mjs.map