Here you can find the source of clamp(double value, final double min, final double max)
Parameter | Description |
---|---|
value | the value |
min | the minimal possible value (inclusive) |
max | the maximal possible value (inclusive) |
public static double clamp(double value, final double min, final double max)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww .ja va2 s . c om*/ * Make sure a value is in between the specified bounds. * * @param value * the value * @param min * the minimal possible value (inclusive) * @param max * the maximal possible value (inclusive) * @return the clamped value */ public static double clamp(double value, final double min, final double max) { if (value < min) { value = min; } else if (value > max) { value = max; } return value; } /** * @see Helpers#clamp(double, double, double) */ public static int clamp(int value, final int min, final int max) { if (value < min) { value = min; } else if (value > max) { value = max; } return value; } }