OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
h3Index.h File Reference

H3Index functions. More...

+ Include dependency graph for h3Index.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define H3_NUM_BITS   64
 
#define H3_MAX_OFFSET   63
 
#define H3_MODE_OFFSET   59
 
#define H3_BC_OFFSET   45
 
#define H3_RES_OFFSET   52
 
#define H3_RESERVED_OFFSET   56
 
#define H3_PER_DIGIT_OFFSET   3
 
#define H3_HIGH_BIT_MASK   ((uint64_t)(1) << H3_MAX_OFFSET)
 
#define H3_HIGH_BIT_MASK_NEGATIVE   (~H3_HIGH_BIT_MASK)
 
#define H3_MODE_MASK   ((uint64_t)(15) << H3_MODE_OFFSET)
 
#define H3_MODE_MASK_NEGATIVE   (~H3_MODE_MASK)
 
#define H3_BC_MASK   ((uint64_t)(127) << H3_BC_OFFSET)
 
#define H3_BC_MASK_NEGATIVE   (~H3_BC_MASK)
 
#define H3_RES_MASK   (UINT64_C(15) << H3_RES_OFFSET)
 
#define H3_RES_MASK_NEGATIVE   (~H3_RES_MASK)
 
#define H3_RESERVED_MASK   ((uint64_t)(7) << H3_RESERVED_OFFSET)
 
#define H3_RESERVED_MASK_NEGATIVE   (~H3_RESERVED_MASK)
 
#define H3_DIGIT_MASK   ((uint64_t)(7))
 
#define H3_DIGIT_MASK_NEGATIVE   (~H3_DIGIT_MASK)
 
#define H3_INIT   (UINT64_C(35184372088831))
 
#define H3_GET_HIGH_BIT(h3)   ((int)((((h3)&H3_HIGH_BIT_MASK) >> H3_MAX_OFFSET)))
 
#define H3_SET_HIGH_BIT(h3, v)   (h3) = (((h3)&H3_HIGH_BIT_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MAX_OFFSET))
 
#define H3_GET_MODE(h3)   ((int)((((h3)&H3_MODE_MASK) >> H3_MODE_OFFSET)))
 
#define H3_SET_MODE(h3, v)   (h3) = (((h3)&H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
 
#define H3_GET_BASE_CELL(h3)   ((int)((((h3)&H3_BC_MASK) >> H3_BC_OFFSET)))
 
#define H3_SET_BASE_CELL(h3, bc)   (h3) = (((h3)&H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))
 
#define H3_GET_RESOLUTION(h3)   ((int)((((h3)&H3_RES_MASK) >> H3_RES_OFFSET)))
 
#define H3_SET_RESOLUTION(h3, res)   (h3) = (((h3)&H3_RES_MASK_NEGATIVE) | (((uint64_t)(res)) << H3_RES_OFFSET))
 
#define H3_GET_INDEX_DIGIT(h3, res)   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & H3_DIGIT_MASK)))
 
#define H3_SET_RESERVED_BITS(h3, v)   (h3) = (((h3)&H3_RESERVED_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_RESERVED_OFFSET))
 
#define H3_GET_RESERVED_BITS(h3)   ((int)((((h3)&H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
 
#define H3_SET_INDEX_DIGIT(h3, res, digit)
 
#define H3_NULL   0
 
#define COMPACT_SUCCESS   0
 
#define COMPACT_LOOP_EXCEEDED   -1
 
#define COMPACT_DUPLICATE   -2
 
#define COMPACT_ALLOC_FAILED   -3
 

Functions

EXTENSION_NOINLINE H3Index _faceIjkToH3 (const FaceIJK(fijk), int res)
 
EXTENSION_INLINE int _h3LeadingNonZeroDigit (H3Index h)
 
EXTENSION_NOINLINE H3Index _h3RotatePent60ccw (H3Index h)
 
EXTENSION_NOINLINE H3Index _h3RotatePent60cw (H3Index h)
 
EXTENSION_NOINLINE H3Index _h3Rotate60ccw (H3Index h)
 
EXTENSION_NOINLINE H3Index _h3Rotate60cw (H3Index h)
 
EXTENSION_NOINLINE int _h3ToFaceIjkWithInitializedFijk (H3Index h, FaceIJK(fijk))
 
EXTENSION_NOINLINE bool _h3ToFaceIjk (H3Index h, FaceIJK(fijk))
 
EXTENSION_NOINLINE bool _h3ToGeo (H3Index h3, GeoCoord(g))
 

Detailed Description

H3Index functions.

Definition in file h3Index.h.

Macro Definition Documentation

#define COMPACT_ALLOC_FAILED   -3

Definition at line 174 of file h3Index.h.

#define COMPACT_DUPLICATE   -2

Definition at line 173 of file h3Index.h.

#define COMPACT_LOOP_EXCEEDED   -1

Definition at line 172 of file h3Index.h.

#define COMPACT_SUCCESS   0

Definition at line 171 of file h3Index.h.

#define H3_BC_MASK   ((uint64_t)(127) << H3_BC_OFFSET)

1's in the 7 base cell bits, 0's everywhere else.

Definition at line 62 of file h3Index.h.

#define H3_BC_MASK_NEGATIVE   (~H3_BC_MASK)

0's in the 7 base cell bits, 1's everywhere else.

Definition at line 65 of file h3Index.h.

#define H3_BC_OFFSET   45

The bit offset of the base cell in an H3 index.

Definition at line 38 of file h3Index.h.

#define H3_DIGIT_MASK   ((uint64_t)(7))

1's in the 3 bits of res 15 digit bits, 0's everywhere else.

Definition at line 80 of file h3Index.h.

Referenced by h3ToParent().

#define H3_DIGIT_MASK_NEGATIVE   (~H3_DIGIT_MASK)

0's in the 7 base cell bits, 1's everywhere else.

Definition at line 83 of file h3Index.h.

#define H3_GET_BASE_CELL (   h3)    ((int)((((h3)&H3_BC_MASK) >> H3_BC_OFFSET)))

Gets the integer base cell of h3.

Definition at line 117 of file h3Index.h.

Referenced by _h3ToFaceIjk(), and _h3ToFaceIjkWithInitializedFijk().

#define H3_GET_HIGH_BIT (   h3)    ((int)((((h3)&H3_HIGH_BIT_MASK) >> H3_MAX_OFFSET)))

Gets the highest bit of the H3 index.

Definition at line 95 of file h3Index.h.

#define H3_GET_INDEX_DIGIT (   h3,
  res 
)    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & H3_DIGIT_MASK)))

Gets the resolution res integer digit (0-7) of h3.

Definition at line 139 of file h3Index.h.

Referenced by _h3LeadingNonZeroDigit(), _h3Rotate60ccw(), _h3Rotate60cw(), _h3RotatePent60ccw(), _h3RotatePent60cw(), and _h3ToFaceIjkWithInitializedFijk().

#define H3_GET_MODE (   h3)    ((int)((((h3)&H3_MODE_MASK) >> H3_MODE_OFFSET)))

Gets the integer mode of h3.

Definition at line 106 of file h3Index.h.

#define H3_GET_RESERVED_BITS (   h3)    ((int)((((h3)&H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))

Gets a value in the reserved space. Should always be zero for valid indexes.

Definition at line 152 of file h3Index.h.

#define H3_GET_RESOLUTION (   h3)    ((int)((((h3)&H3_RES_MASK) >> H3_RES_OFFSET)))
#define H3_HIGH_BIT_MASK   ((uint64_t)(1) << H3_MAX_OFFSET)

1 in the highest bit, 0's everywhere else.

Definition at line 50 of file h3Index.h.

#define H3_HIGH_BIT_MASK_NEGATIVE   (~H3_HIGH_BIT_MASK)

0 in the highest bit, 1's everywhere else.

Definition at line 53 of file h3Index.h.

#define H3_INIT   (UINT64_C(35184372088831))

H3 index with mode 0, res 0, base cell 0, and 7 for all index digits. Typically used to initialize the creation of an H3 cell index, which expects all direction digits to be 7 beyond the cell's resolution.

Definition at line 90 of file h3Index.h.

Referenced by _faceIjkToH3().

#define H3_MAX_OFFSET   63

The bit offset of the max resolution digit in an H3 index.

Definition at line 32 of file h3Index.h.

#define H3_MODE_MASK   ((uint64_t)(15) << H3_MODE_OFFSET)

1's in the 4 mode bits, 0's everywhere else.

Definition at line 56 of file h3Index.h.

#define H3_MODE_MASK_NEGATIVE   (~H3_MODE_MASK)

0's in the 4 mode bits, 1's everywhere else.

Definition at line 59 of file h3Index.h.

#define H3_MODE_OFFSET   59

The bit offset of the mode in an H3 index.

Definition at line 35 of file h3Index.h.

#define H3_NULL   0

Invalid index used to indicate an error from geoToH3 and related functions or missing data in arrays of h3 indices. Analogous to NaN in floating point.

Definition at line 165 of file h3Index.h.

Referenced by _faceIjkToH3(), geoToH3(), and h3ToParent().

#define H3_NUM_BITS   64

The number of bits in an H3 index.

Definition at line 29 of file h3Index.h.

#define H3_PER_DIGIT_OFFSET   3

The number of bits in a single H3 resolution digit.

Definition at line 47 of file h3Index.h.

#define H3_RES_MASK   (UINT64_C(15) << H3_RES_OFFSET)

