Added moveDirection() which can move a point in the specified
screen direction. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2551 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DirectionUtil.java,v 1.8 2003/02/12 07:22:04 mdb Exp $
|
||||
// $Id: DirectionUtil.java,v 1.9 2003/05/07 19:41:57 ray Exp $
|
||||
|
||||
package com.threerings.util;
|
||||
|
||||
@@ -195,6 +195,32 @@ public class DirectionUtil implements DirectionCodes
|
||||
return ANGLE_MAP[(int)Math.round(theta) % FINE_DIRECTION_COUNT];
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the specified point the specified number of logical
|
||||
* pixels in the specified direction. Fine coordinates are
|
||||
* not supported.
|
||||
*/
|
||||
public static void moveDirection (Point p, int direction, int dx, int dy)
|
||||
{
|
||||
if (direction >= DIRECTION_COUNT) {
|
||||
throw new IllegalArgumentException(
|
||||
"Fine coordinates not supported.");
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case NORTH: case NORTHWEST: case NORTHEAST: p.y -= dy;
|
||||
}
|
||||
switch (direction) {
|
||||
case SOUTH: case SOUTHWEST: case SOUTHEAST: p.y += dy;
|
||||
}
|
||||
switch (direction) {
|
||||
case WEST: case SOUTHWEST: case NORTHWEST: p.x -= dx;
|
||||
}
|
||||
switch (direction) {
|
||||
case EAST: case SOUTHEAST: case NORTHEAST: p.x += dx;
|
||||
}
|
||||
}
|
||||
|
||||
/** Direction constant string names. */
|
||||
protected static final String[] DIR_STRINGS = {
|
||||
"SOUTHWEST", "WEST", "NORTHWEST", "NORTH",
|
||||
|
||||
Reference in New Issue
Block a user