Debian Codegraph @

vendor/github.com/xyproto/gfx/int.go

raw
1 //go:build !tinygo
2 // +build !tinygo
3
4 package gfx
5
6 // IntAbs returns the absolute value of x.
7 func IntAbs(x int) int {
8 if x > 0 {
9 return x
10 }
11
12 return -x
13 }
14
15 // IntMin returns the smaller of x or y.
16 func IntMin(x, y int) int {
17 if x < y {
18 return x
19 }
20
21 return y
22 }
23
24 // IntMax returns the larger of x or y.
25 func IntMax(x, y int) int {
26 if x > y {
27 return x
28 }
29
30 return y
31 }
32
33 // IntClamp returns x clamped to the interval [min, max].
34 //
35 // If x is less than min, min is returned.
36 // If x is more than max, max is returned. Otherwise, x is returned.
37 func IntClamp(x, min, max int) int {
38 switch {
39 case x < min:
40 return min
41 case x > max:
42 return max
43 default:
44 return x
45 }
46 }