Here you can find the source of clampLoop(int v, int min, int max)
public static int clampLoop(int v, int min, int max)
//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 }