Here you can find the source of clamp(float value, float min, float max)
Parameter | Description |
---|---|
value | a parameter |
min | The minimum desired value |
max | The maximum desired value |
public static float clamp(float value, float min, float max)
//package com.java2s; // file 'LICENSE', which is part of this source code package. public class Main { /**//from w ww. j a v a2 s. c o m * Restricts a value to be within a specified range. * @param value * @param min The minimum desired value * @param max The maximum desired value * @return Return a value between min and max */ public static float clamp(float value, float min, float max) { value = (value > max) ? max : value; value = (value < min) ? min : value; return value; } /** * Restricts a value to be within a specified range. * @param value * @param min The minimum desired value * @param max The maximum desired value * @return Return a value between min and max */ public static int clamp(int value, int min, int max) { return (int) clamp((float) value, (float) min, (float) max); } }