joyful/internal/mappingrules/math.go
Anna Rose Wiggins e617a6eda6 Implement axis targets, axis -> button and axis -> relative axis mappings. (#1)
Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com>
Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
2025-07-15 19:55:19 +00:00

30 lines
557 B
Go

package mappingrules
import (
"golang.org/x/exp/constraints"
)
type Numeric interface {
constraints.Integer | constraints.Float
}
func Abs[T Numeric](value T) T {
return max(value, -value)
}
// LerpInt linearly interpolates between two integer values using
// a float64 index value
func LerpInt[T constraints.Integer](min, max T, t float64) T {
t = Clamp(t, 0.0, 1.0)
return T((1-t)*float64(min) + t*float64(max))
}
func Clamp[T Numeric](value, min, max T) T {
if value < min {
value = min
}
if value > max {
value = max
}
return value
}