Esempio n. 1
0
        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(2, 1);
            Point q1 = new Point(1, 0);
            Point q2 = new Point(1, 2);
            SegmentsIntersectionVerificator siv = new SegmentsIntersectionVerificator();
            bool result = siv.Verify(p1, p2, q1, q2);

            Assert.That(result, Is.EqualTo(true));
        }
        public void TestQ2OnSegmentP()
        {
            Point p1 = new Point(2, 0);
            Point p2 = new Point(2, 2);
            Point q1 = new Point(1, 0);
            Point q2 = new Point(1, 2);
            SegmentsIntersectionVerificator siv = new SegmentsIntersectionVerificator();
            bool result = siv.Verify(p1, p2, q1, q2);

            Assert.That(result, Is.EqualTo(false));
        }
        public void TestHorizontallyParallelSegments()
        {
            Point p1 = new Point(0, 0);
            Point p2 = new Point(2, 0);
            Point q1 = new Point(0, 1);
            Point q2 = new Point(2, 1);
            SegmentsIntersectionVerificator siv = new SegmentsIntersectionVerificator();
            bool result = siv.Verify(p1, p2, q1, q2);

            Assert.That(result, Is.EqualTo(false));
        }