2015-07-26 16:44:51 +02:00
|
|
|
// Copyright 2014, 2015 by Sascha L. Teichmann
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2015-07-21 22:01:10 +02:00
|
|
|
package common
|
|
|
|
|
2015-07-26 12:32:59 +02:00
|
|
|
func Max(a, b int) int {
|
2015-07-21 22:01:10 +02:00
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2015-07-26 12:32:59 +02:00
|
|
|
func Min(a, b int) int {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2015-07-21 22:01:10 +02:00
|
|
|
func max32(a, b int32) int32 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func max16(a, b int16) int16 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func min16(a, b int16) int16 {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
2015-07-26 11:55:38 +02:00
|
|
|
|
|
|
|
func min32f(a, b float32) float32 {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func Clamp32f(x, a, b float32) float32 {
|
|
|
|
switch {
|
|
|
|
case x < a:
|
|
|
|
return a
|
|
|
|
case x > b:
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
return x
|
|
|
|
}
|
2015-07-26 16:40:50 +02:00
|
|
|
|
2015-07-27 19:03:47 +02:00
|
|
|
func Order(a, b int) (int, int) {
|
|
|
|
if a < b {
|
|
|
|
return a, b
|
|
|
|
}
|
|
|
|
return b, a
|
|
|
|
}
|
|
|
|
|
|
|
|
func Order16(a, b int16) (int16, int16) {
|
|
|
|
if a < b {
|
|
|
|
return a, b
|
|
|
|
}
|
|
|
|
return b, a
|
|
|
|
}
|
|
|
|
|
2015-07-26 16:40:50 +02:00
|
|
|
func Order64(a, b int64) (int64, int64) {
|
|
|
|
if a < b {
|
|
|
|
return a, b
|
|
|
|
}
|
|
|
|
return b, a
|
|
|
|
}
|