1's in the 4 resolution bits, 0's everywhere else.

Definition at line 68 of file h3Index.h.

#define H3_RES_MASK_NEGATIVE   (~H3_RES_MASK)

0's in the 4 resolution bits, 1's everywhere else.

Definition at line 71 of file h3Index.h.

#define H3_RES_OFFSET   52

The bit offset of the resolution in an H3 index.

Definition at line 41 of file h3Index.h.

#define H3_RESERVED_MASK   ((uint64_t)(7) << H3_RESERVED_OFFSET)

1's in the 3 reserved bits, 0's everywhere else.

Definition at line 74 of file h3Index.h.

#define H3_RESERVED_MASK_NEGATIVE   (~H3_RESERVED_MASK)

0's in the 3 reserved bits, 1's everywhere else.

Definition at line 77 of file h3Index.h.

#define H3_RESERVED_OFFSET   56

The bit offset of the reserved bits in an H3 index.

Definition at line 44 of file h3Index.h.

#define H3_SET_BASE_CELL (   h3,
  bc 
)    (h3) = (((h3)&H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))

Sets the integer base cell of h3 to bc.

Definition at line 122 of file h3Index.h.

Referenced by _faceIjkToH3().

#define H3_SET_HIGH_BIT (   h3,
 
)    (h3) = (((h3)&H3_HIGH_BIT_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MAX_OFFSET))

Sets the highest bit of the h3 to v.

Definition at line 100 of file h3Index.h.

