Xavier F. Gouchet
01/09/2020, 10:53 AMclamp
method on Numbers in the StdLib :
fun clamp(d: Double, min : Double, max : Double) : Double {
return if (d < min) {
min
} else if (d > max) {
max
} else {
d
}
}
or
fun Double.clamp(min : Double, max : Double) : Double {
return if (this< min) {
min
} else if (this > max) {
max
} else {
this
}
}
diesieben07
01/09/2020, 11:05 AMnfrankel
01/09/2020, 12:02 PM