Here you can find the source of clamp(float value, float minimum, float maximum)
Parameter | Description |
---|---|
value | The value to clamp. |
minimum | The minimum return value. |
maximum | The maximum return value. |
public static float clamp(float value, float minimum, float maximum)
//package com.java2s; /*/*from w w w .j av a 2 s .com*/ This file is part of GBukkitCore. GBukkitCore 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, either version 3 of the License, or (at your option) any later version. GBukkitCore 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 Lesser General Public License along with GBukkitCore. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Assure that a value is between two other values. * @param value The value to clamp. * @param minimum The minimum return value. * @param maximum The maximum return value. * @return {@code value} if it is between {@code minimum} and {@code maximum}, {@code minimum} if {@code value < minimum}, or {@code maximum} of {@code value > maximum}. */ public static float clamp(float value, float minimum, float maximum) { return Math.max(Math.min(value, maximum), minimum); } /** * Assure that a value is between two other values. * @param value The value to clamp. * @param minimum The minimum return value. * @param maximum The maximum return value. * @return {@code value} if it is between {@code minimum} and {@code maximum}, {@code minimum} if {@code value < minimum}, or {@code maximum} of {@code value > maximum}. */ public static double clamp(double value, double minimum, double maximum) { return Math.max(Math.min(value, maximum), minimum); } /** * Assure that a value is between two other values. * @param value The value to clamp. * @param minimum The minimum return value. * @param maximum The maximum return value. * @return {@code value} if it is between {@code minimum} and {@code maximum}, {@code minimum} if {@code value < minimum}, or {@code maximum} of {@code value > maximum}. */ public static long clamp(long value, long minimum, long maximum) { return Math.max(Math.min(value, maximum), minimum); } /** * Assure that a value is between two other values. * @param value The value to clamp. * @param minimum The minimum return value. * @param maximum The maximum return value. * @return {@code value} if it is between {@code minimum} and {@code maximum}, {@code minimum} if {@code value < minimum}, or {@code maximum} of {@code value > maximum}. */ public static int clamp(int value, int minimum, int maximum) { return Math.max(Math.min(value, maximum), minimum); } }