public void getH3UnidirectionalEdgesFromHexagon() { H3Index sf = H3Index.geoToH3(ref sfGeo, 9); var edges = new ulong[6].Select(cell => new H3Index(cell)).ToList(); H3UniEdge.getH3UnidirectionalEdgesFromHexagon(sf, edges); for (int i = 0; i < 6; i++) { Assert.True ( H3UniEdge.h3UnidirectionalEdgeIsValid(edges[i]) == 1, "edge is an edge" ); Assert.True ( sf == H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(edges[i]), "origin is correct" ); Assert.True ( sf != H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(edges[i]), "destination is not origin" ); } }
public static H3Index[] GetH3UniDirectionalEdgesFromHexagon(Code.H3Index origin) { var cells = MakeEmpty(6); H3UniEdge.getH3UnidirectionalEdgesFromHexagon(origin, cells); return(cells.Where(v => v != 0) .Select(v => new H3Index { Value = v.value }) .ToArray()); }
public void getH3UnidirectionalEdgeBoundaryPentagonClassIII() { H3Index pentagon = 0; GeoBoundary boundary = new GeoBoundary(); GeoBoundary edgeBoundary = new GeoBoundary(); var edges = new ulong[6].Select(cell => new H3Index(cell)).ToList(); int[,] expectedVertices = { { -1, -1, -1 }, { 2, 3, 4 }, { 4, 5, 6 }, { 8, 9, 0 }, { 6, 7, 8 }, { 0, 1, 2 } }; // TODO: The current implementation relies on lat/lon comparison and fails // on resolutions finer than 12 for (int res = 1; res < 13; res += 2) { H3Index.setH3Index(ref pentagon, res, 24, 0); H3Index.h3ToGeoBoundary(pentagon, ref boundary); H3UniEdge.getH3UnidirectionalEdgesFromHexagon(pentagon, edges); int missingEdgeCount = 0; for (int i = 0; i < 6; i++) { if (edges[i] == 0) { missingEdgeCount++; } else { H3UniEdge.getH3UnidirectionalEdgeBoundary(edges[i], ref edgeBoundary); Assert.True (edgeBoundary.numVerts == 3, "Got the expected number of vertices back for a Class III pentagon" ); for (int j = 0; j < edgeBoundary.numVerts; j++) { Assert.True ( GeoCoord.geoAlmostEqual(edgeBoundary.verts[j], boundary.verts[expectedVertices[i, j]]), "Got expected vertex" ); } } } Assert.True (missingEdgeCount == 1, "Only one edge was deleted for the pentagon" ); } }
public void getH3UnidirectionalEdgesFromPentagon() { H3Index pentagon = 0x821c07fffffffff; var edges = new ulong[6].Select(cell => new H3Index(cell)).ToList(); H3UniEdge.getH3UnidirectionalEdgesFromHexagon(pentagon, edges); int missingEdgeCount = 0; for (int i = 0; i < 6; i++) { if (edges[i] == 0) { missingEdgeCount++; } else { Assert.True ( H3UniEdge.h3UnidirectionalEdgeIsValid(edges[i]) == 1, "edge is an edge" ); Assert.True ( pentagon == H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(edges[i]), "origin is correct" ); Assert.True ( pentagon != H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(edges[i]), "destination is not origin" ); } } Assert.True ( missingEdgeCount == 1, "Only one edge was deleted for the pentagon" ); }
public void getH3UnidirectionalEdgeBoundary() { H3Index sf = 0; GeoBoundary boundary = new GeoBoundary(); GeoBoundary edgeBoundary = new GeoBoundary(); var edges = new ulong[6].Select(cell => new H3Index(cell)).ToList(); int[,] expectedVertices = { { 3, 4 }, { 1, 2 }, { 2, 3 }, { 5, 0 }, { 4, 5 }, { 0, 1 } }; // TODO: The current implementation relies on lat/lon comparison and fails // on resolutions finer than 12 for (int res = 0; res < 13; res++) { sf = H3Index.geoToH3(ref sfGeo, res); H3Index.h3ToGeoBoundary(sf, ref boundary); H3UniEdge.getH3UnidirectionalEdgesFromHexagon(sf, edges); for (int i = 0; i < 6; i++) { H3UniEdge.getH3UnidirectionalEdgeBoundary(edges[i], ref edgeBoundary); Assert.True(edgeBoundary.numVerts == 2, "Got the expected number of vertices back"); for (int j = 0; j < edgeBoundary.numVerts; j++) { Assert.True( GeoCoord.geoAlmostEqual(edgeBoundary.verts[j], boundary.verts[expectedVertices[i, j]]), "Got expected vertex"); } } } }