local function accelerate(dt, gas_input, speed, max_speed, accel, min_speed)
  if (min_speed == nil) then
    min_speed = 0
  end
  local new_speed = speed + accel * dt * gas_input
  if (new_speed >= max_speed) then
    new_speed = max_speed
  elseif (new_speed <= min_speed) then
    new_speed = min_speed
  elseif(new_speed <= -max_speed) then
    new_speed = -max_speed
  end
  return new_speed
end

local function centrifugal_force(dt, mass, speed, max_speed)
  local speed_percent = (speed/max_speed)
  local dx = dt * 2 * speed_percent
  local dy = dt * 2 * speed_percent
  return mass * dy * speed * speed
end

local function drift(dt, pos_x, pos_y, speed, max_speed, angle, scale_x, scale_y)
  local speed_percent = (speed/max_speed)
  local dx = dt * 2.0 * speed_percent -- at top speed, should be able to cross from left to right (-1 to 1) in 1 second
  local dy = dt * 2.0 * speed_percent
  cos = math.cos(angle)
  sin = math.sin(angle)

  return pos_x + (dx * speed_percent * cos) * (scale_x or 1),
    pos_y + (dy * speed_percent * sin) * (scale_y or 1)
end

-- local function gas(accel, drag, friction)
--   friction = friction or 0
--   return accel - drag - friction
-- end

-- local function brake(decel, drag, grip, friction)
--   friction = friction or 0
--   return - decel - drag - grip - friction
-- end

-- local function roam(decel, drag, friction)
--   friction = friction or 0
--   return - decel - drag - friction
-- end

-- local function steer(_steer, grip, drag, velocity, friction)
--   friction = friction or 0
--   return _steer + grip + drag - velocity + friction
-- end

return {
  accelerate = accelerate,
  drift = drift,
  centrifugal_force = centrifugal_force
}
