/// <summary>
        /// Determines if there is any lane connection from source lane to target segment.
        /// </summary>
        public static bool IsLaneConnectedToSegment(LaneData sourceLane, ushort targetSegmentID)
        {
            ushort sourceSegmentID = sourceLane.SegmentID;
            ushort nodeID          = sourceSegmentID.ToSegment().GetSharedNode(targetSegmentID);
            bool   sourceStartNode = NetUtil.IsStartNode(sourceSegmentID, nodeID);
            bool   targetStartNode = NetUtil.IsStartNode(targetSegmentID, nodeID);
            var    targetLanes     = NetUtil.IterateLanes(
                targetSegmentID,
                !targetStartNode,// going away from start node.
                LaneConnectionManager.LANE_TYPES,
                LaneConnectionManager.VEHICLE_TYPES);

            foreach (LaneData targetLane in targetLanes)
            {
                if (LaneConnectionManager.Instance.AreLanesConnected(sourceLane.LaneID, targetLane.LaneID, sourceStartNode))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #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);
        }
Пример #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);
        }
        /// <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(JunctionRestrictionsManager.Instance.IsUturnAllowed(sourceSegmentID, startNode));
            }
            ArrowDirection arrowDir    = ExtSegmentEndManager.Instance.GetDirection(sourceSegmentID, targetSegmentID, nodeID);
            LaneArrows     arrow       = ArrowDir2LaneArrows(arrowDir);
            var            sourceLanes = NetUtil.IterateLanes(
                sourceSegmentID,
                startNode,
                LaneArrowManager.LANE_TYPES,
                LaneArrowManager.VEHICLE_TYPES);

            foreach (LaneData sourceLane in sourceLanes)
            {
                bool connected;
                if (LaneConnectionManager.Instance.HasConnections(sourceLane.LaneID, startNode))
                {
                    connected = IsLaneConnectedToSegment(sourceLane, targetSegmentID);
                    //Log.Debug($"IsLaneConnectedToSegment({sourceLane},{targetSegmentID}) = {connected}");
                }
                else
                {
                    LaneArrows arrows = LaneArrowManager.Instance.GetFinalLaneArrows(sourceLane.LaneID);
                    connected = arrows.IsFlagSet(arrow);
                }
                if (connected)
                {
                    return(true);
                }
            }
            return(false);
        }