#include "blitz/common/Smoothing.h"
#include <cassert>
#include <cmath>

namespace blitz {

EMASmoother::EMASmoother() : Alpha(1.0f), Current(0.0f) {}

void EMASmoother::TickUnitT(float target) {
	Current = target + Alpha * (Current - target);
}

void EMASmoother::Tick(float target, float delta) {
	Current = target + std::pow(Alpha, delta) * (Current - target);
}

float EMASmoother::GetAlpha() {
	return Alpha;
}

void EMASmoother::SetAlpha(float alpha) {
	assert(0.0f < alpha && alpha <= 1.0f);
	Alpha = alpha;
}

void EMASmoother::SetSmoothingTime(float t) {
	SetAlpha(std::pow(1.0f - 0.999f, 1.0f / t));
};

}  // namespace blitz