public void AddTrafficLight(Road road, TrafficLight trafficlight) { if (!roadlist.Contains(road)) { roadlist.Add(road); trafficlightdictionary.Add(road, new List<TrafficLight>()); } trafficlightdictionary[road].Add(trafficlight); }
protected void setlane(Lane lane, bool changeilanecontainer) { // This methods sets a lane. This isn't accomplished by property because of intended side-effects: // Crossinglane and roadlane also get changed. We save these two to not always have to cast in case // we want to know if Vehicle is on a crossinglane or roadlane. if (this.lane == lane) return; // Remove the Vehicle from the Vehiclelist of Lane. If ChangeIlaneContainer, then also remove Vehicle from the // IlaneContainer of the Lane. if (this.lane != null) this.lane.LeaveLane(this, changeilanecontainer); crossinglane = lane as CrossingLane; this.lane = lane; roadlane = lane as RoadLane; trafficlight = roadlane == null ? null : roadlane.TrafficLight; if (this.lane != null) this.lane.EnterLane(this); }
private Crossing(PointD location, CrossingData crossingdata, params RoadConnection[] roadconnections) { cornerpoints = new PointD[2*roadconnections.Length]; lanelist = new List<CrossingLane>(); linewidth = crossingdata.LineWidth; this.location = location; roadlist = new List<Road>(); trafficlightsystem = new TrafficLightSystem(this); #region SortRoads List<RoadConnection> roadconnectionlist = roadconnections.ToList(); // Bepaal het SortingPoint van elke Road. Dit is het uiteinde van de Road dat bij de Crossing uitkomt. foreach (RoadConnection t in roadconnectionlist) t.Road.SortPoint = t.Road.GetTowardCoordinate(location); // Sorteer de Roads die op de Crossing samenkomen tegen de klik in. roadconnectionlist.Sort( (r1, r2) => Math.Atan2(r2.Road.SortPoint.Y - location.Y, r2.Road.SortPoint.X - location.X).CompareTo( Math.Atan2(r1.Road.SortPoint.Y - location.Y, r1.Road.SortPoint.X - location.X))); #endregion #region MakeCrossingLanes for (int i = 0; i < roadconnectionlist.Count; i++) { Road road = roadconnectionlist[i].Road; roadlist.Add(road); // Bepaal de hoekpunten van de Crossing bij elke Road. if (road.IsToward(location)) { cornerpoints[2*i] = road.GetLastCoordinate() + road.GetLastDirection().GetLeftHandNormal()*road.Width/2; cornerpoints[2*i + 1] = road.GetLastCoordinate() + road.GetLastDirection().GetRightHandNormal()*road.Width/2; road.SetNext(this); } else { cornerpoints[2*i] = road.GetFirstCoordinate() + road.GetFirstDirection().GetRightHandNormal()*road.Width/2; cornerpoints[2*i + 1] = road.GetFirstCoordinate() + road.GetFirstDirection().GetLeftHandNormal()*road.Width/2; road.SetPrevious(this); } Dictionary<int, HashSet<RoadLaneIndex>> connectiondictionary = roadconnectionlist[i].ConnectionDictionary; List<RoadLane> road1lanelist = roadconnectionlist[i].Road.GetTowardLanes(location); // Verbind de Lanes van de Roads met elkaar zoals beschreven in de PDF foreach (int lane1 in connectiondictionary.Keys) { var vehiclelist = new List<Vehicle>(); HashSet<RoadLaneIndex> roadlaneindexhashset = connectiondictionary[lane1]; var trafficlight = new TrafficLight(road1lanelist[lane1], road1lanelist[lane1].GetLastCoordinate()); foreach (RoadLaneIndex roadlaneindex in roadlaneindexhashset) { int road2index = (i + roadlaneindex.Road)%roadconnectionlist.Count; List<RoadLane> road2lanelist = roadconnectionlist[road2index].Road.GetOffwardLanes(location); trafficlight.AddExitLane(road2lanelist[roadlaneindex.Lane]); lanelist.Add(new CrossingLane(this, road1lanelist[lane1], road2lanelist[roadlaneindex.Lane], road1lanelist[lane1].Width, vehiclelist)); } if (road1lanelist[lane1].LaneType == LaneType.Shoulder) continue; trafficlightsystem.AddTrafficLight(road, trafficlight); road1lanelist[lane1].TrafficLight = trafficlight; } } #endregion MakeCrossingGraphicsPath(); }