Java Float Number Clamp clampBounds(float[] target, float[] clamp)

Here you can find the source of clampBounds(float[] target, float[] clamp)

Description

Clamps the target bounds using the provided `clamp` bounds

License

Open Source License

Parameter

Parameter Description
target target bounds to modify
clamp bounds to clamp with

Return

bounds

Declaration

public static float[] clampBounds(float[] target, float[] clamp) 

Method Source Code

//package com.java2s;
/*/* w  w w  . j  av  a2  s. co m*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2015, 2016 IceDragon200
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

public class Main {
    public static final float[] NORMALIZED_CLAMP = new float[] { 0.0f,
            0.0f, 0.0f, 1.0f, 1.0f, 1.0f };

    /**
     * Clamps the target bounds using the provided `clamp` bounds
     * @param target target bounds to modify
     * @param clamp bounds to clamp with
     * @return bounds
     */
    public static float[] clampBounds(float[] target, float[] clamp) {
        assert target.length == 6;
        if (target[0] < clamp[0])
            target[0] = clamp[0];
        if (target[1] < clamp[1])
            target[1] = clamp[1];
        if (target[2] < clamp[2])
            target[2] = clamp[2];
        if (target[3] > clamp[3])
            target[3] = clamp[3];
        if (target[4] > clamp[4])
            target[4] = clamp[4];
        if (target[5] > clamp[5])
            target[5] = clamp[5];
        return target;
    }

    /**
     * Clamps the target bounds using the NORMALIZED_CLAMP
     * @param target target bounds to modify
     * @return bounds
     */
    public static float[] clampBounds(float[] target) {
        return clampBounds(target, NORMALIZED_CLAMP);
    }
}

Related

  1. clamp1f(float f)
  2. clamp360(float dir)
  3. clamp_float(float p_76131_0_, float p_76131_1_, float p_76131_2_)
  4. clampAngle(float value, float min, float max)
  5. clampAngle(float var, float min, float max)
  6. clampColour(float value)
  7. clampDegree0To360(float degree)
  8. clampFloat(float value, float minimum, float maximum)
  9. clampLevel(float level)