add pixel.Clamp

This commit is contained in:
faiface 2017-10-15 19:42:13 +02:00
parent ce09bb1114
commit 62cefc262e
1 changed files with 14 additions and 0 deletions

View File

@ -5,6 +5,20 @@ import (
"math"
)
// Clamp returns x clamped to the interval [min, max].
//
// If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is
// returned.
func Clamp(x, min, max float64) float64 {
if x < min {
return min
}
if x > max {
return max
}
return x
}
// Vec is a 2D vector type with X and Y coordinates.
//
// Create vectors with the V constructor: