def clamp(v: float, minVal: float, maxVal: float):
    """
        Component-wise clamp

        In case v is smaller than minVal, minVal is returned.
        If v is larger than maxVal, maxVal is returned.

        :param v: vector to clamp
        :param minVal: minimal value (component-wise)
        :param maxVal: maximal value (component-wise)
        :return: clamped value
    """
    if v<minVal:
        return minVal
    elif v>maxVal:
        return maxVal
    else:
        return v