summaryrefslogtreecommitdiff
path: root/src/Util/Util.js
blob: 88ed59fd9fbe43e02c98ea7096c4728904686a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}

class Enum {
	constructor(prefix, name) { 
		this.prefix = prefix;
		this.name = name;
	}
	toString() { return `${this.prefix}.${this.name}`; }
}

export { useAverage, clamp, lerp, Enum };