示例#1
0
        public void normalizeMultiPolygonTwoHoles()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0, 0),
                new GeoCoord(0, 0.4),
                new GeoCoord(0.4, 0.4),
                new GeoCoord(0.4, 0)
            };

            LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer);
            createLinkedLoop(ref outer, verts, 4);

            List <GeoCoord> verts2 =
                new List <GeoCoord>
            {
                new GeoCoord(0.1, 0.1),
                new GeoCoord(0.2, 0.2),
                new GeoCoord(0.1, 0.2)
            };

            LinkedGeo.LinkedGeoLoop inner1 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(inner1);
            createLinkedLoop(ref inner1, verts2, 3);

            List <GeoCoord> verts3 =
                new List <GeoCoord>
            {
                new GeoCoord(0.2, 0.2),
                new GeoCoord(0.3, 0.3),
                new GeoCoord(0.2, 0.3)
            };

            LinkedGeo.LinkedGeoLoop inner2 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(inner2);
            createLinkedLoop(ref inner2, verts3, 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref inner2);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer);
            LinkedGeo.addLinkedLoop(ref polygon, ref inner1);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned");

            Assert.True
            (
                LinkedGeo.countLinkedPolygons(ref polygon) == 1,
                "Polygon count correct for 2 holes"
            );
            Assert.True(polygon.first == outer, "Got expected outer loop");
            Assert.True
            (
                LinkedGeo.countLinkedLoops(ref polygon) == 3,
                "Loop count on first polygon correct"
            );
        }
示例#2
0
        public void normalizeMultiPolygonSingle()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0, 0),
                new GeoCoord(0, 1),
                new GeoCoord(1, 1)
            };

            LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop();
            Assert.True(outer != null);
            createLinkedLoop(ref outer, verts, 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref outer);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "Loop count correct");
            Assert.True(polygon.first == outer, "Got expected loop");
        }
示例#3
0
 public static void createLinkedLoop(
     ref LinkedGeo.LinkedGeoLoop loop, List <GeoCoord> verts, int numVerts)
 {
     loop = new LinkedGeo.LinkedGeoLoop();
     for (int i = 0; i < numVerts; i++)
     {
         var vi = verts[i];
         LinkedGeo.addLinkedCoord(ref loop, ref vi);
     }
 }
示例#4
0
        public void isNotClockwiseLinkedGeoLoop()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0, 0), new GeoCoord(0, 0.4), new GeoCoord(0.4, 0.4), new GeoCoord(0.4, 0)
            };

            LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop();
            createLinkedLoop(ref loop, verts, 4);

            Assert.False(LinkedGeo.isClockwiseLinkedGeoLoop(loop),
                         "Got false for counter-clockwise loop");
        }
示例#5
0
        public void bboxFromLinkedGeoLoopNoVertices()
        {
            LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop();

            BBox expected = new BBox {
                north = 0.0, south = 0.0, east = 0.0, west = 0.0
            };

            BBox result = new BBox();

            LinkedGeo.bboxFromLinkedGeoLoop(ref loop, ref result);

            Assert.True(BBox.bboxEquals(result, expected), "Got expected bbox");
        }
示例#6
0
        public void isNotClockwiseLinkedGeoLoopTransmeridian()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0.4, Constants.M_PI - 0.1),
                new GeoCoord(-0.4, Constants.M_PI - 0.1),
                new GeoCoord(-0.4, -Constants.M_PI + 0.1),
                new GeoCoord(0.4, -Constants.M_PI + 0.1)
            };

            LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop();
            createLinkedLoop(ref loop, verts, 4);

            Assert.False(LinkedGeo.isClockwiseLinkedGeoLoop(loop),
                         "Got false for counter-clockwise transmeridian loop");
        }
