public static H3Index GetUniDirectionalEdge(Code.H3Index origin, Code.H3Index destination) { return(new H3Index { Value = H3UniEdge.getH3UnidirectionalEdge(origin, destination).value }); }
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 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 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"); }