@Immutable public final class Direction extends Object
EAST
is a direction of 0 and NORTH
is a
direction of π⁄2. The angle measurement of a
direction will always be in the range [0, 2π).Modifier and Type | Class | Description |
---|---|---|
static class |
Direction.Deserializer |
A deserializer for directions.
|
static class |
Direction.Serializer |
A serializer for directions.
|
Modifier and Type | Field | Description |
---|---|---|
static Direction |
EAST |
The direction with measurement 0.
|
static Direction |
NORTH |
The direction with measurement π⁄2.
|
static Direction |
SOUTH |
The direction with measurement 3π⁄2.
|
static Direction |
WEST |
The direction with measurement π.
|
Constructor | Description |
---|---|
Direction(double direction) |
Constructs a direction object with the given direction measurement.
|
Modifier and Type | Method | Description |
---|---|---|
Direction |
add(double angle) |
Adds the given amount to this direction, returning the result of the
addition.
|
static double |
difference(Direction alpha,
Direction beta) |
Returns the signed difference between two angles.
|
boolean |
equals(Object other) |
|
double |
get() |
Returns the measurement of this direction object, in radians, where
EAST is 0.0 and measurements increase as they rotate
counter-clockwise. |
Direction |
getOpposite() |
Returns the direction that is the opposite of this one.
|
int |
hashCode() |
|
static Direction |
random() |
Returns a randomly-generated direction.
|
Direction |
reflectAcrossX() |
Reflects this direction across the x-axis, returning the result.
|
Direction |
reflectAcrossY() |
Reflects this direction across the y-axis, returning the result.
|
String |
toString() |
public static final Direction EAST
public static final Direction NORTH
public static final Direction WEST
public static final Direction SOUTH
public Direction(double direction)
get()
on the returned object may return something
different than the passed-in direction measurement if the given
measurement is outside the range [0, 2π). For example,
9π⁄4 would be converted to
π⁄4.direction
- the angle measurement of the desired directionIllegalArgumentException
- if direction is not finitepublic static Direction random()
public double get()
EAST
is 0.0 and measurements increase as they rotate
counter-clockwise. Direction objects are immutable, so this will always
return the same value.public Direction add(double angle)
angle
- the angle to add to this direction's angle measurementIllegalArgumentException
- if angle is not finitepublic Direction getOpposite()
public Direction reflectAcrossY()
public Direction reflectAcrossX()
public static double difference(Direction alpha, Direction beta)
add(double)
method is used to add the result of this method to
alpha, the resulting angle will be very close to beta, and will differ
only due to issues with floating-point arithmetic.alpha
- the first anglebeta
- the second angle