Ejemplo n.º 1
0
        public void IjBaseCells()
        {
            H3Index origin = 0x8029fffffffffff;
            CoordIj ij     = new CoordIj(0, 0);

            (int status, var retrieved) = ij.ToH3Experimental(origin);
            Assert.AreEqual(0, status);
            Assert.AreEqual(0x8029fffffffffff, retrieved.Value);

            ij = ij.ReplaceI(1);
            (status, retrieved) = ij.ToH3Experimental(origin);
            Assert.AreEqual(0, status);
            Assert.AreEqual(0x8051fffffffffff, retrieved.Value);

            ij = ij.ReplaceI(2);
            (status, retrieved) = ij.ToH3Experimental(origin);
            Assert.AreNotEqual(0, status);

            ij = new CoordIj(0, 2);
            (status, retrieved) = ij.ToH3Experimental(origin);
            Assert.AreNotEqual(0, status);

            ij = new CoordIj(-2, -2);
            (status, retrieved) = ij.ToH3Experimental(origin);
            Assert.AreNotEqual(0, status);
        }
Ejemplo n.º 2
0
        public void OnOffPentagonSame()
        {
            //  Test that coming from the same direction outside the pentagon is handled
            //  the same as coming from the same direction inside the pentagon.
            for (var bc = 0; bc < Constants.H3.NUM_BASE_CELLS; bc++)
            {
                for (var res = 1; res <= Constants.H3.MAX_H3_RES; res++)
                {
                    // K_AXES_DIGIT is the first internal direction, and it's also
                    // invalid for pentagons, so skip to next.
                    var startDir = Direction.K_AXES_DIGIT;
                    if (bc.IsBaseCellPentagon())
                    {
                        startDir++;
                    }

                    for (var dir = startDir; dir < Direction.NUM_DIGITS; dir++)
                    {
                        var internalOrigin = new H3Index(res, bc, dir);
                        var externalOrigin = new H3Index(res, bc.GetNeighbor(dir), Direction.CENTER_DIGIT);

                        for (var testDir = startDir; testDir < Direction.NUM_DIGITS; testDir++)
                        {
                            var testIndex = new H3Index(res, bc, testDir);
                            (int internalIjFailed, var internalIj) = internalOrigin.ToLocalIjExperimental(testIndex);
                            (int externalIjFailed, var externalIj) = externalOrigin.ToLocalIjExperimental(testIndex);

                            Assert.AreEqual(externalIjFailed != 0, internalIjFailed != 0);

                            if (internalIjFailed != 0)
                            {
                                continue;
                            }

                            (int internalIjFailed2, var internalIndex) = internalIj.ToH3Experimental(internalOrigin);
                            (int externalIjFailed2, var externalIndex) = externalIj.ToH3Experimental(externalOrigin);

                            Assert.AreEqual(externalIjFailed2 != 0, internalIjFailed2 != 0);

                            if (internalIjFailed2 != 0)
                            {
                                continue;
                            }

                            Assert.AreEqual(externalIndex, internalIndex);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// hexagons neighbors in all directions, assuming no pentagons,
        /// reporting distance from origin
        /// </summary>
        public static int HexRangeDistances(H3Index origin, int k, out List <H3Index> outCells, out List <int> distances)
        {
            (int status, var values) = origin.HexRangeDistances(k);

            outCells  = new List <H3Index>();
            distances = new List <int>();
            foreach (var tuple in values)
            {
                outCells.Add(tuple.Item1);
                distances.Add(tuple.Item2);
            }

            return(status);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Number of indexes in a line connecting two indexes
 /// </summary>
 public static int H3LineSize(H3Index start, H3Index end)
 {
     return(start.LineSize(end));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns the GeoBoundary containing the coordinates of the edge
 /// </summary>
 public static void GetH3UnidirectionalEdgeBoundary(H3Index edge, out GeoBoundary gb)
 {
     gb = edge.UniEdgeToGeoBoundary();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns the origin and destination hexagons from the unidirectional
 /// edge H3Index
 /// </summary>
 public static void GetH3IndexesFromUnidirectionalEdge(H3Index edge, out (H3Index, H3Index) originDestination)
 {
     originDestination = edge.GetH3IndexesFromUniEdge();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns the origin hexagon H3Index from the unidirectional edge
 /// </summary>
 /// H3Index
 public static H3Index GetOriginH3IndexFromUnidirectionalEdge(H3Index edge)
 {
     return(edge.OriginFromUniDirectionalEdge());
 }
Ejemplo n.º 8
0
 /// <summary>
 /// returns the unidirectional edge H3Index for the specified origin and
 /// destination
 /// </summary>
 public static H3Index GetH3UnidirectionalEdge(H3Index origin, H3Index destination)
 {
     return(origin.UniDirectionalEdgeTo(destination));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// returns the parent (or grandparent, etc) hexagon of the given hexagon
 /// </summary>
 public static H3Index H3ToParent(H3Index h, int parentRes)
 {
     return(h.ToParent(parentRes));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// confirms if an H3Index is a valid cell (hexagon or pentagon)
 /// </summary>
 public static int H3IsValid(H3Index h)
 {
     return(h.IsValid()
                ? 1
                : 0);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// converts an H3Index to a canonical string
 /// </summary>
 public static void H3ToString(H3Index h, out string str)
 {
     str = h.ToString();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// returns the base cell "number" (0 to 121) of the provided H3 cell
 /// </summary>
 public static int H3GetBaseCell(H3Index h)
 {
     return(h.BaseCell);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// returns the resolution of the provided H3 index
 /// Works on both cells and unidirectional edges.
 /// </summary>
 public static int H3GetResolution(H3Index h)
 {
     return(h.Resolution);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// give the cell boundary in lat/lon coordinates for the cell h3
 /// </summary>
 public static void H3ToGeoBoundary(H3Index h3, out GeoBoundary gb)
 {
     gb = h3.ToGeoBoundary();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// exact length for a specific unidirectional edge in meters*/
 /// </summary>
 public static decimal ExactEdgeLengthM(H3Index edge)
 {
     return(edge.ExactEdgeLengthM());
 }
Ejemplo n.º 16
0
 /// <summary>
 /// hexagons neighbors in all directions, assuming no pentagons
 /// </summary>
 public static int HexRange(H3Index origin, int k, out List <H3Index> outHex)
 {
     (int status, var tempHex) = origin.HexRange(k);
     outHex = tempHex;
     return(status);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// returns whether or not the provided hexagons border
 /// </summary>
 public static int H3IndexesAreNeighbors(H3Index origin, H3Index destination)
 {
     return(origin.IsNeighborTo(destination)
                ? 1
                : 0);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// determines the maximum number of children (or grandchildren, etc)
 /// </summary>
 public static long MaxH3ToChildrenSize(H3Index h, int childRes)
 {
     return(h.MaxChildrenSize(childRes));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// returns whether the H3Index is a valid unidirectional edge
 /// </summary>
 public static int H3UnidirectionalEdgeIsValid(H3Index edge)
 {
     return(edge.IsValidUniEdge()
                ? 1
                : 0);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// provides the children (or grandchildren, etc) of the given hexagon
 /// </summary>
 public static void H3ToChildren(H3Index h, int childRes, out List <H3Index> outChildren)
 {
     outChildren = h.ToChildren(childRes);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Returns the destination hexagon H3Index from the unidirectional edge
 /// H3Index
 /// </summary>
 public static H3Index GetDestinationH3IndexFromUnidirectionalEdge(H3Index edge)
 {
     return(edge.DestinationFromUniDirectionalEdge());
 }
Ejemplo n.º 22
0
 /// <summary>
 /// returns the center child of the given hexagon at the specified resolution
 /// </summary>
 public static H3Index H3ToCenterChild(H3Index h, int childRes)
 {
     return(h.ToCenterChild(childRes));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Returns the 6 (or 5 for pentagons) edges associated with the H3Index
 /// </summary>
 public static void GetH3UnidirectionalEdgesFromHexagon(H3Index origin, out List <H3Index> edges)
 {
     edges = origin.GetUniEdgesFromCell().ToList();
 }
Ejemplo n.º 24
0
 /// <summary>
 /// determines if a hexagon is Class III (or Class II)
 /// </summary>
 public static int H3IsResClassIii(H3Index h)
 {
     return(h.IsResClassIii
                ? 1
                : 0);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Returns grid distance between two indexes
 /// </summary>
 public static int H3Distance(H3Index origin, H3Index h3)
 {
     return(origin.DistanceTo(h3));
 }
Ejemplo n.º 26
0
 /// <summary>
 /// determines if an H3 cell is a pentagon
 /// </summary>
 public static int H3IsPentagon(H3Index h)
 {
     return(h.IsPentagon()
                ? 1
                : 0);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Line of h3 indexes connecting two indexes
 /// </summary>
 public static int H3Line(H3Index start, H3Index end, out List <H3Index> outCells)
 {
     (int status, var tempCells) = start.LineTo(end);
     outCells = tempCells.ToList();
     return(status);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Max number of icosahedron faces intersected by an index
 /// </summary>
 public static int MaxFaceCount(H3Index h3)
 {
     return(h3.MaxFaceCount());
 }
Ejemplo n.º 29
0
 /// <summary>
 /// hexagon neighbors in all directions
 /// </summary>
 public static void KRing(H3Index origin, int k, out List <H3Index> outCells)
 {
     outCells = origin.KRing(k);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Find all icosahedron faces intersected by a given H3 index
 /// </summary>
 public static void H3GetFaces(H3Index h3, out List <int> outFaces)
 {
     outFaces = h3.GetFaces();
 }