#define H3_SET_INDEX_DIGIT (   h3,
  res,
  digit 
)
Value:
(h3) = (((h3) & ~((H3_DIGIT_MASK << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
(((uint64_t)(digit)) << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
#define H3_PER_DIGIT_OFFSET
Definition: h3Index.h:47
#define H3_DIGIT_MASK
Definition: h3Index.h:80
#define MAX_H3_RES
Definition: constants.h:68

Sets the resolution res digit of h3 to the integer digit (0-7)

Definition at line 157 of file h3Index.h.

Referenced by _faceIjkToH3(), _h3Rotate60ccw(), _h3Rotate60cw(), _h3RotatePent60ccw(), _h3RotatePent60cw(), and h3ToParent().

#define H3_SET_MODE (   h3,
 
)    (h3) = (((h3)&H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))

Sets the integer mode of h3 to v.

Definition at line 111 of file h3Index.h.

Referenced by _faceIjkToH3().

#define H3_SET_RESERVED_BITS (   h3,
 
)    (h3) = (((h3)&H3_RESERVED_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_RESERVED_OFFSET))

Sets a value in the reserved space. Setting to non-zero may produce invalid indexes.

Definition at line 146 of file h3Index.h.

#define H3_SET_RESOLUTION (   h3,
  res 
)    (h3) = (((h3)&H3_RES_MASK_NEGATIVE) | (((uint64_t)(res)) << H3_RES_OFFSET))

Sets the integer resolution of h3.

Definition at line 133 of file h3Index.h.

Referenced by _faceIjkToH3(), and h3ToParent().

Function Documentation

EXTENSION_NOINLINE H3Index _faceIjkToH3 ( const   FaceIJKfijk,
int  res 
)

Convert an FaceIJK address to the corresponding H3Index.

Parameters
fijkThe FaceIJK address.
resThe cell resolution.
Returns
The encoded H3Index (or H3_NULL on failure).

Definition at line 643 of file h3Index.hpp.

References _baseCellIsCwOffset(), _downAp7(), _downAp7r(), _faceIjkToBaseCell(), _faceIjkToBaseCellCCWrot60(), _h3LeadingNonZeroDigit(), _h3Rotate60ccw(), _h3Rotate60cw(), _h3RotatePent60ccw(), _ijkNormalize(), _ijkSub(), _isBaseCellPentagon(), _unitIjkToDigit(), _upAp7(), _upAp7r(), CoordIJK, CoordIJK_clone, CoordIJK_copy, CoordIJK_ptr, FACE_INDEX, FaceIJK, FaceIJK_clone, H3_HEXAGON_MODE, H3_INIT, H3_NULL, H3_SET_BASE_CELL, H3_SET_INDEX_DIGIT, H3_SET_MODE, H3_SET_RESOLUTION, H3Index, I_INDEX, isResClassIII(), J_INDEX, K_AXES_DIGIT, K_INDEX, and MAX_FACE_COORD.

Referenced by geoToH3().

643  {
644  // initialize the index
645  H3Index h = H3_INIT;
648 
649  // check for res 0/base cell
650  if (res == 0) {
651  if (fijk[I_INDEX] > MAX_FACE_COORD || fijk[J_INDEX] > MAX_FACE_COORD ||
652  fijk[K_INDEX] > MAX_FACE_COORD) {
653  // out of range input
654  return H3_NULL;
655  }
656 
658  return h;
659  }
660 
661  // we need to find the correct base cell FaceIJK for this H3 index;
662  // start with the passed in face and resolution res ijk coordinates
663  // in that face's coordinate system
664  FaceIJK(fijkBC) = FaceIJK_clone(fijk);
665 
666  // build the H3Index from finest res up
667  // adjust r for the fact that the res 0 base cell offsets the indexing
668  // digits
669  CoordIJK_ptr(ijk) = fijkBC;
670  for (int r = res - 1; r >= 0; r--) {
671  CoordIJK(lastIJK) = CoordIJK_clone(ijk);
672  CoordIJK(lastCenter);
673  if (isResClassIII(r + 1)) {
674  // rotate ccw
675  _upAp7(ijk);
676  CoordIJK_copy(lastCenter, ijk);
677  _downAp7(lastCenter);
678  } else {
679  // rotate cw
680  _upAp7r(ijk);
681  CoordIJK_copy(lastCenter, ijk);
682  _downAp7r(lastCenter);
683  }
684 
685  CoordIJK(diff);
686  _ijkSub(lastIJK, lastCenter, diff);
687  _ijkNormalize(diff);
688 
689  H3_SET_INDEX_DIGIT(h, r + 1, _unitIjkToDigit(diff));
690  }
691 
692  // fijkBC should now hold the IJK of the base cell in the
693  // coordinate system of the current face
694 
695  if (fijkBC[I_INDEX] > MAX_FACE_COORD || fijkBC[J_INDEX] > MAX_FACE_COORD ||
696  fijkBC[K_INDEX] > MAX_FACE_COORD) {
697  // out of range input
698  return H3_NULL;
699  }
700 
701  // lookup the correct base cell
702  int baseCell = _faceIjkToBaseCell(fijkBC);
703  H3_SET_BASE_CELL(h, baseCell);
704 
705  // rotate if necessary to get canonical base cell orientation
706  // for this base cell
707  int numRots = _faceIjkToBaseCellCCWrot60(fijkBC);
708  if (_isBaseCellPentagon(baseCell)) {
709  // force rotation out of missing k-axes sub-sequence
711  // check for a cw/ccw offset face; default is ccw
712  if (_baseCellIsCwOffset(baseCell, fijkBC[FACE_INDEX])) {
713  h = _h3Rotate60cw(h);
714  } else {
715  h = _h3Rotate60ccw(h);
716  }
717  }
718 
719  for (int i = 0; i < numRots; i++)
720  h = _h3RotatePent60ccw(h);
721  } else {
722  for (int i = 0; i < numRots; i++) {
723  h = _h3Rotate60ccw(h);
724  }
725  }
726 
727  return h;
728 }
#define H3_SET_INDEX_DIGIT(h3, res, digit)
Definition: h3Index.h:157
#define H3_HEXAGON_MODE
Definition: constants.h:82
EXTENSION_INLINE int _h3LeadingNonZeroDigit(H3Index h)
Definition: h3Index.hpp:551
EXTENSION_NOINLINE int _unitIjkToDigit(const CoordIJK(ijk))
Definition: coordijk.hpp:266
EXTENSION_INLINE int isResClassIII(int res)
Definition: faceijk.hpp:350
#define FaceIJK(variable_name)
Definition: faceijk.h:36
EXTENSION_INLINE bool _ijkSub(const CoordIJK(h1), const CoordIJK(h2), CoordIJK(diff))
Definition: coordijk.hpp:198
#define J_INDEX
Definition: coordijk.h:43
#define H3_SET_RESOLUTION(h3, res)
Definition: h3Index.h:133
EXTENSION_NOINLINE bool _downAp7r(CoordIJK(ijk))
Definition: coordijk.hpp:348
#define H3_SET_BASE_CELL(h3, bc)
Definition: h3Index.h:122
#define H3Index
the H3Index fits within a 64-bit unsigned integer
Definition: h3api.h:75
#define CoordIJK_clone(ijk)
Definition: coordijk.h:47
#define MAX_FACE_COORD
Definition: baseCells.h:45
EXTENSION_NOINLINE H3Index _h3RotatePent60ccw(H3Index h)
Definition: h3Index.hpp:564
#define I_INDEX
Definition: coordijk.h:42
#define CoordIJK_ptr(variable_name)
Definition: coordijk.h:46
EXTENSION_INLINE int _isBaseCellPentagon(int baseCell)
Return whether or not the indicated base cell is a pentagon.
Definition: baseCells.hpp:824
#define CoordIJK(variable_name)
Definition: coordijk.h:45
#define CoordIJK_copy(dest_ijk, src_ijk)
Definition: coordijk.h:49
EXTENSION_INLINE bool _baseCellIsCwOffset(int baseCell, int testFace)
Find the FaceIJK given a base cell.
Definition: baseCells.hpp:887
EXTENSION_INLINE int _faceIjkToBaseCellCCWrot60(const FaceIJK(h))
Find base cell given FaceIJK.
Definition: baseCells.hpp:854
#define FACE_INDEX
Definition: faceijk.h:35
EXTENSION_NOINLINE bool _downAp7(CoordIJK(ijk))
Definition: coordijk.hpp:325
#define FaceIJK_clone(fijk)
Definition: faceijk.h:37
EXTENSION_NOINLINE bool _upAp7(CoordIJK(ijk))
Definition: coordijk.hpp:287
#define K_INDEX
Definition: coordijk.h:44
#define H3_INIT
Definition: h3Index.h:90
#define H3_NULL
Definition: h3Index.h:165
EXTENSION_NOINLINE bool _upAp7r(CoordIJK(ijk))
Definition: coordijk.hpp:306
EXTENSION_INLINE int _faceIjkToBaseCell(const FaceIJK(h))
Return whether the indicated base cell is a pentagon where all neighbors are oriented towards it...
Definition: baseCells.hpp:842
#define H3_SET_MODE(h3, v)
Definition: h3Index.h:111
EXTENSION_NOINLINE H3Index _h3Rotate60cw(H3Index h)
Definition: h3Index.hpp:629
EXTENSION_NOINLINE bool _ijkNormalize(CoordIJK(c))
Definition: coordijk.hpp:224
EXTENSION_NOINLINE H3Index _h3Rotate60ccw(H3Index h)
Definition: h3Index.hpp:616

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE int _h3LeadingNonZeroDigit ( H3Index  h)

Determines whether one resolution is a valid child resolution of another. Each resolution is considered a valid child resolution of itself.

Parameters
parentResint resolution of the parent
childResint resolution of the child
Returns
The validity of the child resolution maxH3ToChildrenSize returns the maximum number of children possible for a given child level.
Parameters
hH3Index to find the number of children of
childResThe resolution of the child level you're interested in
Returns
int count of maximum number of children (equal for hexagons, less for pentagons makeDirectChild takes an index and immediately returns the immediate child index based on the specified cell number. Bit operations only, could generate invalid indexes if not careful (deleted cell under a pentagon).
Parameters
hH3Index to find the direct child of
cellNumberint id of the direct child (0-6)
Returns
The new H3Index for the child h3ToChildren takes the given hexagon id and generates all of the children at the specified resolution storing them into the provided memory pointer. It's assumed that maxH3ToChildrenSize was used to determine the allocation.
Parameters
hH3Index to find the children of
childResint the child level to produce
childrenH3Index* the memory to store the resulting addresses in h3ToCenterChild produces the center child index for a given H3 index at the specified resolution
hH3Index to find center child of
childResThe resolution to switch to
Returns
H3Index of the center child, or H3_NULL if you actually asked for a parent compact takes a set of hexagons all at the same resolution and compresses them by pruning full child branches to the parent level. This is also done for all parents recursively to get the minimum number of hex addresses that perfectly cover the defined space.
Parameters
h3SetSet of hexagons
compactedSetThe output array of compressed hexagons (preallocated)
numHexesThe size of the input and output arrays (possible that no contiguous regions exist in the set at all and no compression possible)
Returns
an error code on bad input data uncompact takes a compressed set of hexagons and expands back to the original set of hexagons.
Parameters
compactedSetSet of hexagons
numHexesThe number of hexes in the input set
h3SetOutput array of decompressed hexagons (preallocated)
maxHexesThe size of the output array to bound check against
resThe hexagon resolution to decompress to
Returns
An error code if output array is too small or any hexagon is smaller than the output resolution. maxUncompactSize takes a compacted set of hexagons are provides an upper-bound estimate of the size of the uncompacted set of hexagons.
Parameters
compactedSetSet of hexagons
numHexesThe number of hexes in the input set
resThe hexagon resolution to decompress to
Returns
The number of hexagons to allocate memory for, or a negative number if an error occurs. h3IsResClassIII takes a hexagon ID and determines if it is in a Class III resolution (rotated versus the icosahedron and subject to shape distortion adding extra points on icosahedron edges, making them not true hexagons).
Parameters
hThe H3Index to check.
Returns
Returns 1 if the hexagon is class III, otherwise 0. h3IsPentagon takes an H3Index and determines if it is actually a pentagon.
Parameters
hThe H3Index to check.
Returns
Returns 1 if it is a pentagon, otherwise 0. Returns the highest resolution non-zero digit in an H3Index.
Parameters
hThe H3Index.
Returns
The highest resolution non-zero digit in the H3Index.

Definition at line 551 of file h3Index.hpp.

References CENTER_DIGIT, H3_GET_INDEX_DIGIT, and H3_GET_RESOLUTION.

Referenced by _faceIjkToH3(), _h3RotatePent60ccw(), _h3RotatePent60cw(), and _h3ToFaceIjk().

551  {
552  for (int r = 1; r <= H3_GET_RESOLUTION(h); r++)
553  if (H3_GET_INDEX_DIGIT(h, r))
554  return H3_GET_INDEX_DIGIT(h, r);
555 
556  // if we're here it's all 0's
557  return CENTER_DIGIT;
558 }
#define H3_GET_INDEX_DIGIT(h3, res)
Definition: h3Index.h:139
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the caller graph for this function:

EXTENSION_NOINLINE H3Index _h3Rotate60ccw ( H3Index  h)

Rotate an H3Index 60 degrees counter-clockwise.

Parameters
hThe H3Index.

Definition at line 616 of file h3Index.hpp.

References _rotate60ccw(), H3_GET_INDEX_DIGIT, H3_GET_RESOLUTION, H3_SET_INDEX_DIGIT, and run_benchmark_import::res.

Referenced by _faceIjkToH3(), and _h3RotatePent60ccw().

616  {
617  for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
618  Direction oldDigit = H3_GET_INDEX_DIGIT(h, r);
619  H3_SET_INDEX_DIGIT(h, r, _rotate60ccw(oldDigit));
620  }
621 
622  return h;
623 }
#define H3_SET_INDEX_DIGIT(h3, res, digit)
Definition: h3Index.h:157
EXTENSION_NOINLINE int _rotate60ccw(int digit)
Definition: coordijk.hpp:429
Direction
H3 digit representing ijk+ axes direction. Values will be within the lowest 3 bits of an integer...
Definition: coordijk.h:75
#define H3_GET_INDEX_DIGIT(h3, res)
Definition: h3Index.h:139
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE H3Index _h3Rotate60cw ( H3Index  h)

Rotate an H3Index 60 degrees clockwise.

Parameters
hThe H3Index.

Definition at line 629 of file h3Index.hpp.

References _rotate60cw(), H3_GET_INDEX_DIGIT, H3_GET_RESOLUTION, H3_SET_INDEX_DIGIT, and run_benchmark_import::res.

Referenced by _faceIjkToH3(), _h3RotatePent60cw(), and _h3ToFaceIjk().

629  {
630  for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
632  }
633 
634  return h;
635 }
#define H3_SET_INDEX_DIGIT(h3, res, digit)
Definition: h3Index.h:157
EXTENSION_NOINLINE int _rotate60cw(int digit)
Definition: coordijk.hpp:453
#define H3_GET_INDEX_DIGIT(h3, res)
Definition: h3Index.h:139
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE H3Index _h3RotatePent60ccw ( H3Index  h)

