public class DirectionUtil extends Object implements DirectionCodes
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST| Constructor and Description |
|---|
DirectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static int |
fromShortString(String dirstr)
Returns the direction code that corresponds to the supplied short string or
DirectionCodes.NONE
if the string does not correspond to a known direction code. |
static int |
fromString(String dirstr)
Returns the direction code that corresponds to the supplied string or
DirectionCodes.NONE if the
string does not correspond to a known direction code. |
static int |
getClosest(int direction,
int[] possible)
Get the direction closest to the specified direction, out of the directions in the possible
list (preferring a clockwise match).
|
static int |
getClosest(int direction,
int[] possible,
boolean preferCW)
Get the direction closest to the specified direction, out of the directions in the possible
list.
|
static int |
getClosestCardinal(int direction)
Get the cardinal direction closest to the specified direction (preferring a clockwise match).
|
static int |
getDirection(double theta)
Returns which of the eight compass directions is associated with the specified angle theta.
|
static int |
getDirection(double ax,
double ay,
double bx,
double by)
Returns which of the eight compass directions that point
b lies in from point
a as one of the DirectionCodes direction constants. |
static int |
getDirection(int ax,
int ay,
int bx,
int by)
Returns which of the eight compass directions that point
b lies in from point
a as one of the DirectionCodes direction constants. |
static int |
getDirection(Point a,
Point b)
Returns which of the eight compass directions that point
b lies in from point
a as one of the DirectionCodes direction constants. |
static String[] |
getDirectionNames()
Returns an array of names corresponding to each direction constant.
|
static int |
getFineDirection(double theta)
Returns which of the sixteen compass directions is associated with the specified angle
theta.
|
static int |
getFineDirection(int ax,
int ay,
int bx,
int by)
Returns which of the sixteen compass directions that point
b lies in from
point a as one of the DirectionCodes direction constants. |
static int |
getFineDirection(Point a,
Point b)
Returns which of the sixteen compass directions that point
b lies in from
point a as one of the DirectionCodes direction constants. |
static int |
getOpposite(int direction)
Returns the opposite of the specified direction.
|
static void |
moveDirection(Point p,
int direction,
int dx,
int dy)
Move the specified point in the specified screen direction, adjusting by the specified
adjustments.
|
static int |
rotateCCW(int direction,
int ticks)
Rotates the requested fine direction constant counter-clockwise by the requested
number of ticks.
|
static int |
rotateCW(int direction,
int ticks)
Rotates the requested fine direction constant clockwise by the requested number of
ticks.
|
static String |
toShortString(int direction)
Returns an abbreviated string representation of the supplied direction code.
|
static String |
toString(int direction)
Returns a string representation of the supplied direction code.
|
static String |
toString(int[] directions)
Returns a string representation of an array of direction codes.
|
public static String[] getDirectionNames()
public static String toString(int direction)
public static String toShortString(int direction)
public static int fromString(String dirstr)
DirectionCodes.NONE if the
string does not correspond to a known direction code.public static int fromShortString(String dirstr)
DirectionCodes.NONE
if the string does not correspond to a known direction code.public static String toString(int[] directions)
public static int rotateCW(int direction,
int ticks)
public static int rotateCCW(int direction,
int ticks)
public static int getOpposite(int direction)
public static int getClosestCardinal(int direction)
public static int getClosest(int direction,
int[] possible)
public static int getClosest(int direction,
int[] possible,
boolean preferCW)
preferCW - whether to prefer a clockwise match or a counter-clockwise match.public static int getDirection(Point a, Point b)
b lies in from point
a as one of the DirectionCodes direction constants. Note:
that the coordinates supplied are assumed to be logical (screen) rather than cartesian
coordinates and NORTH is considered to point toward the top of the screen.public static int getDirection(int ax,
int ay,
int bx,
int by)
b lies in from point
a as one of the DirectionCodes direction constants. Note:
that the coordinates supplied are assumed to be logical (screen) rather than cartesian
coordinates and NORTH is considered to point toward the top of the screen.public static int getDirection(double ax,
double ay,
double bx,
double by)
b lies in from point
a as one of the DirectionCodes direction constants. Note:
that the coordinates supplied are assumed to be logical (screen) rather than cartesian
coordinates and NORTH is considered to point toward the top of the screen.public static int getDirection(double theta)
NORTH is considered to point toward the top of the screen.public static int getFineDirection(Point a, Point b)
b lies in from
point a as one of the DirectionCodes direction constants.
Note: that the coordinates supplied are assumed to be logical (screen) rather than
cartesian coordinates and NORTH is considered to point toward the top of the
screen.public static int getFineDirection(int ax,
int ay,
int bx,
int by)
b lies in from
point a as one of the DirectionCodes direction constants.
Note: that the coordinates supplied are assumed to be logical (screen) rather than
cartesian coordinates and NORTH is considered to point toward the top of the
screen.public static int getFineDirection(double theta)
NORTH is considered to point toward the top of the
screen.public static void moveDirection(Point p, int direction, int dx, int dy)
Copyright © 2015. All rights reserved.