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 void h3UnidirectionalEdgeIsValid() { H3Index sf = H3Index.geoToH3(ref sfGeo, 9); var ring = new ulong[Algos.maxKringSize(1)].Select(cell => new H3Index(cell)).ToList(); Algos.hexRing(sf, 1, ref ring); H3Index sf2 = ring[0]; H3Index edge = H3UniEdge.getH3UnidirectionalEdge(sf, sf2); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(edge) == 1, "edges validate correctly"); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(sf) == 0, "hexagons do not validate"); H3Index fakeEdge = sf; H3Index.H3_SET_MODE(ref fakeEdge, Constants.H3_UNIEDGE_MODE); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(fakeEdge) == 0, "edges without an edge specified don't work"); H3Index pentagon = 0x821c07fffffffff; H3Index goodPentagonalEdge = pentagon; H3Index.H3_SET_MODE(ref goodPentagonalEdge, Constants.H3_UNIEDGE_MODE); H3Index.H3_SET_RESERVED_BITS(ref goodPentagonalEdge, 2); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(goodPentagonalEdge) == 1, "pentagonal edge validates"); H3Index badPentagonalEdge = goodPentagonalEdge; H3Index.H3_SET_RESERVED_BITS(ref badPentagonalEdge, 1); Assert.True(H3UniEdge.h3UnidirectionalEdgeIsValid(badPentagonalEdge) == 0, "missing pentagonal edge does not validate"); }
public static H3Index GetOriginH3FromUniDirectionalEdge(Code.H3Index edge) { return(new H3Index { Value = H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(edge).value }); }
public static H3Index GetDestinationH3FromUniDirectionalEdge(Code.H3Index edge) { return(new H3Index { Value = H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(edge) }); }
public static H3Index GetUniDirectionalEdge(Code.H3Index origin, Code.H3Index destination) { return(new H3Index { Value = H3UniEdge.getH3UnidirectionalEdge(origin, destination).value }); }
public void getH3UnidirectionalEdgeAndFriends() { 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); H3Index sf2 = ring[0]; H3Index edge = H3UniEdge.getH3UnidirectionalEdge(sf, sf2); Assert.True(sf == H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(edge), "can retrieve the origin from the edge"); Assert.True( sf2 == H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(edge), "can retrieve the destination from the edge"); var originDestination = new ulong[2].Select(cell => new H3Index(cell)).ToList(); H3UniEdge.getH3IndexesFromUnidirectionalEdge(edge, ref originDestination); Assert.True(originDestination[0] == sf, "got the origin first in the pair request"); Assert.True(originDestination[1] == sf2, "got the destination last in the pair request"); List <H3Index> largerRing = new ulong[Algos.maxKringSize(2)].Select(cell => new H3Index(cell)).ToList(); Algos.hexRing(sf, 2, ref largerRing); H3Index sf3 = largerRing[0]; H3Index notEdge = H3UniEdge.getH3UnidirectionalEdge(sf, sf3); Assert.True(notEdge == 0, "Non-neighbors can't have edges"); }
public void getOriginH3IndexFromUnidirectionalEdgeBadInput() { H3Index hexagon = 0x891ea6d6533ffffL; Assert.True(H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(hexagon) == 0, "getting the origin from a hexagon index returns 0"); Assert.True(H3UniEdge.getOriginH3IndexFromUnidirectionalEdge(0) == 0, "getting the origin from a null index returns 0"); }
public void getDestinationH3IndexFromUnidirectionalEdge() { H3Index hexagon = 0x891ea6d6533ffffL; Assert.True( H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(hexagon) == 0, "getting the destination from a hexagon index returns 0"); Assert.True(H3UniEdge.getDestinationH3IndexFromUnidirectionalEdge(0) == 0, "getting the destination from a null index returns 0"); }
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 static H3Index[] GetH3IndexesFromUnidirectionalEdge(Code.H3Index edge) { List <Code.H3Index> cells = new List <Code.H3Index> { 0, 0 }; H3UniEdge.getH3IndexesFromUnidirectionalEdge(edge, ref cells); return(cells.Select(v => new H3Index { Value = v.value }).ToArray()); }
public static GeoBoundary GetH3UnidirectionalEdgeBoundary(Code.H3Index edge) { Code.GeoBoundary gb = new Code.GeoBoundary(); H3UniEdge.getH3UnidirectionalEdgeBoundary(edge, ref gb); var newVerts = gb.verts.Select(v => new GeoCoord(v)).ToArray(); return(new GeoBoundary { VertexCount = gb.numVerts, Vertices = newVerts }); }
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 getH3UnidirectionalEdgeFromPentagon() { H3Index pentagon = new H3Index(); H3Index.setH3Index(ref pentagon, 0, 4, 0); H3Index adjacent = new H3Index(); H3Index.setH3Index(ref adjacent, 0, 8, 0); H3Index edge = H3UniEdge.getH3UnidirectionalEdge(pentagon, adjacent); Assert.True(edge != 0, "Produces a valid edge"); }
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"); }
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"); } } } }
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" ); }
public static int H3UniDirectionalEdgeIsValid(Code.H3Index edge) { return(H3UniEdge.h3UnidirectionalEdgeIsValid(edge)); }