static void Repopulate(this List <LaneData> list, LaneDataIterator it)
 {
     list.Clear();
     while (it.MoveNext())
     {
         list.Add(it.Current);
     }
 }
Example #2
0
        /// <summary>
        /// Determines if any lane from source segment goes to the target segment
        /// based on lane arrows and lane connections.
        public static bool DoesSegmentGoToSegment(ushort sourceSegmentID, ushort targetSegmentID, ushort nodeID)
        {
            bool startNode = NetUtil.IsStartNode(sourceSegmentID, nodeID);

            if (sourceSegmentID == targetSegmentID)
            {
                return(TMPE.JunctionRestrictionsManager.IsUturnAllowed(sourceSegmentID, startNode));
            }
            ArrowDirection arrowDir    = TMPE.ExtSegmentEndManager.GetDirection(sourceSegmentID, targetSegmentID, nodeID);
            LaneArrows     arrow       = ArrowDir2LaneArrows(arrowDir);
            var            sourceLanes = new LaneDataIterator(
                sourceSegmentID,
                startNode,
                TMPE.LaneArrowManager.LaneTypes,
                TMPE.LaneArrowManager.VehicleTypes);

            //Log.Debug("DoesSegmentGoToSegment: sourceLanes=" + sourceLanes.ToSTR());

            foreach (LaneData sourceLane in sourceLanes)
            {
                bool connected;
                if (TMPE.LaneConnectionManager.HasConnections(sourceLane.LaneID, startNode))
                {
                    connected = IsLaneConnectedToSegment(sourceLane.LaneID, targetSegmentID);
                    //Log.Debug($"IsLaneConnectedToSegment({sourceLane},{targetSegmentID}) = {connected}");
                }
                else
                {
                    LaneArrows arrows = TMPE.LaneArrowManager.GetFinalLaneArrows(sourceLane.LaneID);
                    connected = (arrows & arrow) != 0;
                }
                if (connected)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
        /// <summary>
        /// Determines if there is any lane connection from source lane to target segment.
        /// </summary>
        public static bool IsLaneConnectedToSegment(uint sourceLaneId, ushort targetSegmentID)
        {
            ushort sourceSegmentID = sourceLaneId.ToLane().m_segment;
            ushort nodeID          = sourceSegmentID.ToSegment().GetSharedNode(targetSegmentID);
            bool   sourceStartNode = NetUtil.IsStartNode(sourceSegmentID, nodeID);
            bool   targetStartNode = NetUtil.IsStartNode(targetSegmentID, nodeID);


            var targetLanes = new LaneDataIterator(
                targetSegmentID,
                !targetStartNode,// going away from start node.
                TMPE.LaneConnectionManager.LaneTypes,
                TMPE.LaneConnectionManager.VehicleTypes);

            foreach (LaneData targetLane in targetLanes)
            {
                if (TMPE.LaneConnectionManager.AreLanesConnected(sourceLaneId, targetLane.LaneID, sourceStartNode))
                {
                    return(true);
                }
            }
            return(false);
        }