local vm = require("lib.vornmath")

local utils = {}

function utils.easeIn(a,b,percent)
  return a + (b-a)*math.pow(percent,2);
end

function utils.easeOut(a,b,percent)
  return a + (b-a)*(1-math.pow(1-percent,2));
end

function utils.easeInOut(a,b,percent)
  return a + (b-a)*((-math.cos(percent*math.pi)/2) + 0.5);
end

function utils.percentRemaining(n, total)
  return (n%total)/total;
end

function utils.interpolate(a, b, percent)
  return a + (b-a)*percent
end

function utils.randomInt(min, max)
  return vm.round(utils.interpolate(min, max, math.random()));
end

function utils.randomChoice(options)
  return options[utils.randomInt(1, #options)]
end

function utils.limit(value, min, max)
  return math.max(min, math.min(value, max))
end

function utils.accelerate(v, accel, dt)
  return v + (accel * dt)
end

function utils.exponentialFog(distance, density)
  return 1 / (math.exp(distance * distance * density))
end

function utils.increase(start, increment, max, is_loop) -- with looping
  local result = start + increment
  if (result > max) and is_loop then
    result = 1
  elseif result <= 0 and is_loop then
    result = max - 1
  end
  return result
end

return utils
