Here you can find the source of clamp(float val, float min, float max)
Parameter | Description |
---|---|
val | a parameter |
min | a parameter |
max | a parameter |
public final static float clamp(float val, float min, float max)
//package com.java2s; /* /* w w w . j a v a2s.co m*/ This file is part of jME Planet Demo. jME Planet Demo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation. jME Planet Demo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License along with jME Planet Demo. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Clamp a value between min and max bounds. * * @param val * @param min * @param max * @return val if val>=min and val<=max. min if val<min and max if val>max */ public final static float clamp(float val, float min, float max) { return Math.max(min, Math.min(max, val)); } /** * Clamp a value between min and max bounds. * * @param val * @param min * @param max * @return val if val>=min and val<=max. min if val<min and max if val>max */ public final static int clamp(int val, int min, int max) { return Math.max(min, Math.min(max, val)); } public final static float max(float... fs) { float ret = Float.MIN_VALUE; for (float f : fs) { ret = Math.max(ret, f); } return ret; } public final static float min(float... fs) { float ret = Float.MAX_VALUE; for (float f : fs) { ret = Math.min(ret, f); } return ret; } }