jfreerails.world.train
Class PathWalkerImpl

java.lang.Object
  extended by jfreerails.world.train.PathWalkerImpl
All Implemented Interfaces:
java.io.Serializable, FreerailsMutableSerializable, FreerailsPathIterator, PathWalker

public class PathWalkerImpl
extends java.lang.Object
implements PathWalker

PathWalker that walks the path exposed by a FreerailsPathIterator.

Author:
Luke
See Also:
Serialized Form

Field Summary
private  boolean beforeFirst
           
private  IntLine currentSegment
          current segment of the path we are on.
private  double distanceAlongCurrentSegment
           
private  double distanceOfThisStepRemaining
           
private  FreerailsPathIterator it
           
private  int lastX
           
private  int lastY
           
private static long serialVersionUID
           
 
Constructor Summary
PathWalkerImpl(FreerailsPathIterator i)
           
 
Method Summary
 boolean canStepForward()
          Returns true if we have not reached the end of the path.
private  void endAtSegmentEnd(IntLine line, double remainingDistanceAlongCurrentSegment)
           
private  void endInMiddleOfSegment(IntLine line)
           
private  int getCoorinateOnSegment(double distanceAlongSegment, int coordinate1, int coordinate2)
           
 boolean hasNext()
          Tests whether the path has another segment.
 void nextSegment(IntLine line)
          Gets the next segment of the path and places its coordinates in the specified IntLine; then moves the iterator forwards by one path segment.
private  void startInMiddleOfSegment(IntLine line)
           
private  void startNewSegment(IntLine line)
           
 void stepForward(double distance)
          Specify the distance this PathWalker is to progress along the current step.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

it

private final FreerailsPathIterator it

currentSegment

private final IntLine currentSegment
current segment of the path we are on.


distanceAlongCurrentSegment

private double distanceAlongCurrentSegment

distanceOfThisStepRemaining

private double distanceOfThisStepRemaining

beforeFirst

private boolean beforeFirst

lastX

private int lastX

lastY

private int lastY
Constructor Detail

PathWalkerImpl

public PathWalkerImpl(FreerailsPathIterator i)
Method Detail

canStepForward

public boolean canStepForward()
Description copied from interface: PathWalker
Returns true if we have not reached the end of the path.

Specified by:
canStepForward in interface PathWalker
Returns:
true if we still have more of the current segment, or more segments left.

stepForward

public void stepForward(double distance)
Specify the distance this PathWalker is to progress along the current step.

Specified by:
stepForward in interface PathWalker

hasNext

public boolean hasNext()
Description copied from interface: FreerailsPathIterator
Tests whether the path has another segment.

Specified by:
hasNext in interface FreerailsPathIterator
Returns:
true if there is still some distance to go along this path

nextSegment

public void nextSegment(IntLine line)
Description copied from interface: FreerailsPathIterator
Gets the next segment of the path and places its coordinates in the specified IntLine; then moves the iterator forwards by one path segment. (The coordinates are placed the passed-in IntLine rather than a new object to avoid the cost of object creation.)

Specified by:
nextSegment in interface FreerailsPathIterator

endInMiddleOfSegment

private void endInMiddleOfSegment(IntLine line)

endAtSegmentEnd

private void endAtSegmentEnd(IntLine line,
                             double remainingDistanceAlongCurrentSegment)

startInMiddleOfSegment

private void startInMiddleOfSegment(IntLine line)

startNewSegment

private void startNewSegment(IntLine line)

getCoorinateOnSegment

private int getCoorinateOnSegment(double distanceAlongSegment,
                                  int coordinate1,
                                  int coordinate2)