Пример #1
0
        public static LineSegment restrictLineToArraySpace(Point one, Point two, long arrayspacesizex, long arrayspacesizey)
        {
            //These points are in relative array space, but can be outside of the array bounds (ie could be larger then the number of array regions, or negative.)
            //Given two points creates a line, then creates a line segment that is within the array space, along this line
            bool pointOneIsExterior = false, pointTwoIsExterior = false;

            if (one.x < 0 || one.x >= arrayspacesizex || one.y < 0 || one.y >= arrayspacesizey)
            {
                pointOneIsExterior = true;
            }

            if (two.x < 0 || two.x >= arrayspacesizex || two.y < 0 || two.y >= arrayspacesizey)
            {
                pointTwoIsExterior = true;
            }

            //Common case in which both points are interior to the domain
            if (!pointOneIsExterior && !pointTwoIsExterior)
            {
                return new LineSegment(one, two);
            }

            //At least 1 pointis exterior, we need to create a line and restrict part of it to the domain
            LineSegment givenLineSegment = new LineSegment(one, two);

            //Create 4 lines to represent to bounds of this rectangle to test intersections against

            LineSegment left = new LineSegment(new Point(0, 0), new Point(0, arrayspacesizey));
            LineSegment right = new LineSegment(new Point(arrayspacesizex, 0), new Point(arrayspacesizex, arrayspacesizey));
            LineSegment bottom = new LineSegment(new Point(0, 0), new Point(arrayspacesizex, 0));
            LineSegment top = new LineSegment(new Point(0, arrayspacesizey), new Point(arrayspacesizex, arrayspacesizey));
            Point intersectionPoint = new Point(0, 0), intersectionPointOne = new Point(0, 0), intersectionPointTwo = new Point(0, 0);
            bool intersectionPointOneFound = false;
            bool infiniteIntersections = false;
            //we need to see if a line segment exists
            if (pointOneIsExterior && pointTwoIsExterior)
            {
                //both points are exterior, check if there is an overlap of the line segment and the bounding box
                //If there exists a line segment, it will be made with a line that intersects two of the lines of the bounding rectangle

                if (givenLineSegment.intersectsLineSegment(left, ref intersectionPoint, ref infiniteIntersections))
                {

                    intersectionPointOne = intersectionPoint;
                    intersectionPointOneFound = true;
                }

                if (givenLineSegment.intersectsLineSegment(right, ref intersectionPoint, ref infiniteIntersections))
                {

                    if (intersectionPointOneFound)
                    {
                        //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                        //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                        //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                        //but be suffeciently high when evaluated as to give all the necessary boxes
                        //intersectionPoint.x -= reduceConstant;
                        intersectionPointTwo = intersectionPoint;
                        return new LineSegment(intersectionPointOne, intersectionPointTwo);
                    }
                    else
                    {
                        //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                        //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                        //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                        //but be suffeciently high when evaluated as to give all the necessary boxes
                        //intersectionPoint.x -= reduceConstant;
                        intersectionPointOne = intersectionPoint;
                        intersectionPointOneFound = true;
                    }
                }

                if (givenLineSegment.intersectsLineSegment(bottom, ref intersectionPoint, ref infiniteIntersections))
                {

                    if (intersectionPointOneFound)
                    {
                        intersectionPointTwo = intersectionPoint;
                        return new LineSegment(intersectionPointOne, intersectionPointTwo);
                    }
                    else
                    {
                        intersectionPointOne = intersectionPoint;
                        intersectionPointOneFound = true;
                    }
                }

                if (givenLineSegment.intersectsLineSegment(top, ref intersectionPoint, ref infiniteIntersections))
                {

                    if (intersectionPointOneFound)
                    {
                        //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                        //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                        //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                        //but be suffeciently high when evaluated as to give all the necessary boxes
                        //intersectionPoint.y -= reduceConstant;
                        intersectionPointTwo = intersectionPoint;

                        return new LineSegment(intersectionPointOne, intersectionPointTwo);
                    }
                    else
                    {
                        //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                        //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                        //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                        //but be suffeciently high when evaluated as to give all the necessary boxes
                        //intersectionPoint.y -= reduceConstant;
                        intersectionPointOne = intersectionPoint;
                        intersectionPointOneFound = true;
                    }
                }

                //Only other option is no intersections took place
                if (!intersectionPointOneFound)
                {
                    //No intersection found
                    return null;
                }
                else
                {
                    //One intersection found?? not possible?
                }
            }
            else if (pointOneIsExterior)
            {
                //only point one is exterior, there must be exactly one intersection point with the bounding rect, use this intersection point + point 2 for a line segment

                if (givenLineSegment.intersectsLineSegment(left, ref intersectionPoint, ref infiniteIntersections))
                {

                    return new LineSegment(intersectionPoint, two);
                }
                else if (givenLineSegment.intersectsLineSegment(right, ref intersectionPoint, ref infiniteIntersections))
                {
                    //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                    //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                    //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                    //but be suffeciently high when evaluated as to give all the necessary boxes
                    //intersectionPoint.x -= reduceConstant;
                    return new LineSegment(intersectionPoint, two);
                }
                else if (givenLineSegment.intersectsLineSegment(bottom, ref intersectionPoint, ref infiniteIntersections))
                {
                    return new LineSegment(intersectionPoint, two);
                }
                else if (givenLineSegment.intersectsLineSegment(top, ref intersectionPoint, ref infiniteIntersections))
                {
                    //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                    //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                    //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                    //but be suffeciently high when evaluated as to give all the necessary boxes
                    //intersectionPoint.y -= reduceConstant;
                    return new LineSegment(intersectionPoint, two);
                }
                else
                {
                    //Cant happen, but still need to do the last check to get the intersection point
                }

            }
            else
            {
                //Onlypoint two is exterior, there must be actaly one intersection point with the bounding rect, use this intersection point + point one for linesegment
                if (givenLineSegment.intersectsLineSegment(left, ref intersectionPoint, ref infiniteIntersections))
                {
                    return new LineSegment(intersectionPoint, one);
                }
                else if (givenLineSegment.intersectsLineSegment(right, ref intersectionPoint, ref infiniteIntersections))
                {
                    //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                    //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                    //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                    //but be suffeciently high when evaluated as to give all the necessary boxes
                    //intersectionPoint.x -= reduceConstant;
                    return new LineSegment(intersectionPoint, one);
                }
                else if (givenLineSegment.intersectsLineSegment(bottom, ref intersectionPoint, ref infiniteIntersections))
                {
                    return new LineSegment(intersectionPoint, one);
                }
                else if (givenLineSegment.intersectsLineSegment(top, ref intersectionPoint, ref infiniteIntersections))
                {
                    //The intersection point is on the end of array space, such that when evaluating it. it will be outside of the array
                    //(ex x = 40, array size = 40, but only elements 0-39 are valid)
                    //Thus reduce the size slightly such that when casted to int it will round down to the last element,
                    //but be suffeciently high when evaluated as to give all the necessary boxes
                    //intersectionPoint.y -= reduceConstant;
                    return new LineSegment(intersectionPoint, one);
                }
                else
                {
                    //Cant happen, but still need to do the last check/functioncall to get the intersection point
                }
            }

            return null;
        }
