Exemplo n.º 1
0
        public void h3IndexesAreNeighbors()
        {
            H3Index        sf   = H3Index.geoToH3(ref sfGeo, 9);
            List <H3Index> ring = new ulong[Algos.maxKringSize(1)].Select(cell => new H3Index(cell)).ToList();

            Algos.hexRing(sf, 1, ref ring);

            Assert.True
            (
                H3UniEdge.h3IndexesAreNeighbors(sf, sf) == 0,
                "an index does not neighbor itself"
            );

            int neighbors = 0;

            for (int i = 0; i < Algos.maxKringSize(1); i++)
            {
                if (ring[i] != 0 && H3UniEdge.h3IndexesAreNeighbors(sf, ring[i]) != 0)
                {
                    neighbors++;
                }
            }

            Assert.True
            (
                neighbors == 6,
                "got the expected number of neighbors from a k-ring of 1"
            );

            var largerRing = new ulong[Algos.maxKringSize(2)].Select(cell => new H3Index(cell)).ToList();

            Algos.hexRing(sf, 2, ref largerRing);

            neighbors = 0;
            for (int i = 0; i < Algos.maxKringSize(2); i++)
            {
                if (largerRing[i] != 0 &&
                    H3UniEdge.h3IndexesAreNeighbors(sf, largerRing[i]) != 0)
                {
                    neighbors++;
                }
            }

            Assert.True
            (
                neighbors == 0,
                "got no neighbors, as expected, from a k-ring of 2"
            );

            H3Index sfBroken = sf;

            H3Index.H3_SET_MODE(ref sfBroken, Constants.H3_UNIEDGE_MODE);
            Assert.True
            (
                H3UniEdge.h3IndexesAreNeighbors(sf, sfBroken) == 0,
                "broken H3Indexes can't be neighbors"
            );

            H3Index sfBigger = H3Index.geoToH3(ref sfGeo, 7);

            Assert.True
            (
                H3UniEdge.h3IndexesAreNeighbors(sf, sfBigger) == 0,
                "hexagons of different resolution can't be neighbors"
            );

            Assert.True
            (
                H3UniEdge.h3IndexesAreNeighbors(ring[2], ring[1]) == 1,
                "hexagons in a ring are neighbors"
            );
        }