mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
49 lines
543 B
Go
49 lines
543 B
Go
package imath
|
|
|
|
import "math"
|
|
|
|
func Max(a, b int) int {
|
|
if a > b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func Min(a, b int) int {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func MinNonZero(a, b int) int {
|
|
switch {
|
|
case a == 0:
|
|
return b
|
|
case b == 0:
|
|
return a
|
|
}
|
|
|
|
return Min(a, b)
|
|
}
|
|
|
|
func Round(a float64) int {
|
|
return int(math.Round(a))
|
|
}
|
|
|
|
func Scale(a int, scale float64) int {
|
|
if a == 0 {
|
|
return 0
|
|
}
|
|
|
|
return Round(float64(a) * scale)
|
|
}
|
|
|
|
func Shrink(a int, shrink float64) int {
|
|
if a == 0 {
|
|
return 0
|
|
}
|
|
|
|
return Round(float64(a) / shrink)
|
|
}
|