示例#7
0
        public void normalizeMultiPolygonNoOuterLoops()
        {
            GeoCoord[] verts1 =
            {
                new GeoCoord(0, 0),
                new GeoCoord(1, 1),
                new GeoCoord(0, 1)
            };

            LinkedGeo.LinkedGeoLoop outer1 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer1);
            createLinkedLoop(ref outer1, verts1.ToList(), 3);

            GeoCoord[] verts2 =
            {
                new GeoCoord(2, 2),
                new GeoCoord(3, 3),
                new GeoCoord(2, 3)
            };

            LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer2);
            createLinkedLoop(ref outer2, verts2.ToList(), 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref outer1);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer2);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True
            (
                result == LinkedGeo.NORMALIZATION_ERR_UNASSIGNED_HOLES,
                "Expected error code returned"
            );

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1,
                        "Polygon count correct");
            Assert.True
            (
                LinkedGeo.countLinkedLoops(ref polygon) == 0,
                "Loop count as expected with invalid input"
            );
        }
示例#8
0
        public void normalizeMultiPolygonAlreadyNormalized()
        {
            GeoCoord[] verts1 =
            {
                new GeoCoord(0, 0),
                new GeoCoord(0, 1),
                new GeoCoord(1, 1)
            };

            LinkedGeo.LinkedGeoLoop outer1 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer1);
            createLinkedLoop(ref outer1, verts1.ToList(), 3);

            GeoCoord[] verts2 =
            {
                new GeoCoord(2, 2),
                new GeoCoord(2, 3),
                new GeoCoord(3, 3)
            };

            LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer2);
            createLinkedLoop(ref outer2, verts2.ToList(), 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref outer1);
            LinkedGeo.LinkedGeoPolygon next = LinkedGeo.addNewLinkedPolygon(ref polygon);
            LinkedGeo.addLinkedLoop(ref next, ref outer2);

            // Should be a no-op
            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_ERR_MULTIPLE_POLYGONS,
                        "Expected error code returned");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1,
                        "Loop count on first polygon correct");
            Assert.True(polygon.first == outer1, "Got expected outer loop");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 1,
                        "Loop count on second polygon correct");
            Assert.True(polygon.next.first == outer2, "Got expected outer loop");
        }
示例#9
0
        public void isClockwiseLinkedGeoLoop()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0.1, 0.1),
                new GeoCoord(0.2, 0.2),
                new GeoCoord(0.1, 0.2)
            };

            LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop();
            createLinkedLoop(ref loop, verts, 3);

            Assert.True
            (
                LinkedGeo.isClockwiseLinkedGeoLoop(loop),
                "Got true for clockwise loop"
            );
        }
示例#10
0
        public void pointInsideLinkedGeoLoop()
        {
            GeoCoord somewhere = new GeoCoord(1, 2);
            GeoCoord inside    = new GeoCoord(0.659, -2.136);

            LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop();
            createLinkedLoop(ref loop, sfVerts, 6);

            BBox bbox = new BBox();

            LinkedGeo.bboxFromLinkedGeoLoop(ref loop, ref bbox);

            Assert.True(LinkedGeo.pointInsideLinkedGeoLoop(ref loop, ref bbox, ref inside),
                        "contains exact4");
            Assert.True(!LinkedGeo.pointInsideLinkedGeoLoop(ref loop, ref bbox, ref somewhere),
                        "contains somewhere else");

            LinkedGeo.destroyLinkedGeoLoop(ref loop);
        }
示例#11
0
        public void normalizeMultiPolygonTwoOuterLoops()
        {
            List <GeoCoord> verts1 =
                new List <GeoCoord>
            {
                new GeoCoord(0, 0), new GeoCoord(0, 1), new GeoCoord(1, 1)
            };

            LinkedGeo.LinkedGeoLoop outer1 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer1);
            createLinkedLoop(ref outer1, verts1, 3);

            List <GeoCoord> verts2 =
                new List <GeoCoord>
            {
                new GeoCoord(2, 2), new GeoCoord(2, 3), new GeoCoord(3, 3)
            };

            LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer2);
            createLinkedLoop(ref outer2, verts2, 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref outer1);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer2);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct");
            Assert.True
            (
                LinkedGeo.countLinkedLoops(ref polygon) == 1,
                "Loop count on first polygon correct"
            );
            Assert.True
            (
                LinkedGeo.countLinkedLoops(ref polygon.next) == 1,
                "Loop count on second polygon correct"
            );
        }
