public static Coordinate Intersect(Horizontal h, Vertical v) { // h.y = 3, h.x1 = 1, h.x2 = 5 // v.x = 3, v.y1 = 1, v.y2 = 5 //Console.WriteLine(h.ToString()); //Console.WriteLine(v.ToString()); if ((v.y1 <= h.y) && (h.y <= v.y2) && (h.x1 <= v.x) && (v.x <= h.x2)) { //Console.WriteLine(string.Format("{0} | {1}", h, v)); return(new Coordinate() { x = v.x, y = h.y }); } else { return(null); } }
static List <Intersect> GetIntersections(List <LineBase> lineSet1, List <LineBase> lineSet2) { List <Intersect> intersects = new List <Intersect>(); foreach (var p1 in lineSet1) { foreach (var p2 in lineSet2) { Horizontal h = (p1 is Horizontal)?(Horizontal)p1:(Horizontal)p2; Vertical v = (p1 is Vertical)?(Vertical)p1:(Vertical)p2; Coordinate c = LineMath.Intersect(h, v); if (c != null && !(c.x == 0 && c.y == 0)) { var intersect = new Intersect() { coordinate = c, line1 = p1, line2 = p2 }; intersects.Add(intersect); Console.WriteLine(string.Format("Found {0},{1} distance {4} {2} {3}", c.x, c.y, p1, p2, intersect.distance)); } } } return(intersects); }