//EaseIn = Start slow, accelerate to the goal.
//EaseOut = Start fast, decelerate to the goal.
//EaseInOut = Start slow, accelerate to the half-way point, decelerate to the goal.
//EaseOutIn = Start fast, decelerate to the half-way point, accelerate to the goal.
enum EaseStyle {EaseIn, EaseOut, EaseInOut, EaseOutIn};
/*
Easer is an Easing/Tweening/Interpolating functor class.
You can either use the EaseEquations stand-alone, or pass them to Easer if you want
persistent data (perhaps holding Easer as a member-variable of another class).
*/
class Easer
{
public:
Easer(EaseFunction easeFunction, EaseStyle style = EaseIn) : EaseFunc(easeFunction), Style(style) { }
~Easer() = default;
EaseStyle Style = EaseIn;
EaseFunction EaseFunc;
//Used to constrain the return result to the desired range, such as 0.0f - 1.0f.
//The default setting is (-FLT_MAX, FLT_MAX). Note: For some funky reason, FLT_MIN is "the minimum positive value above zero". =/
FloatRange Constaints = FloatRange(-FLT_MAX, FLT_MAX);
//The current position.
float Position = 0.0f;
public:
//Sets 'position' to 'newPosition'.
void SetPosition(float position);
//Resets 'position' to 0.0f. This is the same as calling SetPosition(0.0f);
void Reset();
//Returns true if 'position' is at or beyond 1.0f.
bool AtEnd() const;
//Returns the value at the current position.
//(Note: Unless constrained, the actual result may actually drop below 0.0f or above 1.0f depending
//on the easing function. This is intentional, and desirable for some effects)
float Get() const;
//Returns the value at the current position, scaled to the range of 'min' to 'max' instead of around (0.0f - 1.0f)-ish
float GetInRange(const FloatRange &range) const;
//Returns the value at 'pos'.
float GetAt(float pos) const;
//Returns the value at 'pos', scaled to the range of 'min' to 'max' instead of around (0.0f - 1.0f)-ish
float GetInRangeAt(float pos, const FloatRange &range) const;
//Moves the position of the ease by 'amount'.
void Step(float amount);
void operator+=(float amount); //Same as Step().
void operator-=(float amount); //Same as Step() with a negative amount.
void operator=(float position); //Same as SetPosition().
float operator()() const; //Same as Get()
float operator()(float value) const; //Same as GetAt()
private:
//Calls the callback function 'EaseFunc' and processes the result depending on the EaseStyle,
//then constrains the result using 'Constaints'.
float plot(float position) const;
};