예제 #1
0
        public void PolygonIntersectionWithPolygon_NoIntersection_ReturnsEmptyCollection()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(5, 0),
                new Point2D(5, 4),
                new Point2D(9, 4),
                new Point2D(9, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            CollectionAssert.IsEmpty(intersections);
        }
예제 #2
0
        public void PolygonIntersectionWithPolygon_PartlyIntersects_ReturnsPartialIntersection()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 4),
                new Point2D(2, 4),
                new Point2D(2, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(1, intersections.Count());
            CollectionAssert.AreEqual(polyB, intersections.ElementAt(0));
        }
예제 #3
0
        public void PolygonIntersectionWithPolygon_IntersectsComplete_ReturnsIntersectionEqualToPolygon()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 4),
                new Point2D(4, 4),
                new Point2D(4, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(1, intersections.Count());
            Assert.AreEqual(polyA, intersections.ElementAt(0));
        }
예제 #4
0
        public void PolygonIntersectionWithPolygon_WithSelfIntersectingPolygon_ThrowsInvalidPolygonException()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(4, 0),
                new Point2D(4, 4),
                new Point2D(6, 0),
                new Point2D(8, 4),
                new Point2D(8, 0)
            };

            // Call
            void Call() => AdvancedMath2D.PolygonIntersectionWithPolygon(polyB, polyA);

            // Assert
            Assert.Throws <InvalidPolygonException>(Call);
        }
예제 #5
0
        public void PolygonIntersectionWithPolygon_IntersectsPolygonLineAndPoint_ReturnsTwoIntersections()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(0, -2),
                new Point2D(0, 5),
                new Point2D(0.5, 5),
                new Point2D(0.5, -1),
                new Point2D(1.0, 0),
                new Point2D(1.5, 0),
                new Point2D(2.0, -1),
                new Point2D(3.0, 0),
                new Point2D(4.0, -2)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(3, intersections.Count());
            CollectionAssert.AreEqual(new[]
            {
                new Point2D(3.0, 0.0)
            }, intersections.ElementAt(0));
            CollectionAssert.AreEqual(new[]
            {
                new Point2D(1.5, 0.0),
                new Point2D(1.0, 0.0)
            }, intersections.ElementAt(1));
            CollectionAssert.AreEqual(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(0.0, 4.0),
                new Point2D(0.5, 4.0),
                new Point2D(0.5, 0.0)
            }, intersections.ElementAt(2));
        }
예제 #6
0
        public void PolygonIntersectionWithPolygon_PartiallyIntersectsTwice_ReturnsTwoIntersections()
        {
            // Setup
            Point2D[] polyA = CreateBasePolygon();

            var polyB = new[]
            {
                new Point2D(2, 0),
                new Point2D(2, 1),
                new Point2D(5, 1),
                new Point2D(5, 3),
                new Point2D(2, 3),
                new Point2D(2, 4),
                new Point2D(6, 4),
                new Point2D(6, 0)
            };

            // Call
            IEnumerable <IEnumerable <Point2D> > intersections = AdvancedMath2D.PolygonIntersectionWithPolygon(polyA, polyB);

            // Assert
            Assert.AreEqual(2, intersections.Count());
            CollectionAssert.AreEqual(new[]
            {
                new Point2D(2, 4),
                new Point2D(4, 4),
                new Point2D(4, 3),
                new Point2D(2, 3)
            }, intersections.ElementAt(0));
            CollectionAssert.AreEqual(new[]
            {
                new Point2D(4, 1),
                new Point2D(4, 0),
                new Point2D(2, 0),
                new Point2D(2, 1)
            }, intersections.ElementAt(1));
        }
예제 #7
0
 private static IEnumerable <Point2D[]> GetSoilLayerWithSurfaceLineIntersection(IEnumerable <Point2D> surfaceLineGeometry, IEnumerable <Point2D> soilLayerGeometry)
 {
     return(AdvancedMath2D.PolygonIntersectionWithPolygon(surfaceLineGeometry, soilLayerGeometry).Where(arr => arr.Length > 2));
 }