Exemple #1
0
        public void GeoPolygon_ContainsPoint()
        {
            GeoPolygon poly;

            //-----------------------------------------------------------------
            // Test a point polygon.

            poly = new GeoPolygon(new GeoCoordinate[] { new GeoCoordinate(10, 10) });
            Assert.IsTrue(poly.Contains(new GeoCoordinate(10, 10)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(10, 0)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(0, 10)));

            //-----------------------------------------------------------------
            // Test a simple rectangle

            poly = new GeoPolygon(
                new GeoCoordinate[] {
                new GeoCoordinate(45, 0),
                new GeoCoordinate(0, 0),
                new GeoCoordinate(6, 60),
                new GeoCoordinate(45, 60)
            });

            // Points inside

            Assert.IsTrue(poly.Contains(new GeoCoordinate(22.5, 30)));

            // Points outside

            Assert.IsFalse(poly.Contains(new GeoCoordinate(22.5, 61)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(-1, 61)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(-1, 30)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(0, -1)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(22.5, -1)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(46, -1)));

            //-----------------------------------------------------------------
            // Test a slanted parallelogram.

            poly = new GeoPolygon(
                new GeoCoordinate[] {
                new GeoCoordinate(45, 0),
                new GeoCoordinate(0, 45),
                new GeoCoordinate(0, 155),
                new GeoCoordinate(45, 65)
            });

            // Points inside the polygon

            Assert.IsTrue(poly.Contains(new GeoCoordinate(22.5, 60)));
            Assert.IsTrue(poly.Contains(new GeoCoordinate(1, 119)));
            Assert.IsTrue(poly.Contains(new GeoCoordinate(1, 46)));

            // Points outside the polygon but within the bounding rectangle

            Assert.IsFalse(poly.Contains(new GeoCoordinate(44, 119)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(1, 1)));

            // Points outside the bounding rectangle

            Assert.IsFalse(poly.Contains(new GeoCoordinate(46, 121)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(46, 60)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(46, -1)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(22.5, -1)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(44, 119)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(-1, -1)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(-1, 60)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(-1, 121)));
            Assert.IsFalse(poly.Contains(new GeoCoordinate(22.5, 121)));
        }