/// <summary> /// Determine where exactly the current trainpath node is on the track node /// </summary> /// <param name="startNode">The start node</param> /// <param name="nextNode">The next node (so also the direction can be understood)</param> /// <param name="tn">The tracknode connecting the startNode and nextNode</param> /// <param name="isForward">Output: whether going from startNode to nextNode is in the forward direction of the track</param> /// <param name="tvsiStart">Output: the track vector section index of where the startNode is</param> /// <param name="sectionOffsetStart">Output: the offset in the section (in the direction of the tracknode, not necessarily in the direction from startNode to nextNode)</param> private void DetermineSectionDetails(TrainpathNode startNode, TrainpathNode nextNode, TrackNode tn, out bool isForward, out int tvsiStart, out float sectionOffsetStart) { TrainpathVectorNode currentNodeAsVector = startNode as TrainpathVectorNode; TrainpathJunctionNode currentNodeAsJunction = startNode as TrainpathJunctionNode; if (currentNodeAsJunction != null) { // we start at a junction node isForward = (currentNodeAsJunction.JunctionIndex == tn.JunctionIndexAtStart()); if (isForward) { tvsiStart = 0; sectionOffsetStart = 0; } else { tvsiStart = tn.TrVectorNode.TrVectorSections.Count() - 1; sectionOffsetStart = SectionLengthAlongTrack(tn, tvsiStart); } } else { // we start at a vector node isForward = currentNodeAsVector.IsEarlierOnTrackThan(nextNode); tvsiStart = currentNodeAsVector.TrackVectorSectionIndex; sectionOffsetStart = currentNodeAsVector.TrackSectionOffset; } }
/// <summary> /// Determine if the path from currentNode to nextNode is in the forward direction of the track (along main path) /// </summary> private bool DetermineIfForward(TrainpathNode currentNode, TrainpathNode nextNode) { // It would be nice if we could separate this into different classes for vector and junction, but this would mean creating three additional classes for only a few methods TrainpathVectorNode currentNodeAsVector = currentNode as TrainpathVectorNode; if (currentNodeAsVector != null) { return(currentNodeAsVector.IsEarlierOnTrackThan(nextNode)); } else { TrainpathJunctionNode currentNodeAsJunction = currentNode as TrainpathJunctionNode; return(currentNodeAsJunction.JunctionIndex == trackDB.TrackNodes[currentNode.NextMainTvnIndex].JunctionIndexAtStart()); } }