geography
Class Route

java.lang.Object
  |
  +--geography.Route

public class Route
extends java.lang.Object

A route in a Streetmap. This is just a wrapper around a Path in the Streetmap's graph, whose vertices hold Points and whose edges hold street names. The toString() method gives nice route descriptions.


Field Summary
protected static java.lang.String[] DIR_NAMES
          Direction names for evenly spaced points around the compass.
protected static double MERGE_ANGLE_TOLERANCE
          Two segments of the same street need not be separately reported unless their direction changes by more than plus or minus this many degrees.
protected  graph.Path path
          The path, or null if no path exists.
protected static double[] TURN_CUTOFFS
          Cutoffs for the different descriptions in TURN_NAMES.
protected static java.lang.String[] TURN_NAMES
          To describe a turn of d degrees, we use the first description in TURN_NAMES whose corresponding cutoff in TURN_CUTOFFS is >= d.
protected  int verbosity
          See Route(Path,int).
 
Constructor Summary
Route(graph.Path path)
          Turns a Path into a Route.
Route(graph.Path path, int verbosity)
          Turns a Path into a Route.
 
Method Summary
protected  java.lang.String angleString(double degrees)
          Way to print angles for the user.
protected static double dirChange(graph.DirectedEdge e1, graph.DirectedEdge e2)
          Change in direction of a turn from e1 onto e2.
protected  java.lang.String dirName(graph.DirectedEdge e)
          Turns a direction into its printable name.
protected  java.lang.String distanceString(double meters)
          Turns a distance into printable form.
protected  graph.DirectedEdge getEdge(int index)
          Get a particular edge of the path.
private  boolean hasTurn(graph.DirectedEdge e1, graph.DirectedEdge e2)
          Do we have to report a turn from e1 onto e2, or are we just continuing pretty much straight on the same street?
private  boolean streetChange(graph.DirectedEdge e1, graph.DirectedEdge e2)
          Does the transition from e1 to e2 represent a change of street?
protected  java.lang.String streetName(graph.DirectedEdge e)
          Given an edge, returns a printable street name for the street segment it represents.
 java.lang.String toString()
          Describes the route as a long string of several \n-terminated lines.
protected  java.lang.String turnName(graph.DirectedEdge e1, graph.DirectedEdge e2)
          Turns a change in direction into its printable name: describes a turn from ss1 onto ss2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

path

protected graph.Path path
The path, or null if no path exists.


verbosity

protected int verbosity
See Route(Path,int).


MERGE_ANGLE_TOLERANCE

protected static final double MERGE_ANGLE_TOLERANCE
Two segments of the same street need not be separately reported unless their direction changes by more than plus or minus this many degrees.

See Also:
Constant Field Values

TURN_CUTOFFS

protected static final double[] TURN_CUTOFFS
Cutoffs for the different descriptions in TURN_NAMES. Last value should be 180 (or more).


TURN_NAMES

protected static final java.lang.String[] TURN_NAMES
To describe a turn of d degrees, we use the first description in TURN_NAMES whose corresponding cutoff in TURN_CUTOFFS is >= d.


DIR_NAMES

protected static final java.lang.String[] DIR_NAMES
Direction names for evenly spaced points around the compass. We divide the compass into this many equal pie slices. The first name DIR_NAMES[0] refers to the slice centered at 0 degrees, and the remaining names proceed counterclockwise.

Constructor Detail

Route

public Route(graph.Path path)
Turns a Path into a Route.


Route

public Route(graph.Path path,
             int verbosity)
Turns a Path into a Route. Verbosity level can be 0, 1, 2, or 3. It controls how much detail is included in the directions produced by toString()

Method Detail

toString

public java.lang.String toString()
Describes the route as a long string of several \n-terminated lines. Example line: "Bear left onto Main St going northeast and continue 2.3 miles.\n" The 2.3 miles here may be made of several edges, and perhaps only the first of these goes northeast, although any abrupt changes in direction or street name (as detected by hasTurn(graph.DirectedEdge, graph.DirectedEdge)) would have caused us to break this line into multiple lines.

Overrides:
toString in class java.lang.Object

streetName

protected java.lang.String streetName(graph.DirectedEdge e)
Given an edge, returns a printable street name for the street segment it represents.


dirName

protected java.lang.String dirName(graph.DirectedEdge e)
Turns a direction into its printable name. See documentation for DIR_NAMES.


turnName

protected java.lang.String turnName(graph.DirectedEdge e1,
                                    graph.DirectedEdge e2)
Turns a change in direction into its printable name: describes a turn from ss1 onto ss2. See documentation for TURN_NAMES.


distanceString

protected java.lang.String distanceString(double meters)
Turns a distance into printable form.


angleString

protected java.lang.String angleString(double degrees)
Way to print angles for the user.


hasTurn

private boolean hasTurn(graph.DirectedEdge e1,
                        graph.DirectedEdge e2)
Do we have to report a turn from e1 onto e2, or are we just continuing pretty much straight on the same street?

An unnamed street is fair game to be the same as this one. See documentation for MERGE_ANGLE_TOLERANCE. If verbosity is >= 3, we report all turns.


streetChange

private boolean streetChange(graph.DirectedEdge e1,
                             graph.DirectedEdge e2)
Does the transition from e1 to e2 represent a change of street?

If either edge is unnamed, assume there's no change of street. This reduces the number of unnamed edges that are unnecessarily printed -- it is common for one segment of a long street to be missing its name.


getEdge

protected graph.DirectedEdge getEdge(int index)
Get a particular edge of the path.


dirChange

protected static final double dirChange(graph.DirectedEdge e1,
                                        graph.DirectedEdge e2)
Change in direction of a turn from e1 onto e2.

Return value is from -180 to 180 degrees. Positive values are counterclockwise.

This method is final because it doesn't make sense to override it; it's just true.