calc.h 712 B

123456789101112131415161718192021
  1. // Calculates the modulo of a number. Works correctly for negative numbers.
  2. int modulo(int x, int N);
  3. // Wraps a number between min and max (inclusive).
  4. int wrap(int x, int min, int max);
  5. // Wraps a number between min and max (inclusive). When wrapping around, the result will always be min or max.
  6. int wrap_single(int x, int min, int max);
  7. // Clamps a number between min and max (inclusive).
  8. int clamp(int x, int min, int max);
  9. // Linearly interpolates between a and b.
  10. int lerp(int a, int b, float t);
  11. // Calculates the inverse linear interpolation of x between a and b.
  12. float inverse_lerp(int a, int b, int x);
  13. // Maps a number from one range to another.
  14. int map(int a0, int b0, int a1, int b1, int x);