@rickosborne/hexgrid
Version:
Rick Osborne's collection of hexagonal grid-related code.
51 lines (50 loc) • 2.34 kB
JavaScript
;
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 qrs_from_pixel_exports = {};
__export(qrs_from_pixel_exports, {
flatQRSFromPixel: () => flatQRSFromPixel,
pointyQRSFromPixel: () => pointyQRSFromPixel,
qrsFromPixel: () => qrsFromPixel
});
module.exports = __toCommonJS(qrs_from_pixel_exports);
var import_cube_round = require("./cube-round.cjs");
var import_cube = require("./cube.cjs");
var import_hex_system = require("./hex-system.cjs");
const MAG_2_3 = 2 / 3;
const flatQRSFromPixel = /* @__PURE__ */ __name(({ x, y }, builder, scale = 1) => {
const q = MAG_2_3 * x / scale;
const r = (import_hex_system.SQRT_3_3 * y - x / 3) / scale;
const round = (0, import_cube_round.cubeRound)((0, import_cube.cubeFromQR)(q, r));
return builder(round.q, round.r);
}, "flatQRSFromPixel");
const pointyQRSFromPixel = /* @__PURE__ */ __name(({ x, y }, builder, scale = 1) => {
const q = (import_hex_system.SQRT_3_3 * x - y / 3) / scale;
const r = MAG_2_3 * y / scale;
const round = (0, import_cube_round.cubeRound)((0, import_cube.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");
//# sourceMappingURL=qrs-from-pixel.cjs.map