From dd1f1516960fd0c1882a3b56d11bec88a03c0059 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sun, 1 Sep 2024 17:22:58 +0200 Subject: [PATCH] Add math.remap_clamped. --- core/math/math.odin | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/math/math.odin b/core/math/math.odin index cf6630ef2..f5e904da6 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -402,7 +402,12 @@ remap :: proc "contextless" (old_value, old_min, old_max, new_min, new_max: $T) if old_range == 0 { return new_range / 2 } - remapped := ((old_value - old_min) / old_range) * new_range + new_min + return ((old_value - old_min) / old_range) * new_range + new_min +} + +@(require_results) +remap_clamped :: proc "contextless" (old_value, old_min, old_max, new_min, new_max: $T) -> (x: T) where intrinsics.type_is_numeric(T), !intrinsics.type_is_array(T) { + remapped := #force_inline remap(old_value, old_min, old_max, new_min, new_max) return clamp(remapped, new_min, new_max) }