package ru.dbotthepony.kstarbound.math

import ru.dbotthepony.kommons.math.linearInterpolation
import kotlin.math.PI
import kotlin.math.sin

fun interface Interpolator {
	fun interpolate(t: Double, a: Double, b: Double): Double

	object Sin : Interpolator {
		override fun interpolate(t: Double, a: Double, b: Double): Double {
			return linearInterpolation((sin(t * PI - PI / 2.0) + 1.0) / 2.0, a, b)
		}
	}

	object Linear : Interpolator {
		override fun interpolate(t: Double, a: Double, b: Double): Double {
			// custom to allow extrapolation
			return a + (b - a) * t
		}
	}

	object NearestMiddle : Interpolator {
		override fun interpolate(t: Double, a: Double, b: Double): Double {
			if (t >= 0.5)
				return b
			else
				return a
		}
	}
}
