{"version":3,"file":"index.cjs","sources":["../../src/physics/simulation.ts"],"sourcesContent":["/**\n * Fixed simulation timestep (seconds), consumed through an accumulator\n * (\"fix your timestep\"). Same trajectory at 60/120/144 Hz, testable step\n * by step. Lower it if very stiff springs ever prove unstable - the API\n * does not change.\n */\nexport const SIMULATION_TIMESTEP_S = 1 / 120\n\nexport interface SimulationState {\n  position: number\n  /** units/s */\n  velocity: number\n}\n\n/**\n * Every physics mode (spring, decay, inertia...) reduces to an acceleration\n * function plus a rest condition over a (position, velocity) state. This is\n * what makes retargeting and handoff free: the state survives, only the\n * simulation behind it changes.\n */\nexport interface Simulation {\n  /** units/s^2 */\n  acceleration(position: number, velocity: number): number\n  /** Settled position when the state qualifies as rest, null while moving. */\n  rest(position: number, velocity: number): number | null\n}\n\n/** One semi-implicit (symplectic) Euler step: velocity first, then position. */\nexport function stepSimulation(\n  simulation: Simulation,\n  state: SimulationState,\n  timestepS: number,\n): SimulationState {\n  const velocity =\n    state.velocity + simulation.acceleration(state.position, state.velocity) * timestepS\n  return { position: state.position + velocity * timestepS, velocity }\n}\n"],"names":["SIMULATION_TIMESTEP_S","stepSimulation","simulation","state","timestepS","velocity"],"mappings":"gFAMO,MAAMA,EAAwB,EAAI,IAsBlC,SAASC,EACdC,EACAC,EACAC,EACiB,CACjB,MAAMC,EACJF,EAAM,SAAWD,EAAW,aAAaC,EAAM,SAAUA,EAAM,QAAQ,EAAIC,EAC7E,MAAO,CAAE,SAAUD,EAAM,SAAWE,EAAWD,EAAW,SAAAC,CAAA,CAC5D"}