summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..f133b15
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,14 @@
+#include <math.h>
+#include "utils.h"
+
+float move_to(float current, float target, float step) {
+ if (step < 0)
+ return move_to(current, target, -step);
+
+ if (current > target)
+ return fmaxf(current-step, target);
+ else if (current < target)
+ return fminf(current+step, target);
+
+ return current;
+}