Rotate an H3Index 60 degrees counter-clockwise about a pentagonal center.

Parameters
hThe H3Index.

Definition at line 564 of file h3Index.hpp.

References _h3LeadingNonZeroDigit(), _h3Rotate60ccw(), _rotate60ccw(), H3_GET_INDEX_DIGIT, H3_GET_RESOLUTION, H3_SET_INDEX_DIGIT, K_AXES_DIGIT, and run_benchmark_import::res.

Referenced by _faceIjkToH3().

564  {
565  // rotate in place; skips any leading 1 digits (k-axis)
566 
567  int foundFirstNonZeroDigit = 0;
568  for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
569  // rotate this digit
571 
572  // look for the first non-zero digit so we
573  // can adjust for deleted k-axes sequence
574  // if necessary
575  if (!foundFirstNonZeroDigit && H3_GET_INDEX_DIGIT(h, r) != 0) {
576  foundFirstNonZeroDigit = 1;
577 
578  // adjust for deleted k-axes sequence
580  h = _h3Rotate60ccw(h);
581  }
582  }
583  return h;
584 }
#define H3_SET_INDEX_DIGIT(h3, res, digit)
Definition: h3Index.h:157
EXTENSION_INLINE int _h3LeadingNonZeroDigit(H3Index h)
Definition: h3Index.hpp:551
EXTENSION_NOINLINE int _rotate60ccw(int digit)
Definition: coordijk.hpp:429
#define H3_GET_INDEX_DIGIT(h3, res)
Definition: h3Index.h:139
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128
EXTENSION_NOINLINE H3Index _h3Rotate60ccw(H3Index h)
Definition: h3Index.hpp:616

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE H3Index _h3RotatePent60cw ( H3Index  h)

