basic setup
This commit is contained in:
22
libs/math.js
Normal file
22
libs/math.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export function clamp(min, input, max) {
|
||||
return Math.max(min, Math.min(input, max))
|
||||
}
|
||||
|
||||
export function mapRange(in_min, in_max, input, out_min, out_max) {
|
||||
return (
|
||||
((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min
|
||||
)
|
||||
}
|
||||
|
||||
export function lerp(start, end, amt) {
|
||||
return (1 - amt) * start + amt * end
|
||||
}
|
||||
|
||||
export function truncate(value, decimals) {
|
||||
return parseFloat(value.toFixed(decimals))
|
||||
}
|
||||
|
||||
export function wrapValue(value, lowBound, highBound) {
|
||||
const range = highBound - lowBound
|
||||
return ((((value - lowBound) % range) + range) % range) + lowBound
|
||||
}
|
||||
Reference in New Issue
Block a user