jfreerails.world.common
Class Step

java.lang.Object
  extended by jfreerails.world.common.Step
All Implemented Interfaces:
java.io.Serializable, FlatTrackTemplate, FreerailsSerializable

public final class Step
extends java.lang.Object
implements FlatTrackTemplate

This class represents a movement from a tile to any one of the surrounding eight tiles.

Author:
Luke
See Also:
Serialized Form

Field Summary
 int deltaX
          The X and Y components of the vector.
 int deltaY
          The X and Y components of the vector.
static Step EAST
          East.
private  int flatTrackTemplate
           
private  double length
           
private static Step[] list
          Another array of OneTileMoveVectors representing the 8 compass directions going clockwise from North.
static Step NORTH
          North.
static Step NORTH_EAST
          North-East.
static Step NORTH_WEST
          North West.
private static long serialVersionUID
           
static Step SOUTH
          South.
static Step SOUTH_EAST
          South East.
static Step SOUTH_WEST
          South West.
static double TILE_DIAGONAL
           
static int TILE_DIAMETER
           
private static Step[][] vectors
          A 3x3 array of OneTileMoveVectors, representing vectors to eight adjacent tiles plus a zero-distance vector.
static Step WEST
          West.
 
Constructor Summary
private Step(int x, int y, int t)
          Create a new OneTileMoveVector.
 
Method Summary
static boolean checkValidity(ImPoint a, ImPoint b)
           
static boolean checkValidity(int x, int y)
          Returns true if the values passed could be used to create a valid vector.
 boolean contains(FlatTrackTemplate ftt)
           
 ImPoint createRelocatedPoint(ImPoint from)
           
 int get8bitTemplate()
           
 int get9bitTemplate()
           
 double getDirection()
           
 int getDx()
          Returns the X component of the vector.
 int getDy()
          Returns the Y component of the vector.
 int getID()
           
static Step getInstance(int number)
           
static Step getInstance(int dx, int dy)
           
 double getLength()
           
static Step[] getList()
           
static Step getNearestVector(int dx, int dy)
           
 Step getOpposite()
          Returns a new oneTileMoveVector whose direction is opposite to that the current one.
 boolean isDiagonal()
           
static ImPoint move(ImPoint p, Step... path)
           
private  java.lang.Object readResolve()
           
private static Step[][] setupVectors()
           
 java.lang.String toAbrvString()
           
 java.lang.String toString()
          Returns the name of the vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

TILE_DIAMETER

public static final int TILE_DIAMETER
See Also:
Constant Field Values

TILE_DIAGONAL

public static final double TILE_DIAGONAL

NORTH

public static final Step NORTH
North.


WEST

public static final Step WEST
West.


SOUTH_EAST

public static final Step SOUTH_EAST
South East.


NORTH_EAST

public static final Step NORTH_EAST
North-East.


EAST

public static final Step EAST
East.


SOUTH

public static final Step SOUTH
South.


SOUTH_WEST

public static final Step SOUTH_WEST
South West.


NORTH_WEST

public static final Step NORTH_WEST
North West.


vectors

private static final Step[][] vectors
A 3x3 array of OneTileMoveVectors, representing vectors to eight adjacent tiles plus a zero-distance vector.


list

private static Step[] list
Another array of OneTileMoveVectors representing the 8 compass directions going clockwise from North.


deltaX

public final int deltaX
The X and Y components of the vector.


deltaY

public final int deltaY
The X and Y components of the vector.


flatTrackTemplate

private final int flatTrackTemplate

length

private final double length
Constructor Detail

Step

private Step(int x,
             int y,
             int t)
Create a new OneTileMoveVector. N.B Private constuctor to enforce enum property, use getInstance(x,y) instead. Pass values for delta X and Y: they must be in the range -1 to 1 and cannot both be equal to 0.

Parameters:
x - Tile coordinate.
y - Tile coordinate
t - an integer representing the track template this vector corresponds to.
Method Detail

setupVectors

private static Step[][] setupVectors()

move

public static ImPoint move(ImPoint p,
                           Step... path)

getDx

public int getDx()
Returns the X component of the vector.


getDy

public int getDy()
Returns the Y component of the vector.


getOpposite

public Step getOpposite()
Returns a new oneTileMoveVector whose direction is opposite to that the current one.

Returns:
A oneTileMoveVector.

toString

public java.lang.String toString()
Returns the name of the vector. E.g. "north-east"

Overrides:
toString in class java.lang.Object
Returns:
the name.

toAbrvString

public java.lang.String toAbrvString()

getInstance

public static Step getInstance(int number)

checkValidity

public static boolean checkValidity(ImPoint a,
                                    ImPoint b)

getInstance

public static Step getInstance(int dx,
                               int dy)

checkValidity

public static boolean checkValidity(int x,
                                    int y)
Returns true if the values passed could be used to create a valid vector.


createRelocatedPoint

public ImPoint createRelocatedPoint(ImPoint from)

contains

public boolean contains(FlatTrackTemplate ftt)
Specified by:
contains in interface FlatTrackTemplate
Parameters:
ftt - the FlatTrackTemplate which may be a subset of this FlatTrackTemplate.
Returns:
true if the vectors represented by this FlatTrackTemplate are a superset of the vectors of the specified FlatTrackTemplate

get9bitTemplate

public int get9bitTemplate()
Specified by:
get9bitTemplate in interface FlatTrackTemplate
Returns:
the integer representing the vector(s) of this object.

getList

public static Step[] getList()
Returns:
a copy of the list of 8 OneTileMoveVectors going clockwise from North.

getLength

public double getLength()
Returns:
the length of this vector. Each tile is 100 units x 100 units.

getDirection

public double getDirection()

getID

public int getID()
Returns:
a number representing the compass point this vector indicates, with 0 representing North, 1 NorthEast, 2 East and so on.

readResolve

private java.lang.Object readResolve()
                              throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

getNearestVector

public static Step getNearestVector(int dx,
                                    int dy)
Returns:
the OneTileMoveVector nearest in orientation to the specified dx, dy

isDiagonal

public boolean isDiagonal()

get8bitTemplate

public int get8bitTemplate()