Here you can find the source of Clamp(float val, float minVal, float maxVal)
public static float Clamp(float val, float minVal, float maxVal)
//package com.java2s; //License from project: Apache License public class Main { public static float Clamp(float val, float minVal, float maxVal) { return (Min(Max(minVal, val), maxVal)); }//from ww w .j a v a 2 s.c o m static public int clamp(int value, int min, int max) { if (value < min) { return min; } if (value > max) { return max; } return value; } static public short clamp(short value, short min, short max) { if (value < min) { return min; } if (value > max) { return max; } return value; } static public float clamp(float value, float min, float max) { if (value < min) { return min; } if (value > max) { return max; } return value; } static public double clamp(double value, double min, double max) { if (value < min) { return min; } if (value > max) { return max; } return value; } public static float Min(float a, float b) { return ((a) > (b) ? (b) : (a)); } public static int min(int a, int b) { if (a < b) { return a; } return b; } public static int min(int a, int b, int c) { if (min(a, b) < c) { return min(a, b); } return c; } public static float Max(float a, float b) { return ((a) < (b) ? (b) : (a)); } public static int max(int a, int b) { if (a > b) { return a; } return b; } }