/// <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; }