Rotate an H3Index 60 degrees clockwise about a pentagonal center.

Parameters
hThe H3Index.

Definition at line 590 of file h3Index.hpp.

References _h3LeadingNonZeroDigit(), _h3Rotate60cw(), _rotate60cw(), H3_GET_INDEX_DIGIT, H3_GET_RESOLUTION, H3_SET_INDEX_DIGIT, K_AXES_DIGIT, and run_benchmark_import::res.

590  {
591  // rotate in place; skips any leading 1 digits (k-axis)
592 
593  int foundFirstNonZeroDigit = 0;
594  for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
595  // rotate this digit
597 
598  // look for the first non-zero digit so we
599  // can adjust for deleted k-axes sequence
600  // if necessary
601  if (!foundFirstNonZeroDigit && H3_GET_INDEX_DIGIT(h, r) != 0) {
602  foundFirstNonZeroDigit = 1;
603 
604  // adjust for deleted k-axes sequence
606  h = _h3Rotate60cw(h);
607  }
608  }
609  return h;
610 }
#define H3_SET_INDEX_DIGIT(h3, res, digit)
Definition: h3Index.h:157
EXTENSION_INLINE int _h3LeadingNonZeroDigit(H3Index h)
Definition: h3Index.hpp:551
EXTENSION_NOINLINE int _rotate60cw(int digit)
Definition: coordijk.hpp:453
#define H3_GET_INDEX_DIGIT(h3, res)
Definition: h3Index.h:139
EXTENSION_NOINLINE H3Index _h3Rotate60cw(H3Index h)
Definition: h3Index.hpp:629
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool _h3ToFaceIjk ( H3Index  h,
FaceIJK(fijk)   
)

