/// <summary> /// Returns a unidirectional edge H3 index based on the provided origin and /// destination /// </summary> /// <param name="origin">The origin H3 hexagon index</param> /// <param name="destination">The destination H3 hexagon index</param> /// <returns>The unidirectional edge H3Index, or 0 on failure.</returns> /// <!-- Based off 3.1.1 --> public static H3Index getH3UnidirectionalEdge(H3Index origin, H3Index destination) { // Short-circuit and return an invalid index value if they are not neighbors if (h3IndexesAreNeighbors(origin, destination) == 0) { return(H3Index.H3_INVALID_INDEX); } // Otherwise, determine the IJK direction from the origin to the destination H3Index output = origin; H3Index.H3_SET_MODE(ref output, Constants.H3_UNIEDGE_MODE); // Checks each neighbor, in order, to determine which direction the // destination neighbor is located. Skips CENTER_DIGIT since that // would be this index. for (var direction = Direction.K_AXES_DIGIT; direction < Direction.NUM_DIGITS; direction++) { int rotations = 0; H3Index neighbor = Algos.h3NeighborRotations(origin, direction, ref rotations); if (neighbor == destination) { H3Index.H3_SET_RESERVED_BITS(ref output, (ulong)direction); return(output); } } // This should be impossible, return an invalid H3Index in this case; return(H3Index.H3_INVALID_INDEX); // LCOV_EXCL_LINE }
/// <summary> /// Returns the destination hexagon from the unidirectional edge H3Index /// </summary> /// <param name="edge">The edge H3 index</param> /// <returns>The destination H3 hexagon index</returns> /// <!-- Based off 3.1.1 --> public static H3Index getDestinationH3IndexFromUnidirectionalEdge(H3Index edge) { if (H3Index.H3_GET_MODE(ref edge) != Constants.H3_UNIEDGE_MODE) { return(H3Index.H3_INVALID_INDEX); } Direction direction = (Direction)H3Index.H3_GET_RESERVED_BITS(edge); int rotations = 0; H3Index destination = Algos .h3NeighborRotations ( getOriginH3IndexFromUnidirectionalEdge(edge), direction, ref rotations ); return(destination); }