// // Add to the list of intersections only if the intersection point is not already in the list (avoids duplicates due to endpoints). // We have as many as 4 intersections since a segment may intersect the endpoint of twe connections. // This prevents against 4 intersections, ensure 2 intersections only. // private void AddIntersection(List <IntersectionAgg> intersections, IntersectionAgg newAgg) { // // Favor an intersection that intersects twice over an intersection that intersects once. // int index1 = IntersectionIndex(intersections, newAgg.intersection1); int index2 = IntersectionIndex(intersections, newAgg.intersection2); // Not found, so add this new intersection. if (index1 == -1 && index2 == -1) { intersections.Add(newAgg); return; } IntersectionAgg agg1 = index1 != -1 ? intersections[index1] : null; IntersectionAgg agg2 = index2 != -1 ? intersections[index2] : null; // This, by default, means newAgg has 2 intersections. if (index1 != -1 && index2 != -1) { intersections.Remove(agg1); intersections.Remove(agg2); intersections.Add(newAgg); return; } // Favor two intersections, if applicable. if (index1 != -1 && index2 == -1) { // Two intersections favored. if (newAgg.intersection1 != null && newAgg.intersection2 != null) { intersections.Remove(agg1); intersections.Add(newAgg); } else { // We already have 1 intersection. } return; } // Two intersections implied. if (index1 == -1 && index2 != -1) { intersections.Remove(agg2); intersections.Add(newAgg); return; } }
private List <IntersectionAgg> GetIntersections(AtomicRegion thatAtom) { List <IntersectionAgg> intersections = new List <IntersectionAgg>(); foreach (Connection thisConn in this.connections) { foreach (Connection thatConn in thatAtom.connections) { Point inter1 = null; Point inter2 = null; thisConn.FindIntersection(thatConn, out inter1, out inter2); if (thisConn.Overlap(thatConn)) { IntersectionAgg newAgg = new IntersectionAgg(); newAgg.thisConn = thisConn; newAgg.thatConn = thatConn; newAgg.intersection1 = null; newAgg.intersection2 = null; newAgg.overlap = true; AddIntersection(intersections, newAgg); } else if (inter1 != null) { IntersectionAgg newAgg = new IntersectionAgg(); newAgg.thisConn = thisConn; newAgg.thatConn = thatConn; newAgg.intersection1 = inter1; newAgg.intersection2 = inter2; newAgg.overlap = thisConn.Overlap(thatConn); AddIntersection(intersections, newAgg); } } } return(intersections); }
private List<IntersectionAgg> GetIntersections(AtomicRegion thatAtom) { List<IntersectionAgg> intersections = new List<IntersectionAgg>(); foreach (Connection thisConn in this.connections) { foreach (Connection thatConn in thatAtom.connections) { Point inter1 = null; Point inter2 = null; thisConn.FindIntersection(thatConn, out inter1, out inter2); if (thisConn.Overlap(thatConn)) { IntersectionAgg newAgg = new IntersectionAgg(); newAgg.thisConn = thisConn; newAgg.thatConn = thatConn; newAgg.intersection1 = null; newAgg.intersection2 = null; newAgg.overlap = true; AddIntersection(intersections, newAgg); } else if (inter1 != null) { IntersectionAgg newAgg = new IntersectionAgg(); newAgg.thisConn = thisConn; newAgg.thatConn = thatConn; newAgg.intersection1 = inter1; newAgg.intersection2 = inter2; newAgg.overlap = thisConn.Overlap(thatConn); AddIntersection(intersections, newAgg); } } } return intersections; }
// // Add to the list of intersections only if the intersection point is not already in the list (avoids duplicates due to endpoints). // We have as many as 4 intersections since a segment may intersect the endpoint of twe connections. // This prevents against 4 intersections, ensure 2 intersections only. // private void AddIntersection(List<IntersectionAgg> intersections, IntersectionAgg newAgg) { // // Favor an intersection that intersects twice over an intersection that intersects once. // int index1 = IntersectionIndex(intersections, newAgg.intersection1); int index2 = IntersectionIndex(intersections, newAgg.intersection2); // Not found, so add this new intersection. if (index1 == -1 && index2 == -1) { intersections.Add(newAgg); return; } IntersectionAgg agg1 = index1 != -1 ? intersections[index1] : null; IntersectionAgg agg2 = index2 != -1 ? intersections[index2] : null; // This, by default, means newAgg has 2 intersections. if (index1 != -1 && index2 != -1) { intersections.Remove(agg1); intersections.Remove(agg2); intersections.Add(newAgg); return; } // Favor two intersections, if applicable. if (index1 != -1 && index2 == -1) { // Two intersections favored. if (newAgg.intersection1 != null && newAgg.intersection2 != null) { intersections.Remove(agg1); intersections.Add(newAgg); } else { // We already have 1 intersection. } return; } // Two intersections implied. if (index1 == -1 && index2 != -1) { intersections.Remove(agg2); intersections.Add(newAgg); return; } }