UNPKG

@tempots/std

Version:

Std library for TypeScript. Natural complement to the Tempo libraries.

46 lines (45 loc) 1.96 kB
import { lpad as a } from "./string.js"; const c = 1e-9, i = (t, e, n = 360) => { let o = (e - t) % n; return o < 0 && (o += n), o > n / 2 && (o -= n), o; }, h = (t, e) => { const n = Math.pow(10, e); return Math.ceil(t * n) / n; }, l = (t, e, n) => Math.min(Math.max(t, e), n), M = (t, e, n) => Math.trunc(l(t, e, n)), u = (t, e) => l(t, -e, e), g = (t, e) => t < e ? -1 : t > e ? 1 : 0, N = (t, e) => { const n = Math.pow(10, e); return Math.floor(t * n) / n; }, w = (t, e = 0) => a(t.toString(16), "0", e), s = (t, e, n) => (e - t) * n + t, A = (t, e, n, o = 360) => r(s(t, t + i(t, e, o), n), o), f = (t, e, n = 360) => { let o = (e - t) % n; return o < 0 && (o += n), o > n / 2 && (o -= n), o; }, d = (t, e, n, o = 360) => r(s(t, t + f(t, e, o), n), o), m = (t, e, n, o = 360) => (t = r(t, o), e = r(e, o), e < t && (e += o), r(s(t, e, n), o)), C = (t, e, n, o = 360) => (t = r(t, o), e = r(e, o), e > t && (e -= o), r(s(t, e, n), o)), E = (t, e, n = c) => isFinite(t) ? isFinite(e) ? Math.abs(t - e) <= n : !1 : isNaN(t) ? isNaN(e) : isNaN(e) || isFinite(e) ? !1 : t > 0 == e > 0, F = (t, e, n = 360, o = c) => Math.abs(i(t, e, n)) <= o, S = (t, e = c) => Math.abs(t) <= e, T = (t, e) => Math.pow(t, 1 / e), W = (t, e) => { const n = Math.pow(10, e); return Math.round(t * n) / n; }, q = (t) => t < 0 ? -1 : 1, D = (t, e, n) => { const o = n - e + 1; return t < e && (t += o * ((e - t) / o + 1)), e + (t - e) % o; }, r = (t, e) => (t = t % e, t < 0 && (t += e), t); export { c as EPSILON, i as angleDifference, h as ceilTo, l as clamp, M as clampInt, u as clampSym, g as compareNumbers, N as floorTo, s as interpolate, A as interpolateAngle, C as interpolateAngleCCW, m as interpolateAngleCW, d as interpolateWidestAngle, F as nearEqualAngles, E as nearEquals, S as nearZero, T as root, W as roundTo, q as sign, w as toHex, f as widestAngleDifference, D as wrap, r as wrapCircular };