Vector Clamp a given value between 0.1 and PI - 0.1. - Java java.lang

Java examples for java.lang:Math Vector

Description

Vector Clamp a given value between 0.1 and PI - 0.1.

Demo Code


import java.awt.Color;
import javax.vecmath.Vector3f;

public class Main{
    /**//from  w w  w.j a v a  2s .com
     * Clamp a given value between 0.1 and PI - 0.1.
     * 
     * @param value The value to be clamped.
     * @return A clamped value.
     * @see #clamp(float, float, float)
     */
    public static float clamp(float value) {
        return clamp(value, 0.1f, (float) (Math.PI - 0.1));
    }
    /**
     * Clamp a given value between a given minimum and maximum value.
     * Clamping means that when the given value is less than the given
     * minimum, this minimum is returned. If the value is greater than
     * the maximum, this maximum is returned. Otherwise, the value is
     * unchanged.
     * 
     * <p>This function does not change any of its parameters.</p>
     * 
     * @param value The value to be clamped.
     * @param min The minimum value for clamping.
     * @param max The maximum value for clamping.
     * @return A value between {@code min} and {@code max}.
     */
    public static float clamp(float value, float min, float max) {
        if (value <= min)
            return min;
        if (value >= max)
            return max;
        return value;
    }
}

Related Tutorials