using System;
using UnityEngine;

public class Sinusoid
{
	private Func<float, float> _shape;
	private float _amplitude;
	private float _frequency;
	private float _offset;

	private static float TAU = 6.283f;

	public Sinusoid(Func<float, float> shape, float amplitude, float frequency, float offset)
	{
		_shape = shape;
		_amplitude = amplitude;
		_frequency = frequency;
		_offset = offset;
	}

	public float GetPosition(float time)
	{
		float offsetTime = time + _offset;
		float frequencyTime = offsetTime * TAU * _frequency;
		float value = _shape(frequencyTime) * _amplitude;
		return Mathf.Clamp(value, -0.5f, 0.5f);
	}
}
