net.kolls.railworld
Class CLoc

java.lang.Object
  extended by net.kolls.railworld.CLoc

public class CLoc
extends java.lang.Object

The CLoc class pinpoints a location and direction within the map (on a track). Locations are represented using three pieces: The rail segment, the originating rail segment, and the percentage from the originating rail segment. For example, say segment A is 50 feet long, connecting at one end to segment B and at the other end to segment C. If the current segment is A, the originating segment is B, and the percentage is 0.75, the we are on segment A, heading toward segment C, currently at 37.5 feet into segment A.

Author:
Steve Kollmansberger

Field Summary
 RailSegment orig
          The origin RailSegment.
 double per
          Percentage (0-1) through the segment.
 RailSegment r
          The current RailSegment.
 
Constructor Summary
CLoc()
          Constructs a CLoc will all null values.
CLoc(RailSegment cur, RailSegment start, double p)
          Constructs a CLoc given the three essentials.
 
Method Summary
 java.awt.geom.Point2D getPoint()
          Returns an absolute point for this location.
 CLoc reverse()
          Returns the same position with opposite directionality.
 DLoc segFwd(Distance len)
          Moves forward in the direction of travel a given distance.
 DLoc segFwd(Distance len, Car myC, Train myT)
          Moves forward in the direction of travel a given distance, and generate rendering information for a given Train and/or Car.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

r

public RailSegment r
The current RailSegment. The position is somewhere on this segment.


orig

public RailSegment orig
The origin RailSegment. This is where we came from. This provides directionality to the location.


per

public double per
Percentage (0-1) through the segment. 0 means we are right at the origin segment. 1 means we are all the way to the opposite end, where the segment ends. Movement can be accomplished by increasing this value.

Constructor Detail

CLoc

public CLoc(RailSegment cur,
            RailSegment start,
            double p)
Constructs a CLoc given the three essentials.

Parameters:
cur - Current RailSegment
start - The RailSegment we came from (originating segment)
p - The percentage through the current segment we are.

CLoc

public CLoc()
Constructs a CLoc will all null values.

Method Detail

reverse

public CLoc reverse()
Returns the same position with opposite directionality. This relies on another segment beyond the current one in the facing direction to become the origin. It also flips the percentage.

Returns:
A new CLoc containing the same position facing the opposite direction.

getPoint

public java.awt.geom.Point2D getPoint()
Returns an absolute point for this location.

Returns:
A Point2D for this location.

segFwd

public DLoc segFwd(Distance len)
Moves forward in the direction of travel a given distance.

Parameters:
len - A Distance representing how far to move. The distance may exceed the current segment.
Returns:
A DLoc representing the new location.

segFwd

public DLoc segFwd(Distance len,
                   Car myC,
                   Train myT)
Moves forward in the direction of travel a given distance, and generate rendering information for a given Train and/or Car. This method generates the lines which will be drawn to render cars in a Train. Note that lines will not be rendered for hidden segments, and cars will not be curved. This method also registers the train and car with the segments and vice versa.

Parameters:
len - A Distance representing how far to move. The distance may exceed the current segment.
myC - A Car for tracking segments. May be null.
myT - A Train for tracking segments and recordings enters. May be null
Returns:
A DLoc representing the new location, and including rendering information.