internal static void AdvanceOneRoad(TraversalParameters traversalParam, TraversalState traversalState) { if (!TryAdvanceOneRoad(traversalParam, traversalState)) { throw new InvalidOperationException( "Failed to advance along road network - you may want TryAdvanceOneRoad instead."); } }
// NOTE: Because this method advances by ROAD, any LANE information will be lost on traversal (reset to 0) // Use TryAdvanceOneLaneSection to move along a selected lane internal static bool TryAdvanceOneRoad(TraversalParameters traversalParam, TraversalState traversalState) { var roadCurrent = traversalParam.roadNetwork.GetRoadById(traversalState.RoadId); var link = GetLinkToNextRoad(roadCurrent, traversalState.Direction); if (link.linkType == RoadLinkType.None || traversalParam.shouldStopAtJunctions && !IsLinkOnGraphEdge(traversalParam.roadNetwork, link)) { return(false); } var directionNext = DetermineNewDirection(link.contactPoint); traversalState.SetNewLocation(new NativeString64(link.nodeId), 0, 0, directionNext); return(true); }
// Each non-junction road is effectively a segment of a graph edge - this function identifies which roads // belong on the same edge as the input graph edge and return the information necessary to query this edge internal static RoadGroup IdentifyGraphEdgeGroup(RoadNetworkDescription roadNetwork, TraversalState state, NativeString64 roadId) { if (roadNetwork.GetRoadById(roadId).junction != "-1") { throw new ArgumentException( "Cannot collect graph edge group for a road inside a junction - roads inside junctions" + "are part of a graph node."); } // Because we want to limit traversal to this graph edge, we will always stop at junctions (nodes) const bool stopAtJunctions = true; var param = new TraversalParameters(roadNetwork, stopAtJunctions); // Count how many Road elements are in this group, including the starting road var numRoads = 1; state.SetNewLocation(roadId, 0, 0, TraversalDirection.Backward); while (TryAdvanceOneRoad(param, state)) { numRoads++; } // We've moved all the way to the "front" of this collection of roads - store it as the starting location var startingRoadId = state.RoadId; // To get from the first Road to the second, we need to travel in the opposite direction we traversed to // reach the first Road var startDirection = (TraversalDirection)(-(int)state.Direction); // Traverse forward to ensure we mark all the roads in this group as traversed state.SetNewLocation(roadId, 0, 0, TraversalDirection.Forward); while (TryAdvanceOneRoad(param, state)) { numRoads++; } return(new RoadGroup(startDirection, startingRoadId, numRoads)); }