Cardinals.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@727 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Dave Hoover
2008-12-03 18:53:20 +00:00
parent 42aa38f832
commit 1680e5135b
2 changed files with 12 additions and 1 deletions
@@ -35,7 +35,7 @@ public interface DirectionCodes
/** A direction code indicating moving right. */
public static final int RIGHT = 1;
/** A direction code indicating moving up. */
public static final int UP = 2;
@@ -107,4 +107,7 @@ public interface DirectionCodes
/** The number of fine compass directions. */
public static final int FINE_DIRECTION_COUNT = 16;
/** The four points of the compass. */
public static final int[] CARDINAL_DIRECTIONS = { NORTH, SOUTH, EAST, WEST };
}
@@ -135,6 +135,14 @@ public class DirectionUtil implements DirectionCodes
return rotateCW(direction, FINE_CW_ROTATE.length/2);
}
/**
* Get the cardinal direction closest to the specified direction (preferring a clockwise match).
*/
public static int getClosestCardinal (int direction)
{
return getClosest(direction, CARDINAL_DIRECTIONS, true);
}
/**
* Get the direction closest to the specified direction, out of
* the directions in the possible list (preferring a clockwise match).