summaryrefslogtreecommitdiff
path: root/src/utils.c
blob: f133b152e1766289a75d5194016445514d15814f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}