/// <summary> /// Check for all waypoints who have exit interconnects that overlaps input and no stop /// </summary> /// <param name="exits"></param> /// <param name="ai"></param> /// <returns></returns> private List<IntersectionInvolved> nonStopOverlaps(IEnumerable<ITraversableWaypoint> exits, ArbiterInterconnect ai) { // list of exits that have an interconnect which overlaps the interconnect input List<IntersectionInvolved> nonStopOverlapWaypoints = new List<IntersectionInvolved>(); // get line of the interconnect Line aiLine = new Line(ai.InitialGeneric.Position, ai.FinalGeneric.Position); // loop over all exits foreach (ITraversableWaypoint exit in exits) { // make sure not our exit and the exit is not a stop and if exit and other are both waypoints then ways not the same if (!exit.Equals(ai.InitialGeneric) && !exit.IsStop && ((!(ai.InitialGeneric is ArbiterWaypoint) || !(exit is ArbiterWaypoint)) || !((ArbiterWaypoint)ai.InitialGeneric).Lane.Way.Equals(((ArbiterWaypoint)exit).Lane.Way))) { // get all interconnects of the exit foreach (ArbiterInterconnect tmp in exit.Exits) { // check relative priority that these are equal or lesser priority if (ai.ComparePriority(tmp) != -1) { // simple check if the interconnect's final is same as input final if (tmp.FinalGeneric.Equals(ai.FinalGeneric)) { // check not already added if (!nonStopOverlapWaypoints.Contains(new IntersectionInvolved(((ITraversableWaypoint)tmp.FinalGeneric).VehicleArea))) { // add exit nonStopOverlapWaypoints.Add(new IntersectionInvolved(exit, exit.VehicleArea, tmp.TurnDirection)); } } // otherwise check overlap of interconnects else { // get line of tmp interconnect Line tmpLine = new Line(tmp.InitialGeneric.Position, tmp.FinalGeneric.Position); // position of cross Coordinates intersectionPoint; // check intersection bool intersects = aiLine.Intersect(tmpLine, out intersectionPoint) && ai.IsInside(intersectionPoint); if (intersects) { // check not already added if (!nonStopOverlapWaypoints.Contains(new IntersectionInvolved(((ITraversableWaypoint)tmp.FinalGeneric).VehicleArea))) { // add exit nonStopOverlapWaypoints.Add(new IntersectionInvolved(exit, exit.VehicleArea, tmp.TurnDirection)); } } } } } } } return nonStopOverlapWaypoints; }
/// <summary> /// Get lanes that overlap with hte interconnect /// </summary> /// <param name="lanes"></param> /// <param name="ai"></param> /// <returns></returns> private List<IntersectionInvolved> laneOverlaps(List<ArbiterLane> lanes, ArbiterInterconnect ai, IEnumerable<ITraversableWaypoint> exits) { List<IntersectionInvolved> overlaps = new List<IntersectionInvolved>(); LineSegment aiSegment = new LineSegment(ai.InitialGeneric.Position, ai.FinalGeneric.Position); if (ai.FinalGeneric is ArbiterWaypoint) { ArbiterWaypoint fin = (ArbiterWaypoint)ai.FinalGeneric; if (fin.PreviousPartition != null && !this.FoundStop(fin.PreviousPartition.Initial, exits, fin.Lane)) { ArbiterWaypoint foundExit = null; foreach (ITraversableWaypoint itw in exits) { if (itw is ArbiterWaypoint && ((ArbiterWaypoint)itw).Lane.Equals(fin.Lane) && (foundExit == null || itw.Position.DistanceTo(fin.Position) < foundExit.Position.DistanceTo(fin.Position))) foundExit = (ArbiterWaypoint)itw; } if (foundExit != null) overlaps.Add(new IntersectionInvolved(foundExit, fin.Lane, ArbiterTurnDirection.Straight)); else overlaps.Add(new IntersectionInvolved(fin.Lane)); } } foreach (ArbiterLane al in lanes) { if (!(ai.InitialGeneric is ArbiterWaypoint) || !((ArbiterWaypoint)ai.InitialGeneric).Lane.Equals(al)) { foreach (LineSegment ls in al.LanePath().GetSegmentEnumerator()) { Coordinates interCoord; bool intersect = ls.Intersect(aiSegment, out interCoord); /*if (intersect) { Console.WriteLine(""); }*/ if (intersect && ai.IsInside(interCoord) && !overlaps.Contains(new IntersectionInvolved(al)) && ai.InterconnectPath.GetClosestPoint(interCoord).Location.DistanceTo(interCoord) < 0.00001 && al.IsInside(interCoord)) { // get closest partition ArbiterLanePartition alp = al.GetClosestPartition(interCoord); if (!this.FoundStop(alp.Initial, exits, al)) { ArbiterWaypoint foundExit = null; foreach (ITraversableWaypoint itw in exits) { if (itw is ArbiterWaypoint && ((ArbiterWaypoint)itw).Lane.Equals(alp.Lane) && (foundExit == null || itw.Position.DistanceTo(interCoord) < foundExit.Position.DistanceTo(interCoord))) foundExit = (ArbiterWaypoint)itw; } if (foundExit != null) overlaps.Add(new IntersectionInvolved(foundExit, alp.Lane, ArbiterTurnDirection.Straight)); else overlaps.Add(new IntersectionInvolved(al)); } } } } } return overlaps; }