From 5efc7885e1c3959aa165be640858ffb3f8a5860b Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 31 May 2022 20:52:15 -0500 Subject: refactor: remove modules/ folder --- src/Util/Util.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/Util/Util.js (limited to 'src/Util/Util.js') diff --git a/src/Util/Util.js b/src/Util/Util.js new file mode 100644 index 0000000..165d1d0 --- /dev/null +++ b/src/Util/Util.js @@ -0,0 +1,20 @@ +function useAverage() { + var avg = 0; + let weight = 0; + const append = value => { + avg = (weight * avg) + value; + weight += 1; + avg = avg/weight; + } + + return [() => avg, append]; +} + +function clamp(value, min, max) { + return Math.min(Math.max(value, min), max); +} + +function lerp(a, b, alpha) { + return ((1-alpha)*a) + (alpha*b); +} +export { useAverage, clamp, lerp }; -- cgit v1.2.1