#ifndef POSITION_FORMULA
#define POSITION_FORMULA

#include <stdint.h>

#include "FixedInt.h"
#include "mathUtils.h"

#include "Param.h"

//PositionFormula is a x=f(t) form where we store the offset, linear quadratic sine and cosine scalars.
//So x=offset + linear*x + quadratic*x*x + sine*sine(x) + cosine*cosine(x)
//It also stores start and endtimes
//linear and quadratic are distance per 1024 ms
//sineFrequency and cosineFrequency are rotations per 1024 ms.
class PositionFormula
{
 public:
  PositionFormula();
  PositionFormula(Param & hash);
  ~PositionFormula();

  void clear();
  void set(Param & hash);
  //returns false if ans is not applicable (tim < start or tim > end). Otherwise ans=f(tim) and returns true.
  bool position (int tim, FixedInt & ans);
 private:
  int startTime, duration, timeShift;
  FixedInt offset, linear, quadratic, sineScalar, cosineScalar, sinePeriod, cosinePeriod;
};
#endif
