package misc import "cmp" func Clamp[T cmp.Ordered](val, min, max T) T { if val > max { val = max } if val < min { val = min } return val }