From b545d1ff05cde210b4033babe39d6d37feea1258 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 7 May 2003 19:41:57 +0000 Subject: [PATCH] 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 --- .../com/threerings/util/DirectionUtil.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/util/DirectionUtil.java b/src/java/com/threerings/util/DirectionUtil.java index 563738249..9a43fce93 100644 --- a/src/java/com/threerings/util/DirectionUtil.java +++ b/src/java/com/threerings/util/DirectionUtil.java @@ -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",