Пример #1
0
        public void FillPolygonTests3()
        {
            var polygon = new[] {
                CreatePoint(0.994356, 1.00136305698),
                CreatePoint(3.0002425, 0.99924525),
                CreatePoint(2.999235236, 2.999252346),
                CreatePoint(1.00135357, 3.001232363)
            };

            var boundingBox = FillPolygon.GetBoundingBox(polygon);

            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 1), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 1), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(3, 1), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(3, 2), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(3, 3), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 3), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 3), boundingBox));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 2), boundingBox));
        }
Пример #2
0
        public void PointInPolygonTests()
        {
            var polygon = new[] {
                CreatePoint(1, 1),
                CreatePoint(10, 1),
                CreatePoint(10, 10),
                CreatePoint(1, 10), // Non repeating last value
            };

            var bounds = FillPolygon.GetBoundingBox(polygon);

            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 5), bounds)); // On the last point pair
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(5, 10), bounds));
            Assert.AreEqual(1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(5, 5), bounds));

            polygon = new[] {
                CreatePoint(1, 1),
                CreatePoint(10, 1),
                CreatePoint(10, 10),
                CreatePoint(9, 10),
                CreatePoint(8, 10),
                CreatePoint(7, 10),
                CreatePoint(6, 10),
                CreatePoint(5, 10),
                CreatePoint(4, 10),
                CreatePoint(3, 10),
                CreatePoint(2, 10),
                CreatePoint(1, 10),
                CreatePoint(1, 9),
                CreatePoint(1, 8),
                CreatePoint(1, 7),
                CreatePoint(1, 3),
                CreatePoint(1, 2),
            };

            Assert.AreEqual(1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(5, 5)));

            polygon = new[] {
                CreatePoint(1, 1),
                CreatePoint(1, 1),
            };

            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 1)));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1.0001, 1.00001)));

            // Check all surrounding points
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(0, 0)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 0)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 0)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 1)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 2)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 2)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(0, 2)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(0, 1)));

            polygon = new[] {
                CreatePoint(1, 1),
                CreatePoint(2, 1),
                CreatePoint(2, 2),
                CreatePoint(3, 2),
                CreatePoint(4, 2),
                CreatePoint(4, 1),
                CreatePoint(5, 1),
                CreatePoint(5, 4),
                CreatePoint(3, 3),
                CreatePoint(1, 4),
                CreatePoint(1, 1),
            };

            bounds = FillPolygon.GetBoundingBox(polygon);

            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1, 1), bounds));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(3.5, 1.5), bounds));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 4), bounds));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 1), bounds));

            polygon = new[] {
                CreatePoint(1, 1),
                CreatePoint(1, 2),
                CreatePoint(2, 2),
                CreatePoint(1, 1),
            };

            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1.5, 1.5)));
            Assert.AreEqual(0, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1.6, 1.6)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(1.6, 1.5)));

            // Figure of 8
            polygon = new[] {
                CreatePoint(2, 1),
                CreatePoint(3, 2),
                CreatePoint(3, 6),
                CreatePoint(3, 6), // Double point - interesting case
                CreatePoint(5, 6),
                CreatePoint(5, 3),
                CreatePoint(2, 4),
                CreatePoint(1, 2),
                CreatePoint(2, 1),
            };

            Assert.AreEqual(1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(2, 3)));
            Assert.AreEqual(1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(4, 4)));
            Assert.AreEqual(-1, FillPolygon.PointInComplexPolygon(polygon, CreatePoint(4, 2)));
        }