Commit: 31038a949f142822ef48388de5247e574ddab781 Parent: 431c5823b49684e7536b83acaeb8d4745d623a59 Author: Randy Palamar Date: Tue, 25 Jun 2024 15:17:05 -0600 simplify move_towards what was wrong with my brain when writing this Diffstat:
M | colourpicker.c | | | 22 | ++++++++++------------ |
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/colourpicker.c b/colourpicker.c @@ -15,18 +15,16 @@ static const char *mode_labels[CPM_LAST][4] = { static f32 move_towards_f32(f32 current, f32 target, f32 delta) { - f32 result; - f32 remaining = target - current; - - if (ABS(remaining) < ABS(delta)) - return target; - - if (target < current) - result = current - delta; - else - result = current + delta; - - return result; + if (target < current) { + current -= delta; + if (current < target) + current = target; + } else { + current += delta; + if (current > target) + current = target; + } + return current; } static v2