Convert an H3Index to a FaceIJK address.

Parameters
hThe H3Index.
fijkThe corresponding FaceIJK address.

Definition at line 783 of file h3Index.hpp.

References _adjustOverageClassII(), _downAp7r(), _h3LeadingNonZeroDigit(), _h3Rotate60cw(), _h3ToFaceIjkWithInitializedFijk(), _isBaseCellPentagon(), _upAp7r(), baseCellData, CoordIJK, CoordIJK_clone, CoordIJK_copy, FaceIJK_copy, H3_GET_BASE_CELL, H3_GET_RESOLUTION, isResClassIII(), NO_OVERAGE, and run_benchmark_import::res.

Referenced by _h3ToGeo().

783  {
784  int baseCell = H3_GET_BASE_CELL(h);
785  // adjust for the pentagonal missing sequence; all of sub-sequence 5 needs
786  // to be adjusted (and some of sub-sequence 4 below)
787  if (_isBaseCellPentagon(baseCell) && _h3LeadingNonZeroDigit(h) == 5)
788  h = _h3Rotate60cw(h);
789 
790  // start with the "home" face and ijk+ coordinates for the base cell of c
791  FaceIJK_copy(fijk, baseCellData[baseCell].homeFijk);
792  if (!_h3ToFaceIjkWithInitializedFijk(h, fijk))
793  return true; // no overage is possible; h lies on this face
794 
795  // if we're here we have the potential for an "overage"; i.e., it is
796  // possible that c lies on an adjacent face
797 
798  CoordIJK(origIJK) = CoordIJK_clone(fijk);
799 
800  // if we're in Class III, drop into the next finer Class II grid
801  int res = H3_GET_RESOLUTION(h);
802  if (isResClassIII(res)) {
803  // Class III
804  _downAp7r(fijk);
805  res++;
806  }
807 
808  // adjust for overage if needed
809  // a pentagon base cell with a leading 4 digit requires special handling
810  int pentLeading4 = (_isBaseCellPentagon(baseCell) && _h3LeadingNonZeroDigit(h) == 4);
811  if (_adjustOverageClassII(fijk, res, pentLeading4, 0) != NO_OVERAGE) {
812  // if the base cell is a pentagon we have the potential for secondary
813  // overages
814  if (_isBaseCellPentagon(baseCell)) {
815  while (_adjustOverageClassII(fijk, res, 0, 0) != NO_OVERAGE)
816  continue;
817  }
818 
819  if (res != H3_GET_RESOLUTION(h))
820  _upAp7r(fijk);
821  } else if (res != H3_GET_RESOLUTION(h)) {
822  CoordIJK_copy(fijk, origIJK);
823  }
824  return true;
825 }
EXTENSION_INLINE int _h3LeadingNonZeroDigit(H3Index h)
Definition: h3Index.hpp:551
EXTENSION_NOINLINE int _h3ToFaceIjkWithInitializedFijk(H3Index h, FaceIJK(fijk))
Definition: h3Index.hpp:753
EXTENSION_INLINE int isResClassIII(int res)
Definition: faceijk.hpp:350
EXTENSION_NOINLINE bool _downAp7r(CoordIJK(ijk))
Definition: coordijk.hpp:348
DEVICE const BaseCellData baseCellData[NUM_BASE_CELLS]
Resolution 0 base cell data table.
Definition: baseCells.hpp:697
#define H3_GET_BASE_CELL(h3)
Definition: h3Index.h:117
#define CoordIJK_clone(ijk)
Definition: coordijk.h:47
#define FaceIJK_copy(dest_ijk, src_ijk)
Definition: faceijk.h:39
EXTENSION_INLINE int _isBaseCellPentagon(int baseCell)
Return whether or not the indicated base cell is a pentagon.
Definition: baseCells.hpp:824
#define CoordIJK(variable_name)
Definition: coordijk.h:45
#define CoordIJK_copy(dest_ijk, src_ijk)
Definition: coordijk.h:49
EXTENSION_NOINLINE bool _upAp7r(CoordIJK(ijk))
Definition: coordijk.hpp:306
EXTENSION_NOINLINE int _adjustOverageClassII(FaceIJK(fijk), int res, int pentLeading4, int substrate)
Definition: faceijk.hpp:864
EXTENSION_NOINLINE H3Index _h3Rotate60cw(H3Index h)
Definition: h3Index.hpp:629
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE int _h3ToFaceIjkWithInitializedFijk ( H3Index  h,
FaceIJK(fijk)   
)

