add pixel.Clamp
This commit is contained in:
parent
4792a9ebd8
commit
6215259c1d
14
geometry.go
14
geometry.go
|
@ -5,6 +5,20 @@ import (
|
||||||
"math"
|
"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.
|
// Vec is a 2D vector type with X and Y coordinates.
|
||||||
//
|
//
|
||||||
// Create vectors with the V constructor:
|
// Create vectors with the V constructor:
|
||||||
|
|
Loading…
Reference in New Issue