//#pragma once
#ifndef AnimationrigWiggle_H
#define AnimationrigWiggle_H

#include <AnimationrigMisc.h>

#include <iostream>
#include <vector>

namespace Animrig {
	enum class WiggleType { Step, Linear, BSpline, Hermite };

	class Wiggle {
	public:
		static float random(double t, WiggleType wiggle, int offset)
		{
			if (t < 0) t = -t;

			int cycle = (int)std::floor(t);
			float a = (float)(t - cycle);

			offset = (offset + cycle) & 1023;

			auto r1 = _randomTable[(offset + 1023) & 1023];
			auto r2 = _randomTable[(offset + 0) & 1023];
			auto r3 = _randomTable[(offset + 1) & 1023];
			auto r4 = _randomTable[(offset + 2) & 1023];

			switch (wiggle)
			{
			case WiggleType::Step: return r2;
			case WiggleType::Linear: return r2 + (r3 - r2) * a;
			case WiggleType::BSpline: return Misc::splineFloat(r1, r2, r3, r4, a, 1.0f, Spline::BSpline);
			case WiggleType::Hermite: return Misc::splineFloat(r1, r2, r3, r4, a, 1.0f, Spline::Hermite);
			}
			return r2;
		}
	protected:
		static const float _randomTable[1024];
	};
}

#endif