Пример #2
0
        public void intersectsLineSegmentTest()
        {
            //Normal line segment intersection
            Point one = new Point(0, 0);
            Point two = new Point(1, 1);
            Point one2 = new Point(0, 1);
            Point two2 = new Point(1, 0);

            LineSegment target = new LineSegment(one, two);
            LineSegment target2 = new LineSegment(one2, two2);

            Point intersectionpoint = null;
            Point intersectionpointExpected = new Point(.5, .5);
            bool infiniteIntersections = false, expectedInfiniteIntersections = false;
            bool intersectionExpected = true;
            bool linesActualIntersection;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting at both end points
            one = new Point(-1, -1);
            two = new Point(0, 0);
            one2 = new Point(0, 0);
            two2 = new Point(2, 1);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting at one end point
            one = new Point(-1, 1);
            two = new Point(1, -1);
            one2 = new Point(1, 1);
            two2 = new Point(0, 0);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting line to horizontal
            one = new Point(0, 0);
            two = new Point(1, 1);
            one2 = new Point(-10, 0.5);
            two2 = new Point(10, 0.5);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0.5, 0.5);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting line to horizontal end point
            one = new Point(0, 0);
            two = new Point(1, 1);
            one2 = new Point(.5, 0.5);
            two2 = new Point(10, 0.5);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0.5, 0.5);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting line end point to horizontal
            one = new Point(0, 0);
            two = new Point(1, 1);
            one2 = new Point(-10, 0);
            two2 = new Point(10, 0);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting line end point to horizontal end point
            one = new Point(0, 0);
            two = new Point(1, 1);
            one2 = new Point(0, 0);
            two2 = new Point(10, 0);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment to line end point
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(1, 1.5);
            two2 = new Point(0, 0.5);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.5);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment to line
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(-1, 0);
            two2 = new Point(1, 1);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.5);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment end point to line
            one = new Point(0.0, 0.0);
            two = new Point(0.0, 1.0);
            one2 = new Point(-1.0, -.5);
            two2 = new Point(1.0, 0.5);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment end to line end
            one = new Point(0, 0);
            two = new Point(1, 1);
            one2 = new Point(1, 1);
            two2 = new Point(1, 3);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(1.0, 1.0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment to horizontal
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(1, .6);
            two2 = new Point(-1, .6);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.6);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment to horizontal end
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(1, .6);
            two2 = new Point(0, .6);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.6);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment end to horizontal
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(1, 1);
            two2 = new Point(-1, 1);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 1);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment end to horizontal end
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(1, 1);
            two2 = new Point(0, 1);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 1);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting vertical segment to vertical segment
            one = new Point(0, 0);
            two = new Point(0, 1);
            one2 = new Point(0, 0);
            two2 = new Point(0, -6);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 0.0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);

            //Connecting horizontal segment to horizontal segment
            one = new Point(0, 5);
            two = new Point(3, 5);
            one2 = new Point(-1, 5);
            two2 = new Point(0, 5);

            target = new LineSegment(one, two);
            target2 = new LineSegment(one2, two2);

            expectedInfiniteIntersections = false;
            intersectionpointExpected = new Point(0, 5.0);
            intersectionExpected = true;
            linesActualIntersection = target.intersectsLineSegment(target2, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
            linesActualIntersection = target2.intersectsLineSegment(target, ref intersectionpoint, ref infiniteIntersections);
            Assert.AreEqual(intersectionpointExpected.x, intersectionpoint.x);
            Assert.AreEqual(intersectionpointExpected.y, intersectionpoint.y);
            Assert.AreEqual(intersectionExpected, linesActualIntersection);
            Assert.AreEqual(expectedInfiniteIntersections, infiniteIntersections);
        }