def _sliderValueFromPosition(
    min: float, max: float, position: int, span: int, upsideDown: bool = False
) -> float:
    """Converts the given pixel `position` to a value.

    0 maps to the `min` parameter, `span` maps to `max` and other values are
    distributed evenly in-between.

    By default, this function assumes that the maximum value is on the right
    for horizontal items and on the bottom for vertical items. Set the
    `upsideDown` parameter to True to reverse this behavior.
    """

    if span <= 0 or position <= 0:
        return max if upsideDown else min
    if position >= span:
        return min if upsideDown else max
    range = max - min
    tmp = min + position * range / span
    return max - tmp if upsideDown else tmp + min