package timemapper;

import timedistortion.ITimeMapping;
import timedistortion.Ictx;

public class Sinus extends AbstractTimeMapper implements ITimeMapping {
	int dlen;

	@Override
	public void setContext(Ictx ictx) {
		super.setContext(ictx);
		dlen = 2 * ictx.len;
	}
	
	@Override
	public int len() {
		return dlen;
	}

	@Override
	public float di_to_ti(int di) {
		float x = (float)di / (float)dlen;
		float f = 0.5f + 0.5f * (float)Math.sin(2.0 * Math.PI * x - Math.PI / 2.0);
		return Math.min((f * (float)ictx.len), ictx.len-1);
	}

}
