public class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static double |
NEAR_DELTA |
Modifier and Type | Method and Description |
---|---|
static String |
angleToApproximateDirection(double angle)
Returns approximate cardinal direction for absolute angle in radians, like N,NE,E,SE,S,SW,W,NW
|
static void |
assertEquals(String message,
Object expected,
Object actual)
Throws AssertionError when the params expected and actual do not equal each other.
|
static void |
assertNear(String message,
double expected,
double actual)
Throws AssertionError when the params expected and actual do not within .00001 difference.
|
static void |
assertNotNull(String message,
Object value)
Throws AssertionError when the param value is null.
|
static void |
assertTrue(String message,
boolean assertion)
Throws AssertionError when the assertion is false.
|
static Random |
getRandom()
Returns random number generator.
|
static boolean |
isNear(double value1,
double value2)
Tests if the two
double values are near to each other. |
static double |
normalAbsoluteAngle(double angle)
Normalizes an angle to an absolute angle.
|
static double |
normalAbsoluteAngleDegrees(double angle)
Normalizes an angle to an absolute angle.
|
static double |
normalNearAbsoluteAngle(double angle)
Normalizes an angle to be near an absolute angle.
|
static double |
normalNearAbsoluteAngleDegrees(double angle)
Normalizes an angle to be near an absolute angle.
|
static double |
normalRelativeAngle(double angle)
Normalizes an angle to a relative angle.
|
static double |
normalRelativeAngleDegrees(double angle)
Normalizes an angle to a relative angle.
|
public static final double NEAR_DELTA
public static double normalAbsoluteAngle(double angle)
angle
- the angle to normalizepublic static double normalAbsoluteAngleDegrees(double angle)
angle
- the angle to normalizepublic static double normalRelativeAngle(double angle)
angle
- the angle to normalizepublic static double normalRelativeAngleDegrees(double angle)
angle
- the angle to normalizepublic static double normalNearAbsoluteAngleDegrees(double angle)
isNear
method is used for defining when the angle is near one of angles listed
above.angle
- the angle to normalizenormalAbsoluteAngle(double)
,
isNear(double, double)
public static double normalNearAbsoluteAngle(double angle)
isNear
method is used for defining when the angle is near one of angles listed
above.angle
- the angle to normalizenormalAbsoluteAngle(double)
,
isNear(double, double)
public static boolean isNear(double value1, double value2)
double
values are near to each other.
It is recommended to use this method instead of testing if the two
doubles are equal using an this expression: value1 == value2
.
The reason being, that this expression might never become
true
due to the precision of double values.
Whether or not the specified doubles are near to each other is defined by
the following expression:
(Math.abs(value1 - value2) < .00001)
value1
- the first double valuevalue2
- the second double valuetrue
if the two doubles are near to each other;
false
otherwise.public static Random getRandom()
public static void assertNotNull(String message, Object value)
message
- of the eventual errorvalue
- tested valuepublic static void assertEquals(String message, Object expected, Object actual)
message
- of the eventual errorexpected
- expected valueactual
- tested valuepublic static void assertTrue(String message, boolean assertion)
message
- of the eventual errorassertion
- expected to be truepublic static void assertNear(String message, double expected, double actual)
message
- of the eventual errorexpected
- expected valueactual
- tested valuepublic static String angleToApproximateDirection(double angle)
angle
- absolute angle in radiansCopyright © 2021 Robocode. All Rights Reserved.