示例#12
0
        public void bboxFromLinkedGeoLoop()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0.8, 0.3),
                new GeoCoord(0.7, 0.6),
                new GeoCoord(1.1, 0.7),
                new GeoCoord(1.0, 0.2)
            };

            LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop();
            createLinkedLoop(ref loop, verts, 4);

            BBox expected = new BBox {
                north = 1.1, south = 0.7, east = 0.7, west = 0.2
            };

            BBox result = new BBox();

            LinkedGeo.bboxFromLinkedGeoLoop(ref loop, ref result);
            Assert.True(BBox.bboxEquals(result, expected), "Got expected bbox");
        }
示例#13
0
        public void normalizeMultiPolygonOneHole()
        {
            List <GeoCoord> verts =
                new List <GeoCoord>
            {
                new GeoCoord(0, 0), new GeoCoord(0, 3),
                new GeoCoord(3, 3), new GeoCoord(3, 0)
            };

            LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer);
            createLinkedLoop(ref outer, verts, 4);

            List <GeoCoord> verts2 =
                new List <GeoCoord>
            {
                new GeoCoord(1, 1), new GeoCoord(2, 2), new GeoCoord(1, 2)
            };

            LinkedGeo.LinkedGeoLoop inner = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(inner);
            createLinkedLoop(ref inner, verts2, 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref inner);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2,
                        "Loop count on first polygon correct");
            Assert.True(polygon.first == outer, "Got expected outer loop");
            Assert.True(polygon.first.next == inner, "Got expected inner loop");
        }
示例#14
0
        public void createLinkedGeo()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.LinkedGeoLoop    loop    = new LinkedGeo.LinkedGeoLoop();
            LinkedGeo.LinkedGeoCoord   coord   = new LinkedGeo.LinkedGeoCoord();

            loop = LinkedGeo.addNewLinkedLoop(ref polygon);
            Assert.True(loop != null, "Loop created");
            coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex1);
            Assert.True(coord != null, "Coord created");
            coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex2);
            Assert.True(coord != null, "Coord created");
            coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex3);
            Assert.True(coord != null, "Coord created");

            loop = LinkedGeo.addNewLinkedLoop(ref polygon);
            Assert.True(loop != null, "Loop createed");
            coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex2);
            Assert.True(coord != null, "Coord created");
            coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex4);
            Assert.True(coord != null, "Coord created");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count correct");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 3,
                        "Coord count 1 correct");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.last) == 2,
                        "Coord count 2 correct");

            LinkedGeo.LinkedGeoPolygon nextPolygon = LinkedGeo.addNewLinkedPolygon(ref polygon);
            Assert.True(nextPolygon != null, "polygon created");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
            polygon = null;
        }
