Java Float Number Clamp clampToMinusOneToOne(float value)

Here you can find the source of clampToMinusOneToOne(float value)

Description

Clamps the given value to the -1..1 range.

License

Open Source License

Declaration

public static float clampToMinusOneToOne(float value) 

Method Source Code

//package com.java2s;
/*/* ww w  . j  a va2s.c o  m*/
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2007-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library 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;
 *    version 2.1 of the License.
 *
 *    This library 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.
 */

public class Main {
    /**
     * Clamps the given value to the -1..1 range.
     */
    public static float clampToMinusOneToOne(float value) {
        if (value < -1) {
            value = -1;
        }

        if (value > 1) {
            value = 1;
        }

        return value;
    }
}

Related

  1. clampLevel(float level)
  2. clampLevel(float level)
  3. clampNumberFromTime(long ms, float seconds)
  4. clampPercentage(float value)
  5. clampRoundByte(float in)
  6. clampToPositiveNonZero(float value)
  7. clampTrigo(float value, float min, float max)
  8. clampWithMod(float parFloat, float parMax)
  9. clampYaw(float yaw)