image-in-browser
Version:
Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)
42 lines • 1.09 kB
JavaScript
export class MathUtils {
static fract(x) {
return x - Math.floor(x);
}
static smoothStep(edge0, edge1, x) {
const t0 = (x - edge0) / (edge1 - edge0);
const t = MathUtils.clamp(t0, 0, 1);
return t * t * (3 - 2 * t);
}
static mix(x, y, a) {
return x * (1 - a) + y * a;
}
static sign(x) {
return x < 0 ? -1 : x > 0 ? 1 : 0;
}
static step(edge, x) {
return x < edge ? 0 : 1;
}
static length3(x, y, z) {
return Math.sqrt(x * x + y * y + z * z);
}
static gcd(x, y) {
let _x = Math.abs(x);
let _y = Math.abs(y);
while (_y) {
const t = _y;
_y = _x % _y;
_x = t;
}
return _x;
}
static clamp(num, low, high) {
return Math.max(low, Math.min(num, high));
}
static clampInt(num, low, high) {
return Math.trunc(MathUtils.clamp(num, low, high));
}
static clampInt255(num) {
return Math.trunc(MathUtils.clamp(num, 0, 255));
}
}
//# sourceMappingURL=math-utils.js.map