com.threerings.util
Class DirectionUtil

java.lang.Object
  extended by com.threerings.util.DirectionUtil
All Implemented Interfaces:
DirectionCodes

public class DirectionUtil
extends Object
implements DirectionCodes

Direction related utility functions.


Field Summary
protected static int[] ANGLE_MAP
          Used to map an angle to a fine compass direction.
protected static String[] DIR_STRINGS
          Direction constant string names.
protected static int[] FINE_CCW_ROTATE
          Used to rotate a fine compass direction counter-clockwise.
protected static int[] FINE_CW_ROTATE
          Used to rotate a fine compass direction clockwise.
protected static String[] SHORT_DIR_STRINGS
          Abbreviated direction constant string names.
 
Fields inherited from interface com.threerings.util.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 Summary
DirectionUtil()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR_STRINGS

protected static final String[] DIR_STRINGS
Direction constant string names.


SHORT_DIR_STRINGS

protected static final String[] SHORT_DIR_STRINGS
Abbreviated direction constant string names.


FINE_CW_ROTATE

protected static final int[] FINE_CW_ROTATE
Used to rotate a fine compass direction clockwise.


FINE_CCW_ROTATE

protected static final int[] FINE_CCW_ROTATE
Used to rotate a fine compass direction counter-clockwise.


ANGLE_MAP

protected static final int[] ANGLE_MAP
Used to map an angle to a fine compass direction.

Constructor Detail

DirectionUtil

public DirectionUtil()
Method Detail

getDirectionNames

public static String[] getDirectionNames()
Returns an array of names corresponding to each direction constant.


toString

public static String toString(int direction)
Returns a string representation of the supplied direction code.


toShortString

public static String toShortString(int direction)
Returns an abbreviated string representation of the supplied direction code.


fromString

public 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.


fromShortString

public 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.


toString

public static String toString(int[] directions)
Returns a string representation of an array of direction codes. The directions are represented by the abbreviated names.


rotateCW

public static int rotateCW(int direction,
                           int ticks)
Rotates the requested fine direction constant clockwise by the requested number of ticks.


rotateCCW

public static int rotateCCW(int direction,
                            int ticks)
Rotates the requested fine direction constant counter-clockwise by the requested number of ticks.


getOpposite

public static int getOpposite(int direction)
Returns the opposite of the specified direction.


getClosestCardinal

public static int getClosestCardinal(int direction)
Get the cardinal direction closest to the specified direction (preferring a clockwise match).


getClosest

public 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).


getClosest

public 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.

Parameters:
preferCW - whether to prefer a clockwise match or a counter-clockwise match.

getDirection

public 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. 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.


getDirection

public 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. 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.


getDirection

public 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. 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.


getDirection

public static int getDirection(double theta)
Returns which of the eight compass directions is associated with the specified angle theta. Note: that the angle supplied is assumed to increase clockwise around the origin (which screen angles do) rather than counter-clockwise around the origin (which cartesian angles do) and NORTH is considered to point toward the top of the screen.


getFineDirection

public 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. 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.


getFineDirection

public 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. 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.


getFineDirection

public static int getFineDirection(double theta)
Returns which of the sixteen compass directions is associated with the specified angle theta. Note: that the angle supplied is assumed to increase clockwise around the origin (which screen angles do) rather than counter-clockwise around the origin (which cartesian angles do) and NORTH is considered to point toward the top of the screen.


moveDirection

public 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. Fine directions are not supported.