Convert an H3Index to the FaceIJK address on a specified icosahedral face.

Parameters
hThe H3Index.
fijkThe FaceIJK address, initialized with the desired face and normalized base cell coordinates.
Returns
Returns 1 if the possibility of overage exists, otherwise 0.

Definition at line 753 of file h3Index.hpp.

References _downAp7(), _downAp7r(), _isBaseCellPentagon(), _neighbor(), H3_GET_BASE_CELL, H3_GET_INDEX_DIGIT, H3_GET_RESOLUTION, I_INDEX, isResClassIII(), J_INDEX, K_INDEX, and run_benchmark_import::res.

Referenced by _h3ToFaceIjk().

753  {
754  int* ijk = fijk;
755  int res = H3_GET_RESOLUTION(h);
756 
757  // center base cell hierarchy is entirely on this face
758  int possibleOverage = 1;
760  (res == 0 || (fijk[I_INDEX] == 0 && fijk[J_INDEX] == 0 && fijk[K_INDEX] == 0)))
761  possibleOverage = 0;
762 
763  for (int r = 1; r <= res; r++) {
764  if (isResClassIII(r)) {
765  // Class III == rotate ccw
766  _downAp7(ijk);
767  } else {
768  // Class II == rotate cw
769  _downAp7r(ijk);
770  }
771 
772  _neighbor(ijk, H3_GET_INDEX_DIGIT(h, r));
773  }
774 
775  return possibleOverage;
776 }
EXTENSION_INLINE int isResClassIII(int res)
Definition: faceijk.hpp:350
EXTENSION_NOINLINE bool _neighbor(CoordIJK(ijk), int digit)
Definition: coordijk.hpp:372
#define J_INDEX
Definition: coordijk.h:43
EXTENSION_NOINLINE bool _downAp7r(CoordIJK(ijk))
Definition: coordijk.hpp:348
#define H3_GET_BASE_CELL(h3)
Definition: h3Index.h:117
#define I_INDEX
Definition: coordijk.h:42
EXTENSION_INLINE int _isBaseCellPentagon(int baseCell)
Return whether or not the indicated base cell is a pentagon.
Definition: baseCells.hpp:824
#define H3_GET_INDEX_DIGIT(h3, res)
Definition: h3Index.h:139
EXTENSION_NOINLINE bool _downAp7(CoordIJK(ijk))
Definition: coordijk.hpp:325
#define K_INDEX
Definition: coordijk.h:44
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool _h3ToGeo ( H3Index  h3,
GeoCoord(g)   
)

Determines the spherical coordinates of the center point of an H3 index.

Parameters
h3The H3 index.
gThe spherical coordinates of the H3 cell center. Note: spherical coordinates are in radians.

Definition at line 834 of file h3Index.hpp.

References _faceIjkToGeo(), _h3ToFaceIjk(), FaceIJK, and H3_GET_RESOLUTION.

Referenced by h3ToGeoPacked(), h3ToLat(), and h3ToLon().

834  {
835  FaceIJK(fijk);
836  _h3ToFaceIjk(h3, fijk);
837  _faceIjkToGeo(fijk, H3_GET_RESOLUTION(h3), g);
838  return true;
839 }
#define FaceIJK(variable_name)
Definition: faceijk.h:36
EXTENSION_NOINLINE bool _h3ToFaceIjk(H3Index h, FaceIJK(fijk))
Definition: h3Index.hpp:783
EXTENSION_NOINLINE bool _faceIjkToGeo(const FaceIJK(h), int res, GeoCoord(g))
Definition: faceijk.hpp:495
#define H3_GET_RESOLUTION(h3)
Definition: h3Index.h:128

+ Here is the call graph for this function:

+ Here is the caller graph for this function: