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); }
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); } } } } }
/// <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); }
/// <summary> /// Number of indexes in a line connecting two indexes /// </summary> public static int H3LineSize(H3Index start, H3Index end) { return(start.LineSize(end)); }
/// <summary> /// Returns the GeoBoundary containing the coordinates of the edge /// </summary> public static void GetH3UnidirectionalEdgeBoundary(H3Index edge, out GeoBoundary gb) { gb = edge.UniEdgeToGeoBoundary(); }
/// <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(); }
/// <summary> /// Returns the origin hexagon H3Index from the unidirectional edge /// </summary> /// H3Index public static H3Index GetOriginH3IndexFromUnidirectionalEdge(H3Index edge) { return(edge.OriginFromUniDirectionalEdge()); }
/// <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)); }
/// <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)); }
/// <summary> /// confirms if an H3Index is a valid cell (hexagon or pentagon) /// </summary> public static int H3IsValid(H3Index h) { return(h.IsValid() ? 1 : 0); }
/// <summary> /// converts an H3Index to a canonical string /// </summary> public static void H3ToString(H3Index h, out string str) { str = h.ToString(); }
/// <summary> /// returns the base cell "number" (0 to 121) of the provided H3 cell /// </summary> public static int H3GetBaseCell(H3Index h) { return(h.BaseCell); }
/// <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); }
/// <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(); }
/// <summary> /// exact length for a specific unidirectional edge in meters*/ /// </summary> public static decimal ExactEdgeLengthM(H3Index edge) { return(edge.ExactEdgeLengthM()); }
/// <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); }
/// <summary> /// returns whether or not the provided hexagons border /// </summary> public static int H3IndexesAreNeighbors(H3Index origin, H3Index destination) { return(origin.IsNeighborTo(destination) ? 1 : 0); }
/// <summary> /// determines the maximum number of children (or grandchildren, etc) /// </summary> public static long MaxH3ToChildrenSize(H3Index h, int childRes) { return(h.MaxChildrenSize(childRes)); }
/// <summary> /// returns whether the H3Index is a valid unidirectional edge /// </summary> public static int H3UnidirectionalEdgeIsValid(H3Index edge) { return(edge.IsValidUniEdge() ? 1 : 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); }
/// <summary> /// Returns the destination hexagon H3Index from the unidirectional edge /// H3Index /// </summary> public static H3Index GetDestinationH3IndexFromUnidirectionalEdge(H3Index edge) { return(edge.DestinationFromUniDirectionalEdge()); }
/// <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)); }
/// <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(); }
/// <summary> /// determines if a hexagon is Class III (or Class II) /// </summary> public static int H3IsResClassIii(H3Index h) { return(h.IsResClassIii ? 1 : 0); }
/// <summary> /// Returns grid distance between two indexes /// </summary> public static int H3Distance(H3Index origin, H3Index h3) { return(origin.DistanceTo(h3)); }
/// <summary> /// determines if an H3 cell is a pentagon /// </summary> public static int H3IsPentagon(H3Index h) { return(h.IsPentagon() ? 1 : 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); }
/// <summary> /// Max number of icosahedron faces intersected by an index /// </summary> public static int MaxFaceCount(H3Index h3) { return(h3.MaxFaceCount()); }
/// <summary> /// hexagon neighbors in all directions /// </summary> public static void KRing(H3Index origin, int k, out List <H3Index> outCells) { outCells = origin.KRing(k); }
/// <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(); }