Package com.amalgamasimulation.trains
Class RailCar
java.lang.Object
com.amalgamasimulation.trains.RailCar
Represents a single railcar that is part of a
Train.
A RailCar has a fixed physical length and may be attached to a train
at a specific position defined by its sequence number and offset along the
train's overall length. The class also provides utility methods for computing
its position within the train and for obtaining its animation segment.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the animationSegmentcorresponding to this railcar’s position along the train’s current animation polyline.doubleReturns the starting offset of this railcar along the train’s total length.doubleReturns the ending offset of this railcar along the train’s total length.doubleReturns the physical length of this railcar.intReturns the sequence number of this railcar within the train.getTrain()Returns theTrainthis railcar is assigned to.voidAssigns this railcar to aTrainand defines its position within the train.
-
Field Details
-
length
protected double length -
train
-
sequenceNumber
protected int sequenceNumber -
beginOffset
protected double beginOffset
-
-
Constructor Details
-
RailCar
public RailCar(double length) Creates a newRailCarwith the specified length.- Parameters:
length- the physical length of the railcar
-
-
Method Details
-
setTrain
Assigns this railcar to aTrainand defines its position within the train.- Parameters:
train- the train this railcar belongs tosequenceNumber- the railcar's index (position) within the trainbeginOffset- the starting offset of the railcar along the train’s total length
-
getLength
public double getLength()Returns the physical length of this railcar.- Returns:
- the length of the railcar
-
getTrain
Returns theTrainthis railcar is assigned to.- Returns:
- the train this railcar belongs to, or
nullif it is not assigned
-
getSequenceNumber
public int getSequenceNumber()Returns the sequence number of this railcar within the train.- Returns:
- the railcar’s sequence number, or
-1if not assigned
-
getBeginOffset
public double getBeginOffset()Returns the starting offset of this railcar along the train’s total length.- Returns:
- the starting offset of the railcar
-
getEndOffset
public double getEndOffset()Returns the ending offset of this railcar along the train’s total length.- Returns:
- the end offset of the railcar, computed as
beginOffset + length
-
getAnimationSegment
Returns the animationSegmentcorresponding to this railcar’s position along the train’s current animation polyline.The returned segment represents the spatial location of the railcar based on the animation path of the train. If the train or its animation polyline is not available, a segment with coordinates set to
Double.POSITIVE_INFINITYis returned.- Returns:
- the animation segment representing the railcar’s position, or a dummy infinite segment if unavailable
-