Java Integer Clamp clampLoop(int v, int min, int max)

Here you can find the source of clampLoop(int v, int min, int max)

Description

clamp Loop

License

Open Source License

Declaration

public static int clampLoop(int v, int min, int max) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014,2015 Hideki Yatomi
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

public class Main {
    public static int clampLoop(int v, int min, int max) {
        if (min == max)
            return min;
        int range = max - min;
        if (v < min)
            v = max + 1 - ((min - v) % range);
        if (v > max)
            v = min - 1 + ((v - max) % range);
        return v;
    }//from   w ww.  j a  v a  2s.c  o  m
}

Related

  1. clampInt(final int min, final int max, final int value)
  2. clampInt(final int min, final int value, final int max)
  3. clampInt(int value, int min, int max)
  4. clampInt(int value, int min, int max)
  5. CLAMPIS(int a, int b, int c)
  6. clampMono(int value)
  7. clampNonNegative(int i, int a, int b)
  8. clampPower(int num)
  9. clampRGB(int val)