Math

A collection of utility functions for common mathematical operations.

clamp

Clamps a value between a minimum and maximum value.

export const clamp = (min: number, value: number, max: number) => {
  return Math.min(Math.max(value, min), max);
};

lerp

Linearly interpolates between two values.

export const lerp = (a: number, b: number, t: number) => {
  return a + t * (b - a);
};

sum

Calculates the sum of an array of numbers.

export const sum = (...args: number[]) => {
  return args.reduce((acc, curr) => acc + curr, 0);
};