示例#15
0
        public void normalizeMultiPolygonNestedDonuts()
        {
            GeoCoord[] verts =
            {
                new GeoCoord(0.2,   0.2),
                new GeoCoord(0.2,  -0.2),
                new GeoCoord(-0.2, -0.2),
                new GeoCoord(-0.2, 0.2)
            };
            LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer);
            createLinkedLoop(ref outer, verts.ToList(), 4);

            GeoCoord[] verts2 =
            {
                new GeoCoord(0.1,   0.1),
                new GeoCoord(-0.1,  0.1),
                new GeoCoord(-0.1, -0.1),
                new GeoCoord(0.1, -0.1)
            };
            LinkedGeo.LinkedGeoLoop inner = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(inner);
            createLinkedLoop(ref inner, verts2.ToList(), 4);

            GeoCoord[] verts3 =
            {
                new GeoCoord(0.6,   0.6),
                new GeoCoord(0.6,  -0.6),
                new GeoCoord(-0.6, -0.6),
                new GeoCoord(-0.6, 0.6)
            };
            LinkedGeo.LinkedGeoLoop outerBig = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outerBig);
            createLinkedLoop(ref outerBig, verts3.ToList(), 4);

            GeoCoord[] verts4 =
            {
                new GeoCoord(0.5,   0.5),
                new GeoCoord(-0.5,  0.5),
                new GeoCoord(-0.5, -0.5),
                new GeoCoord(0.5, -0.5)
            };
            LinkedGeo.LinkedGeoLoop innerBig = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(innerBig);
            createLinkedLoop(ref innerBig, verts4.ToList(), 4);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref inner);
            LinkedGeo.addLinkedLoop(ref polygon, ref outerBig);
            LinkedGeo.addLinkedLoop(ref polygon, ref innerBig);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2,
                        "Loop count on first polygon correct");
            Assert.True(polygon.first == outerBig, "Got expected outer loop");
            Assert.True(polygon.first.next == innerBig, "Got expected inner loop");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2,
                        "Loop count on second polygon correct");
            Assert.True(polygon.next.first == outer, "Got expected outer loop");
            Assert.True(polygon.next.first.next == inner, "Got expected inner loop");
        }
示例#16
0
        public void normalizeMultiPolygonTwoDonuts()
        {
            GeoCoord[] verts =
            {
                new GeoCoord(0, 0),
                new GeoCoord(0, 3),
                new GeoCoord(3, 3),
                new GeoCoord(3, 0)
            };
            LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer);
            createLinkedLoop(ref outer, verts.ToList(), 4);

            GeoCoord[] verts2 =
            {
                new GeoCoord(1, 1),
                new GeoCoord(2, 2),
                new GeoCoord(1, 2)
            };
            LinkedGeo.LinkedGeoLoop inner = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(inner);
            createLinkedLoop(ref inner, verts2.ToList(), 3);

            GeoCoord[] verts3 =
            {
                new GeoCoord(0,   0),
                new GeoCoord(0,  -3),
                new GeoCoord(-3, -3),
                new GeoCoord(-3, 0)
            };
            LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(outer2);
            createLinkedLoop(ref outer2, verts3.ToList(), 4);

            GeoCoord[] verts4 =
            {
                new GeoCoord(-1, -1),
                new GeoCoord(-2, -2),
                new GeoCoord(-1, -2)
            };
            LinkedGeo.LinkedGeoLoop inner2 = new LinkedGeo.LinkedGeoLoop();
            Assert.NotNull(inner2);
            createLinkedLoop(ref inner2, verts4.ToList(), 3);

            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            LinkedGeo.addLinkedLoop(ref polygon, ref inner2);
            LinkedGeo.addLinkedLoop(ref polygon, ref inner);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer);
            LinkedGeo.addLinkedLoop(ref polygon, ref outer2);

            int result = LinkedGeo.normalizeMultiPolygon(ref polygon);

            Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned");

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct");
            Assert.True
            (
                LinkedGeo.countLinkedLoops(ref polygon) == 2,
                "Loop count on first polygon correct"
            );
            Assert.True
            (
                LinkedGeo.countLinkedCoords(ref polygon.first) == 4,
                "Got expected outer loop"
            );
            Assert.True
            (
                LinkedGeo.countLinkedCoords(ref polygon.first.next) == 3,
                "Got expected inner loop"
            );
            Assert.True
            (
                LinkedGeo.countLinkedLoops(ref polygon.next) == 2,
                "Loop count on second polygon correct"
            );
            Assert.True
            (
                LinkedGeo.countLinkedCoords(ref polygon.next.first) == 4,
                "Got expected outer loop"
            );
            Assert.True
            (
                LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 3,
                "Got expected inner loop"
            );
        }