import { clamp01 } from "./clamp01.js";

/**
 * Adapted from OpenGL spec
 * smoothstep performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where a threshold function with a smooth transition is desired.
 * @see https://en.wikipedia.org/wiki/Smoothstep
 * @param {number} edge0
 * @param {number} edge1
 * @param {number} x
 * @returns {number}
 */
export function smoothStep(edge0, edge1, x) {

    const span = edge1 - edge0;

    const t = clamp01((x - edge0) / span);

    return t * t * (3 - 2 * t);
}
