/**
 * Compute fraction of linear interpolation
 * @example
 *  inverseLerp(1, 5, 1) === 0
 *  inverseLerp(1, 5, 5) === 1
 *  inverseLerp(1, 5, 3) === 0.5
 *
 * @param {number} a
 * @param {number} b
 * @param {number} value
 * @returns {number} fraction of where the {@link value} lies between {@link a} and {@link b}
 */
export function inverseLerp(a, b, value) {
    const range = b - a;
    const scaledValue = value - a;

    if (range === 0) {

        // avoid division by zero error

        // this is arbitrary output, as the actual answer is undefined

        return 0;
    }

    return scaledValue / range;
}
