Example #1
0
        public void nestedDonut()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            // hollow 1-ring + hollow 3-ring around the same hex
            List <H3Index> set = new List <H3Index> {
                0x89283082813ffff, 0x8928308281bffff, 0x8928308280bffff,
                0x8928308280fffff, 0x89283082807ffff, 0x89283082817ffff,
                0x8928308289bffff, 0x892830828d7ffff, 0x892830828c3ffff,
                0x892830828cbffff, 0x89283082853ffff, 0x89283082843ffff,
                0x8928308284fffff, 0x8928308287bffff, 0x89283082863ffff,
                0x89283082867ffff, 0x8928308282bffff, 0x89283082823ffff,
                0x89283082837ffff, 0x892830828afffff, 0x892830828a3ffff,
                0x892830828b3ffff, 0x89283082887ffff, 0x89283082883ffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            // Note that the polygon order here is arbitrary, making this test
            // somewhat brittle, but it's difficult to assert correctness otherwise
            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2,
                        "Loop count on first polygon correct");

            //  Brittleness comes from hashing into buckets, so let's cover both bases.
            if (LinkedGeo.countLinkedCoords(ref polygon.first) == 42)
            {
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 42,
                            "Got expected big outer loop");
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 30,
                            "Got expected big inner loop");
                Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2,
                            "Loop count on second polygon correct");
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 18,
                            "Got expected outer loop");
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 6,
                            "Got expected inner loop");
            }
            else
            {
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 18,
                            "Got expected big outer loop");
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 6,
                            "Got expected big inner loop");
                Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2,
                            "Loop count on second polygon correct");
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 42,
                            "Got expected outer loop");
                Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 30,
                            "Got expected inner loop");
            }

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #2
0
        public void contiguous2()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            List <H3Index>             set     = new List <H3Index> {
                0x8928308291bffff, 0x89283082957ffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "1 loop added to polygon");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 10,
                        "All coords added to loop except 2 shared");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #3
0
        public void singleHex()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            List <H3Index>             set     = new List <H3Index> {
                0x890dab6220bffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "1 loop added to polygon");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 6,
                        "6 coords added to loop");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #4
0
        public void     pentagon()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            List <H3Index>             set     = new List <H3Index> {
                0x851c0003fffffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "1 loop added to polygon");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 10,
                        "10 coords (distorted pentagon) added to loop");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #5
0
        public void hole()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            List <H3Index>             set     = new List <H3Index> {
                0x892830828c7ffff, 0x892830828d7ffff,
                0x8928308289bffff, 0x89283082813ffff,
                0x8928308288fffff, 0x89283082883ffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "2 loops added to polygon");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 6 * 3,
                        "All outer coords added to first loop");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 6,
                        "All inner coords added to second loop");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #6
0
        public void nonContiguous2()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            List <H3Index>             set     = new List <H3Index> {
                0x8928308291bffff, 0x89283082943ffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "2 polygons added");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "1 loop on the first polygon");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 6,
                        "All coords for one hex added to first loop");
            Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 1,
                        "Loop count on second polygon correct");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 6,
                        "All coords for one hex added to second polygon");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #7
0
        public void test2Ring()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            // 2-ring, in order returned by k-ring algo
            List <H3Index> set = new List <H3Index> {
                0x8930062838bffff, 0x8930062838fffff, 0x89300628383ffff,
                0x8930062839bffff, 0x893006283d7ffff, 0x893006283c7ffff,
                0x89300628313ffff, 0x89300628317ffff, 0x893006283bbffff,
                0x89300628387ffff, 0x89300628397ffff, 0x89300628393ffff,
                0x89300628067ffff, 0x8930062806fffff, 0x893006283d3ffff,
                0x893006283c3ffff, 0x893006283cfffff, 0x8930062831bffff,
                0x89300628303ffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "1 loop added to polygon");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == (6 * (2 * 2 + 1)),
                        "Expected number of coords added to loop");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #8
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;
        }
Example #9
0
        public void nestedDonutTransmeridian()
        {
            LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon();
            // hollow 1-ring + hollow 3-ring around the hex at (0, -180)
            List <H3Index> set = new List <H3Index> {
                0x897eb5722c7ffff, 0x897eb5722cfffff, 0x897eb572257ffff,
                0x897eb57220bffff, 0x897eb572203ffff, 0x897eb572213ffff,
                0x897eb57266fffff, 0x897eb5722d3ffff, 0x897eb5722dbffff,
                0x897eb573537ffff, 0x897eb573527ffff, 0x897eb57225bffff,
                0x897eb57224bffff, 0x897eb57224fffff, 0x897eb57227bffff,
                0x897eb572263ffff, 0x897eb572277ffff, 0x897eb57223bffff,
                0x897eb572233ffff, 0x897eb5722abffff, 0x897eb5722bbffff,
                0x897eb572287ffff, 0x897eb572283ffff, 0x897eb57229bffff
            };
            int numHexes = set.Count;

            Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon);

            // Note that the polygon order here is arbitrary, making this test
            // somewhat brittle, but it's difficult to assert correctness otherwise
            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) == 18,
                        "Got expected outer loop");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 6,
                        "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) == 42,
                        "Got expected big outer loop");
            Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 30,
                        "Got expected big inner loop");

            LinkedGeo.destroyLinkedPolygon(ref polygon);
        }
Example #10
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"
            );
        }