@thi.ng/vectors
Version:
Optimized 2d/3d/4d and arbitrary length vector operations, support for memory mapping/layouts
32 lines (31 loc) • 689 B
JavaScript
import { defOp } from "./compile/emit.js";
import { ARGS_V, NEW_OUT } from "./compile/templates.js";
const $ = (tpl, pre = NEW_OUT) => defOp(tpl, ARGS_V, ARGS_V, "o", 1, pre);
const [asIVec, asIVec2, asIVec3, asIVec4] = $(
([o, a]) => `${o}=${a}|0;`
);
const [asUVec, asUVec2, asUVec3, asUVec4] = $(
([o, a]) => `${o}=${a}>>>0;`
);
const [asBVec, asBVec2, asBVec3, asBVec4] = $(
([o, a]) => `${o}=!!${a};`
);
const [fromBVec, fromBVec2, fromBVec3, fromBVec4] = $(([o, a]) => `${o}=~~${a};`);
export {
asBVec,
asBVec2,
asBVec3,
asBVec4,
asIVec,
asIVec2,
asIVec3,
asIVec4,
asUVec,
asUVec2,
asUVec3,
asUVec4,
fromBVec,
fromBVec2,
fromBVec3,
fromBVec4
};