/*******************************************************************************
* Copyright (c) 2001, 2008 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/cpl-v10.html
*
* Contributors:
* Mathew A. Nelson
* - Initial API and implementation
* Flemming N. Larsen
* - Moved all methods to classes like FileUtil, StringUtil, WindowUtil,
* Logger etc. exception for the following methods, which have been kept
* here as legacy robots make use of these methods:
* - normalAbsoluteAngle()
* - normalNearAbsoluteAngle()
* - normalRelativeAngle()
* - The isNear() was made public
* - Optimized and provided javadocs for all methods
*******************************************************************************/
import static java.lang.Math.PI;
import java.util.Random;
/**
* Utility class that provide methods for normalizing angles.
*
* @author Mathew A. Nelson (original)
* @author Flemming N. Larsen (contributor)
*/
public class Utils {
private final static double TWO_PI = 2 * PI;
/**
* Normalizes an angle to an absolute angle.
* The normalized angle will be in the range from 0 to 2*PI, where 2*PI
* itself is not included.
*
* @param angle the angle to normalize
* @return the normalized angle that will be in the range of [0,2*PI[
*/
public static double normalAbsoluteAngle(double angle) {
return (angle %= TWO_PI) >= 0 ? angle : (angle + TWO_PI);
}
}