Here you can find the source of clamp(double min, double max, double value)
Parameter | Description |
---|---|
min | The minimum value. |
max | The maximum value. |
value | The value to constrain within <code>min</code> and <code>max</code> |
value
if within min
and max
, otherwise one of min
and max
.
public static double clamp(double min, double max, double value)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w . ja v a 2s. co m*/ * Constrains the value between the given borders (inclusive). * @param min The minimum value. * @param max The maximum value. * @param value The value to constrain within <code>min</code> and <code>max</code> * @return The <code>value</code> if within <code>min</code> and <code>max</code>, otherwise one of <code>min</code> and <code>max</code>. */ public static double clamp(double min, double max, double value) { return Math.min(Math.max(min, value), max); } }