private List <Point> GetIntersections(List <Point> wire1, List <Point> wire2) { List <Point> intersections = new List <Point>(); Point p1; Point p2; Point q1; Point q2; SegmentsIntersectionVerificator siv = new SegmentsIntersectionVerificator(); SegmentsIntersectionCalculator sic = new SegmentsIntersectionCalculator(); for (int i = 0; i < wire1.Count - 1; i++) { p1 = wire1[i]; p2 = wire1[i + 1]; for (int j = 0; j < wire2.Count - 1; j++) { q1 = wire2[j]; q2 = wire2[j + 1]; if (siv.Verify(p1, p2, q1, q2)) { intersections.Add(sic.Calculate(p1, p2, q1, q2)); } } } return(intersections); }
public void TestInterectingSegments() { Point p1 = new Point(0, 1); Point p2 = new Point(3, 1); Point q1 = new Point(2, 0); Point q2 = new Point(2, 2); SegmentsIntersectionCalculator sic = new SegmentsIntersectionCalculator(); Point result = sic.Calculate(p1, p2, q1, q2); Assert.That(result.X, Is.EqualTo(2)); Assert.That(result.Y, Is.EqualTo(1)); }