Beispiel #1
0
        private static void h3Distance_kRing_assertions(H3Index h3)
        {
            int r = H3Index.H3_GET_RESOLUTION(h3);

            Assert.True(r <= 5, "resolution supported by test function (kRing)");
            int maxK = MAX_DISTANCES[r];

            int sz        = Algos.maxKringSize(maxK);
            var neighbors = new H3Index[sz].ToList();
            var distances = new int[sz].ToList();

            Algos.kRingDistances(h3, maxK, ref neighbors, ref distances);

            for (int i = 0; i < sz; i++)
            {
                if (neighbors[i] == 0)
                {
                    continue;
                }

                int calculatedDistance = LocalIJ.h3Distance(h3, neighbors[i]);

                // Don't consider indexes where h3Distance reports failure to
                // generate
                Assert.True(calculatedDistance == distances[i] || calculatedDistance == -1,
                            "kRingDistances matches h3Distance");
            }
        }
Beispiel #2
0
        public void testIndexDistance()
        {
            H3Index bc = 0;

            H3Index.setH3Index(ref bc, 1, 17, (Direction)0);
            H3Index p = 0;

            H3Index.setH3Index(ref p, 1, 14, (Direction)0);
            H3Index p2 = 0;

            H3Index.setH3Index(ref p2, 1, 14, (Direction)2);
            H3Index p3 = 0;

            H3Index.setH3Index(ref p3, 1, 14, (Direction)3);
            H3Index p4 = 0;

            H3Index.setH3Index(ref p4, 1, 14, (Direction)4);
            H3Index p5 = 0;

            H3Index.setH3Index(ref p5, 1, 14, (Direction)5);
            H3Index p6 = 0;

            H3Index.setH3Index(ref p6, 1, 14, (Direction)6);

            Assert.True(LocalIJ.h3Distance(bc, p) == 3, "distance onto pentagon");
            Assert.True(LocalIJ.h3Distance(bc, p2) == 2, "distance onto p2");
            Assert.True(LocalIJ.h3Distance(bc, p3) == 3, "distance onto p3");
            // TODO works correctly but is rejected due to possible pentagon
            // distortion.
            //    t_assert(H3_EXPORT(h3Distance)(bc, p4) == 3, "distance onto p4");
            //    t_assert(H3_EXPORT(h3Distance)(bc, p5) == 4, "distance onto p5");
            Assert.True(LocalIJ.h3Distance(bc, p6) == 2, "distance onto p6");
        }
Beispiel #3
0
 public void h3DistanceBaseCells()
 {
     Assert.True(LocalIJ.h3Distance(bc1, pent1) == 1,
                 "distance to neighbor is 1 (15, 4)");
     Assert.True(LocalIJ.h3Distance(bc1, bc2) == 1,
                 "distance to neighbor is 1 (15, 8)");
     Assert.True(LocalIJ.h3Distance(bc1, bc3) == 1,
                 "distance to neighbor is 1 (15, 31)");
     Assert.True(LocalIJ.h3Distance(pent1, bc3) == -1,
                 "distance to neighbor is invalid");
 }
Beispiel #4
0
        public void testIndexDistance2()
        {
            H3Index origin = 0x820c4ffffffffffL;
            // Destination is on the other side of the pentagon
            H3Index destination = 0x821ce7fffffffffL;

            // TODO doesn't work because of pentagon distortion. Both should be 5.
            Assert.True(LocalIJ.h3Distance(destination, origin) == -1,
                        "distance in res 2 across pentagon");
            Assert.True(LocalIJ.h3Distance(origin, destination) == -1,
                        "distance in res 2 across pentagon (reversed)");
        }
Beispiel #5
0
        public void h3DistanceEdge()
        {
            H3Index origin = 0x832830fffffffffL;
            H3Index dest   = 0x832834fffffffffL;
            H3Index edge   = H3UniEdge.getH3UnidirectionalEdge(origin, dest);

            Assert.True(0 != edge, "test edge is valid");
            Assert.True(LocalIJ.h3Distance(edge, origin) == 0,
                        "edge has zero distance to origin");
            Assert.True(LocalIJ.h3Distance(origin, edge) == 0,
                        "origin has zero distance to edge");

            Assert.True(LocalIJ.h3Distance(edge, dest) == 1,
                        "edge has distance to destination");
            Assert.True(LocalIJ.h3Distance(edge, dest) == 1,
                        "destination has distance to edge");
        }
Beispiel #6
0
 public static int H3Distance(Code.H3Index origin, Code.H3Index h3)
 {
     return(LocalIJ.h3Distance(origin, h3));
 }
Beispiel #7
0
 public void h3DistanceResolutionMismatch()
 {
     Assert.True(
         LocalIJ.h3Distance(0x832830fffffffffL, 0x822837fffffffffL) == -1,
         "cannot compare at different resolutions");
 }
Beispiel #8
0
 private static void h3Distance_identity_assertions(H3Index h3)
 {
     Assert.True(LocalIJ.h3Distance(h3, h3) == 0, "distance to self is 0");
 }