def constrain(x: float, out_min: float, out_max: float) -> float:
    """Constrains ``x`` to be within the inclusive range [``out_min``, ``out_max``].
    Sometimes called ``clip`` or ``clamp`` in other libraries.
    ``out_min`` should be less than or equal to ``out_max``.
    If ``x`` is less than ``out_min``, return ``out_min``.
    If ``x`` is greater than ``out_max``, return ``out_max``.
    Otherwise just return ``x``.

    :param float out_min: Lower bound of output range.
    :param float out_max: Upper bound of output range.
    :return: Returns value constrained to given range.
    :rtype: float
    """
    return max(out_min, min(x, out_max))