import { presets } from "../presets";
var secondPerFrame = 1 / 45;
var precision = 1e-1;
var _presets$noWobble = presets.noWobble,
  stiffness = _presets$noWobble.stiffness,
  damping = _presets$noWobble.damping;

// imported from https://github.com/chenglou/react-motion/blob/master/src/stepper.js
// and slightly simplified
var reusedTuple = [0, 0];
export var stepper = function stepper(currentX, currentV, targetX) {
  // https://en.wikipedia.org/wiki/Hooke%27s_law
  var springForce = -stiffness * (currentX - targetX);
  var dampingForce = -damping * currentV;
  var acceleration = springForce + dampingForce;
  var newV = currentV + acceleration * secondPerFrame;
  var newX = currentX + newV * secondPerFrame;
  if (Math.abs(newV) < precision && Math.abs(newX - targetX) < precision) {
    reusedTuple[0] = targetX;
    reusedTuple[1] = 0;
    return reusedTuple;
  }
  reusedTuple[0] = newX;
  reusedTuple[1] = newV;
  return reusedTuple;
};