2020-10-01 13:14:36 +02:00
|
|
|
package buf2d
|
|
|
|
|
2022-03-31 12:37:35 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
)
|
2021-01-15 21:40:09 +01:00
|
|
|
|
2020-10-01 13:14:36 +02:00
|
|
|
func limit(v, min, max int) int {
|
|
|
|
return getmax(getmin(v, max), min)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getmax(x, y int) int {
|
|
|
|
if x > y {
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
return y
|
|
|
|
}
|
|
|
|
|
|
|
|
func getmin(x, y int) int {
|
|
|
|
if x < y {
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
return y
|
|
|
|
}
|
2021-01-15 21:40:09 +01:00
|
|
|
|
2022-03-31 12:37:35 +02:00
|
|
|
func MakeDefaultStringFunc[T any]() func(T) string {
|
|
|
|
if reflect.TypeOf(new(T)).Elem() == reflect.TypeOf(new(rune)).Elem() {
|
|
|
|
return func(value T) string {
|
|
|
|
return string((interface{}(value)).(rune))
|
|
|
|
}
|
|
|
|
} else if reflect.TypeOf(new(T)).Elem() == reflect.TypeOf(new(string)).Elem() {
|
|
|
|
return func(value T) string {
|
|
|
|
return (interface{}(value)).(string)
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 21:40:09 +01:00
|
|
|
|
2022-03-31 12:37:35 +02:00
|
|
|
return func(value T) string {
|
|
|
|
return fmt.Sprintf("%v", value)
|
|
|
|
}
|
2021-01-15 21:40:09 +01:00
|
|
|
}
|