Пример #1
0
        /// <summary>
        /// Advance the lane to the next element
        /// </summary>
        /// <param name="curLane">Index of the lane to advance</param>
        /// <returns>True if there will still be nodes in this lane</returns>
        private int AdvanceLane(int curLane)
        {
            LaneJunctionDetail lane = _laneNodes[curLane];
            int minLane             = curLane;

            // Advance the lane
            lane.Next();

            // See if we can pull up ancestors
            if (lane.Count == 0 && lane.Junction == null)
            {
                // Handle a single node branch.
                _currentRow.Collapse(curLane);
                _laneNodes.RemoveAt(curLane);
            }
            else if (lane.Count == 0)
            {
                Node node = lane.Junction.Oldest;
                foreach (Junction parent in node.Ancestors)
                {
                    if (parent.ProcessingState != JunctionProcessingState.Unprocessed)
                    {
                        // This item is already in the lane list, no action needed
                        continue;
                    }

                    var addedLane = new LaneJunctionDetail(parent);
                    addedLane.Next();
                    int addedLaneLane = int.MaxValue;

                    // Check to see if this junction already points to one of the
                    // existing lanes. If so, we'll just add the lane line and not
                    // add it to the laneNodes.
                    if (addedLane.Count == 1)
                    {
                        for (int i = 0; i < _laneNodes.Count; i++)
                        {
                            if (_laneNodes[i].Current == addedLane.Current)
                            {
                                // We still advance the lane so it gets
                                // marked as processed.
                                addedLane.Next();

                                addedLaneLane = i;
                                break;
                            }
                        }
                    }

                    // Add to the lane nodes
                    if (addedLaneLane == int.MaxValue)
                    {
                        if (lane.Count == 0)
                        {
                            lane = addedLane;
                            _laneNodes[curLane] = lane;
                            addedLaneLane       = curLane;
                        }
                        else
                        {
                            addedLaneLane = curLane + 1;
                            _laneNodes.Insert(addedLaneLane, addedLane);
                            _currentRow.Expand(addedLaneLane);
                        }
                    }

                    _currentRow.Add(curLane, new LaneInfo(addedLaneLane, parent));
                }

                // If the lane count after processing is still 0
                // this is a root node of the graph
                if (lane.Count == 0)
                {
                    _currentRow.Collapse(curLane);
                    _laneNodes.RemoveAt(curLane);
                }
            }
            else if (lane.Count == 1)
            {
                // If any other lanes have this node on top, merge them together
                for (int i = 0; i < _laneNodes.Count; i++)
                {
                    if (i == curLane || curLane >= _laneNodes.Count)
                    {
                        continue;
                    }

                    if (_laneNodes[i].Current == _laneNodes[curLane].Current)
                    {
                        int      left;
                        int      right;
                        Junction junction = _laneNodes[curLane].Junction;
                        if (i > curLane)
                        {
                            left  = curLane;
                            right = i;
                        }
                        else
                        {
                            left    = i;
                            right   = curLane;
                            curLane = i;
                        }

                        _currentRow.Replace(right, left);
                        _currentRow.Collapse(right);
                        _laneNodes[right].Clear();
                        _laneNodes.RemoveAt(right);

                        _currentRow.Add(_currentRow.NodeLane, new LaneInfo(left, junction));
                        minLane = Math.Min(minLane, left);
                    }
                }

                // If the current lane is still active, add it. It might not be active
                // if it got merged above.
                if (!lane.IsClear)
                {
                    _currentRow.Add(_currentRow.NodeLane, new LaneInfo(curLane, lane.Junction));
                }
            }
            else
            {
                // lane.Count > 1
                _currentRow.Add(_currentRow.NodeLane, new LaneInfo(curLane, lane.Junction));
            }

            return(curLane);
        }
Пример #2
0
 public LaneJunctionDetail([NotNull] Junction j)
 {
     Junction = j;
     Junction.ProcessingState = JunctionProcessingState.Processing;
 }
Пример #3
0
 public LaneInfo(int connectLane, Junction junction)
     : this(connectLane, new List <Junction> {
     junction
 })
 {
 }