package speiger.src.coreengine.math.value;

import speiger.src.coreengine.math.MathUtils;

public class CubicValue extends Value {
	final float startValue;
	final float startHelperValue;
	final float endHelperValue;
	final float endValue;
	boolean smooth = false;
	
	public CubicValue(float duration, float startValue, float startHelper, float endHelper, float endValue) { 
		this(0F, duration, startValue, startHelper, endHelper, endValue); 
	}
	
	public CubicValue(float start, float duration, float startValue, float startHelper, float endHelper, float endValue) {
		super(start, duration);
		this.startValue = startValue;
		startHelperValue = startHelper;
		endHelperValue = endHelper;
		this.endValue = endValue;
	}
	
	public CubicValue setSmooth() {
		smooth = true;
		return this;
	}
	
	public CubicValue setSmooth(boolean smooth) {
		this.smooth = smooth;
		return this;
	}
	
	@Override
	protected float calculateProgress(float time) {
		if(smooth) {
			float first = MathUtils.smoothQuadraticCurve(startValue, startHelperValue, endHelperValue, time);
			float second = MathUtils.smoothQuadraticCurve(startHelperValue, endHelperValue, endValue, time);
			return MathUtils.smoothLerp(first, second, time);
		}
		float first = MathUtils.quadraticCurve(startValue, startHelperValue, endHelperValue, time);
		float second = MathUtils.quadraticCurve(startHelperValue, endHelperValue, endValue, time);
		return MathUtils.lerp(first, second, time);
	}
	
	@Override
	protected void onFinished() { finishProgress(); }
}
