Java Float Number Clamp clampAngle(float var, float min, float max)

Here you can find the source of clampAngle(float var, float min, float max)

Description

Clamps the angles to a min max by adding or subtracting the min max.

License

Open Source License

Declaration

public static float clampAngle(float var, float min, float max) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w w w  . j  a v  a  2  s.  c o  m
     * Clamps the angles to a min max by adding or subtracting the min max. This way it maintanes
     * the change in angle in the chance it goes out of bounds
     */
    public static float clampAngle(float var, float min, float max) {
        while (var < min) {
            var += 360;
        }

        while (var > max) {
            var -= 360;
        }

        return var;
    }

    public static double clampAngle(double var, double min, float max) {
        while (var < min) {
            var += max;
        }
        while (var > max) {
            var -= max;
        }
        return var;
    }
}

Related

  1. clamp180(float r1, float r2)
  2. clamp1f(float f)
  3. clamp360(float dir)
  4. clamp_float(float p_76131_0_, float p_76131_1_, float p_76131_2_)
  5. clampAngle(float value, float min, float max)
  6. clampBounds(float[] target, float[] clamp)
  7. clampColour(float value)
  8. clampDegree0To360(float degree)
  9. clampFloat(float value, float minimum, float maximum)