jfreerails.client.view
Class NearestStationFinder

java.lang.Object
  extended by jfreerails.client.view.NearestStationFinder

public class NearestStationFinder
extends java.lang.Object

Provides methods that find the nearest station in a given direction, used by the select station popup window.

Author:
Luke

Field Summary
private  int MAX_DISTANCE_TO_SELECT_SQUARED
           
static int NOT_FOUND
           
private  FreerailsPrincipal principal
           
private  ReadOnlyWorld world
           
 
Constructor Summary
NearestStationFinder(ReadOnlyWorld w, FreerailsPrincipal player)
           
 
Method Summary
 int findNearestStation(int x, int y)
           
 int findNearestStationInDirection(int startStation, Step direction)
           
private  boolean isInRightDirection(Step direction, int deltaX, int deltaY)
          Returns true if the angle between direction and the vector (deltaX, deltaY) is less than 45 degrees.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_FOUND

public static final int NOT_FOUND
See Also:
Constant Field Values

world

private final ReadOnlyWorld world

principal

private final FreerailsPrincipal principal

MAX_DISTANCE_TO_SELECT_SQUARED

private final int MAX_DISTANCE_TO_SELECT_SQUARED
See Also:
Constant Field Values
Constructor Detail

NearestStationFinder

public NearestStationFinder(ReadOnlyWorld w,
                            FreerailsPrincipal player)
Method Detail

findNearestStation

public int findNearestStation(int x,
                              int y)

findNearestStationInDirection

public int findNearestStationInDirection(int startStation,
                                         Step direction)

isInRightDirection

private boolean isInRightDirection(Step direction,
                                   int deltaX,
                                   int deltaY)
Returns true if the angle between direction and the vector (deltaX, deltaY) is less than 45 degrees.