Here you can find the source of clamp(final float val, final float min, final float max)
Parameter | Description |
---|---|
val | The value to clamp. |
min | The minimum value to clamp between. |
max | The maximum value to clamp between. |
public static float clamp(final float val, final float min, final float max)
//package com.java2s; //License from project: Open Source License public class Main { /**//www. j a v a 2s .c o m * With this function you can maintain an input value between a specified range. * * @param val The value to clamp. * @param min The minimum value to clamp between. * @param max The maximum value to clamp between. * @return a value clamped between the specified minimum and maximum. * @see #clamp(int, int, int) */ public static float clamp(final float val, final float min, final float max) { return Math.max(min, Math.min(max, val)); } /** * With this function you can maintain an input value between a specified range. * * @param val The value to clamp. * @param min The minimum value to clamp between. * @param max The maximum value to clamp between. * @return a value clamped between the specified minimum and maximum. * @see #clamp(float, float, float) */ public static int clamp(final int val, final int min, final int max) { return Math.max(min, Math.min(max, val)); } }