package solutions.tretter.mindmachine.session

import kotlin.math.ln
import kotlin.math.pow

object ParameterMapping {
    fun logMap01(value01: Float, min: Float, max: Float): Float {
        val v = value01.coerceIn(0f, 1f)
        val a = ln(min)
        val b = ln(max)
        return kotlin.math.exp(a + (b - a) * v)
    }

    fun invLog01(value: Float, min: Float, max: Float): Float {
        val v = value.coerceIn(min, max)
        val a = ln(min)
        val b = ln(max)
        return ((ln(v) - a) / (b - a)).toFloat().coerceIn(0f, 1f)
    }
}
