LLVMFuzzerTestOneInput:
   29|    580|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   30|    580|    if (size < sizeof(inputArgs)) {
  ------------------
  |  Branch (30:9): [True: 6, False: 574]
  ------------------
   31|      6|        return 0;
   32|      6|    }
   33|    574|    const inputArgs *args = (const inputArgs *)data;
   34|       |
   35|    574|    H3Index out;
   36|    574|    H3_EXPORT(cellToVertex)(args->index, args->vertexNum, &out);
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   37|    574|    H3Index outArr[6];
   38|    574|    H3_EXPORT(cellToVertexes)(args->index, outArr);
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   39|    574|    LatLng geo;
   40|    574|    H3_EXPORT(vertexToLatLng)(args->index, &geo);
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   41|    574|    H3_EXPORT(isValidVertex)(args->index);
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   42|    574|    H3Index v1, v2;
   43|    574|    H3_EXPORT(edgeToVertexes)(args->index, &v1, &v2);
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   44|    574|    return 0;
   45|    580|}

faceijk.c:_ijkToHex2d:
  244|    561|static inline void _ijkToHex2d(const CoordIJK *h, Vec2d *v) {
  245|    561|    int i = h->i - h->k;
  246|    561|    int j = h->j - h->k;
  247|       |
  248|    561|    v->x = i - 0.5 * j;
  249|    561|    v->y = j * M_SQRT3_2;
  ------------------
  |  |   52|    561|#define M_SQRT3_2 0.8660254037844386467637231707529361834714
  ------------------
  250|    561|}
faceijk.c:_ijkRotate60ccw:
  614|  17.1k|static inline void _ijkRotate60ccw(CoordIJK *ijk) {
  615|       |    // unit vector rotations
  616|  17.1k|    CoordIJK iVec = {1, 1, 0};
  617|  17.1k|    CoordIJK jVec = {0, 1, 1};
  618|  17.1k|    CoordIJK kVec = {1, 0, 1};
  619|       |
  620|  17.1k|    _ijkScale(&iVec, ijk->i);
  621|  17.1k|    _ijkScale(&jVec, ijk->j);
  622|  17.1k|    _ijkScale(&kVec, ijk->k);
  623|       |
  624|  17.1k|    _ijkAdd(&iVec, &jVec, ijk);
  625|  17.1k|    _ijkAdd(ijk, &kVec, ijk);
  626|       |
  627|  17.1k|    _ijkNormalize(ijk);
  628|  17.1k|}
faceijk.c:_ijkScale:
  155|  63.2k|static inline void _ijkScale(CoordIJK *c, int factor) {
  156|  63.2k|    c->i *= factor;
  157|  63.2k|    c->j *= factor;
  158|  63.2k|    c->k *= factor;
  159|  63.2k|}
faceijk.c:_ijkAdd:
  129|  47.8k|                           CoordIJK *sum) {
  130|  47.8k|    sum->i = h1->i + h2->i;
  131|  47.8k|    sum->j = h1->j + h2->j;
  132|  47.8k|    sum->k = h1->k + h2->k;
  133|  47.8k|}
faceijk.c:_ijkNormalize:
  207|  28.1k|static inline void _ijkNormalize(CoordIJK *c) {
  208|       |    // remove any negative values
  209|  28.1k|    if (c->i < 0) {
  ------------------
  |  Branch (209:9): [True: 0, False: 28.1k]
  ------------------
  210|      0|        c->j -= c->i;
  211|      0|        c->k -= c->i;
  212|      0|        c->i = 0;
  213|      0|    }
  214|       |
  215|  28.1k|    if (c->j < 0) {
  ------------------
  |  Branch (215:9): [True: 0, False: 28.1k]
  ------------------
  216|      0|        c->i -= c->j;
  217|      0|        c->k -= c->j;
  218|      0|        c->j = 0;
  219|      0|    }
  220|       |
  221|  28.1k|    if (c->k < 0) {
  ------------------
  |  Branch (221:9): [True: 0, False: 28.1k]
  ------------------
  222|      0|        c->i -= c->k;
  223|      0|        c->j -= c->k;
  224|      0|        c->k = 0;
  225|      0|    }
  226|       |
  227|       |    // remove the min value if needed
  228|  28.1k|    int min = c->i;
  229|  28.1k|    if (c->j < min) min = c->j;
  ------------------
  |  Branch (229:9): [True: 12.4k, False: 15.7k]
  ------------------
  230|  28.1k|    if (c->k < min) min = c->k;
  ------------------
  |  Branch (230:9): [True: 10.3k, False: 17.7k]
  ------------------
  231|  28.1k|    if (min > 0) {
  ------------------
  |  Branch (231:9): [True: 26.5k, False: 1.60k]
  ------------------
  232|  26.5k|        c->i -= min;
  233|  26.5k|        c->j -= min;
  234|  26.5k|        c->k -= min;
  235|  26.5k|    }
  236|  28.1k|}
faceijk.c:_downAp3:
  557|    561|static inline void _downAp3(CoordIJK *ijk) {
  558|       |    // res r unit vectors in res r+1
  559|    561|    CoordIJK iVec = {2, 0, 1};
  560|    561|    CoordIJK jVec = {1, 2, 0};
  561|    561|    CoordIJK kVec = {0, 1, 2};
  562|       |
  563|    561|    _ijkScale(&iVec, ijk->i);
  564|    561|    _ijkScale(&jVec, ijk->j);
  565|    561|    _ijkScale(&kVec, ijk->k);
  566|       |
  567|    561|    _ijkAdd(&iVec, &jVec, ijk);
  568|    561|    _ijkAdd(ijk, &kVec, ijk);
  569|       |
  570|    561|    _ijkNormalize(ijk);
  571|    561|}
faceijk.c:_downAp3r:
  579|    561|static inline void _downAp3r(CoordIJK *ijk) {
  580|       |    // res r unit vectors in res r+1
  581|    561|    CoordIJK iVec = {2, 1, 0};
  582|    561|    CoordIJK jVec = {0, 2, 1};
  583|    561|    CoordIJK kVec = {1, 0, 2};
  584|       |
  585|    561|    _ijkScale(&iVec, ijk->i);
  586|    561|    _ijkScale(&jVec, ijk->j);
  587|    561|    _ijkScale(&kVec, ijk->k);
  588|       |
  589|    561|    _ijkAdd(&iVec, &jVec, ijk);
  590|    561|    _ijkAdd(ijk, &kVec, ijk);
  591|       |
  592|    561|    _ijkNormalize(ijk);
  593|    561|}
faceijk.c:_downAp7r:
  534|    409|static inline void _downAp7r(CoordIJK *ijk) {
  535|       |    // res r unit vectors in res r+1
  536|    409|    CoordIJK iVec = {3, 1, 0};
  537|    409|    CoordIJK jVec = {0, 3, 1};
  538|    409|    CoordIJK kVec = {1, 0, 3};
  539|       |
  540|    409|    _ijkScale(&iVec, ijk->i);
  541|    409|    _ijkScale(&jVec, ijk->j);
  542|    409|    _ijkScale(&kVec, ijk->k);
  543|       |
  544|    409|    _ijkAdd(&iVec, &jVec, ijk);
  545|    409|    _ijkAdd(ijk, &kVec, ijk);
  546|       |
  547|    409|    _ijkNormalize(ijk);
  548|    409|}
faceijk.c:_setIJK:
  103|    538|static inline void _setIJK(CoordIJK *ijk, int i, int j, int k) {
  104|    538|    ijk->i = i;
  105|    538|    ijk->j = j;
  106|    538|    ijk->k = k;
  107|    538|}
faceijk.c:_ijkSub:
  143|    538|                           CoordIJK *diff) {
  144|    538|    diff->i = h1->i - h2->i;
  145|    538|    diff->j = h1->j - h2->j;
  146|    538|    diff->k = h1->k - h2->k;
  147|    538|}
faceijk.c:_ijkRotate60cw:
  635|    538|static inline void _ijkRotate60cw(CoordIJK *ijk) {
  636|       |    // unit vector rotations
  637|    538|    CoordIJK iVec = {1, 0, 1};
  638|    538|    CoordIJK jVec = {1, 1, 0};
  639|    538|    CoordIJK kVec = {0, 1, 1};
  640|       |
  641|    538|    _ijkScale(&iVec, ijk->i);
  642|    538|    _ijkScale(&jVec, ijk->j);
  643|    538|    _ijkScale(&kVec, ijk->k);
  644|       |
  645|    538|    _ijkAdd(&iVec, &jVec, ijk);
  646|    538|    _ijkAdd(ijk, &kVec, ijk);
  647|       |
  648|    538|    _ijkNormalize(ijk);
  649|    538|}
h3Index.c:_rotate60ccw:
  656|  11.7k|static inline Direction _rotate60ccw(Direction digit) {
  657|  11.7k|    switch (digit) {
  658|  2.45k|        case K_AXES_DIGIT:
  ------------------
  |  Branch (658:9): [True: 2.45k, False: 9.27k]
  ------------------
  659|  2.45k|            return IK_AXES_DIGIT;
  660|  1.87k|        case IK_AXES_DIGIT:
  ------------------
  |  Branch (660:9): [True: 1.87k, False: 9.85k]
  ------------------
  661|  1.87k|            return I_AXES_DIGIT;
  662|  1.46k|        case I_AXES_DIGIT:
  ------------------
  |  Branch (662:9): [True: 1.46k, False: 10.2k]
  ------------------
  663|  1.46k|            return IJ_AXES_DIGIT;
  664|  1.38k|        case IJ_AXES_DIGIT:
  ------------------
  |  Branch (664:9): [True: 1.38k, False: 10.3k]
  ------------------
  665|  1.38k|            return J_AXES_DIGIT;
  666|  1.77k|        case J_AXES_DIGIT:
  ------------------
  |  Branch (666:9): [True: 1.77k, False: 9.95k]
  ------------------
  667|  1.77k|            return JK_AXES_DIGIT;
  668|  2.36k|        case JK_AXES_DIGIT:
  ------------------
  |  Branch (668:9): [True: 2.36k, False: 9.36k]
  ------------------
  669|  2.36k|            return K_AXES_DIGIT;
  670|    396|        default:
  ------------------
  |  Branch (670:9): [True: 396, False: 11.3k]
  ------------------
  671|    396|            return digit;
  672|  11.7k|    }
  673|  11.7k|}
h3Index.c:_rotate60cw:
  680|  7.46k|static inline Direction _rotate60cw(Direction digit) {
  681|  7.46k|    switch (digit) {
  682|  1.05k|        case K_AXES_DIGIT:
  ------------------
  |  Branch (682:9): [True: 1.05k, False: 6.41k]
  ------------------
  683|  1.05k|            return JK_AXES_DIGIT;
  684|    628|        case JK_AXES_DIGIT:
  ------------------
  |  Branch (684:9): [True: 628, False: 6.84k]
  ------------------
  685|    628|            return J_AXES_DIGIT;
  686|    495|        case J_AXES_DIGIT:
  ------------------
  |  Branch (686:9): [True: 495, False: 6.97k]
  ------------------
  687|    495|            return IJ_AXES_DIGIT;
  688|    990|        case IJ_AXES_DIGIT:
  ------------------
  |  Branch (688:9): [True: 990, False: 6.47k]
  ------------------
  689|    990|            return I_AXES_DIGIT;
  690|    751|        case I_AXES_DIGIT:
  ------------------
  |  Branch (690:9): [True: 751, False: 6.71k]
  ------------------
  691|    751|            return IK_AXES_DIGIT;
  692|  1.55k|        case IK_AXES_DIGIT:
  ------------------
  |  Branch (692:9): [True: 1.55k, False: 5.91k]
  ------------------
  693|  1.55k|            return K_AXES_DIGIT;
  694|  1.99k|        default:
  ------------------
  |  Branch (694:9): [True: 1.99k, False: 5.47k]
  ------------------
  695|  1.99k|            return digit;
  696|  7.46k|    }
  697|  7.46k|}
h3Index.c:_downAp7:
  512|  41.0k|static inline void _downAp7(CoordIJK *ijk) {
  513|       |    // res r unit vectors in res r+1
  514|  41.0k|    CoordIJK iVec = {3, 0, 1};
  515|  41.0k|    CoordIJK jVec = {1, 3, 0};
  516|  41.0k|    CoordIJK kVec = {0, 1, 3};
  517|       |
  518|  41.0k|    _ijkScale(&iVec, ijk->i);
  519|  41.0k|    _ijkScale(&jVec, ijk->j);
  520|  41.0k|    _ijkScale(&kVec, ijk->k);
  521|       |
  522|  41.0k|    _ijkAdd(&iVec, &jVec, ijk);
  523|  41.0k|    _ijkAdd(ijk, &kVec, ijk);
  524|       |
  525|  41.0k|    _ijkNormalize(ijk);
  526|  41.0k|}
h3Index.c:_ijkScale:
  155|   245k|static inline void _ijkScale(CoordIJK *c, int factor) {
  156|   245k|    c->i *= factor;
  157|   245k|    c->j *= factor;
  158|   245k|    c->k *= factor;
  159|   245k|}
h3Index.c:_ijkAdd:
  129|   221k|                           CoordIJK *sum) {
  130|   221k|    sum->i = h1->i + h2->i;
  131|   221k|    sum->j = h1->j + h2->j;
  132|   221k|    sum->k = h1->k + h2->k;
  133|   221k|}
h3Index.c:_upAp7r:
  494|  2.79k|static inline void _upAp7r(CoordIJK *ijk) {
  495|       |    // convert to CoordIJ
  496|  2.79k|    int i = ijk->i - ijk->k;
  497|  2.79k|    int j = ijk->j - ijk->k;
  498|       |
  499|  2.79k|    ijk->i = (int)lround((2 * i + j) * M_ONESEVENTH);
  ------------------
  |  |   62|  2.79k|#define M_ONESEVENTH 0.14285714285714285714285714285714285
  ------------------
  500|  2.79k|    ijk->j = (int)lround((3 * j - i) * M_ONESEVENTH);
  ------------------
  |  |   62|  2.79k|#define M_ONESEVENTH 0.14285714285714285714285714285714285
  ------------------
  501|  2.79k|    ijk->k = 0;
  502|  2.79k|    _ijkNormalize(ijk);
  503|  2.79k|}
h3Index.c:_downAp7r:
  534|  40.8k|static inline void _downAp7r(CoordIJK *ijk) {
  535|       |    // res r unit vectors in res r+1
  536|  40.8k|    CoordIJK iVec = {3, 1, 0};
  537|  40.8k|    CoordIJK jVec = {0, 3, 1};
  538|  40.8k|    CoordIJK kVec = {1, 0, 3};
  539|       |
  540|  40.8k|    _ijkScale(&iVec, ijk->i);
  541|  40.8k|    _ijkScale(&jVec, ijk->j);
  542|  40.8k|    _ijkScale(&kVec, ijk->k);
  543|       |
  544|  40.8k|    _ijkAdd(&iVec, &jVec, ijk);
  545|  40.8k|    _ijkAdd(ijk, &kVec, ijk);
  546|       |
  547|  40.8k|    _ijkNormalize(ijk);
  548|  40.8k|}
h3Index.c:_ijkNormalize:
  207|   142k|static inline void _ijkNormalize(CoordIJK *c) {
  208|       |    // remove any negative values
  209|   142k|    if (c->i < 0) {
  ------------------
  |  Branch (209:9): [True: 925, False: 141k]
  ------------------
  210|    925|        c->j -= c->i;
  211|    925|        c->k -= c->i;
  212|    925|        c->i = 0;
  213|    925|    }
  214|       |
  215|   142k|    if (c->j < 0) {
  ------------------
  |  Branch (215:9): [True: 940, False: 141k]
  ------------------
  216|    940|        c->i -= c->j;
  217|    940|        c->k -= c->j;
  218|    940|        c->j = 0;
  219|    940|    }
  220|       |
  221|   142k|    if (c->k < 0) {
  ------------------
  |  Branch (221:9): [True: 0, False: 142k]
  ------------------
  222|      0|        c->i -= c->k;
  223|      0|        c->j -= c->k;
  224|      0|        c->k = 0;
  225|      0|    }
  226|       |
  227|       |    // remove the min value if needed
  228|   142k|    int min = c->i;
  229|   142k|    if (c->j < min) min = c->j;
  ------------------
  |  Branch (229:9): [True: 97.3k, False: 45.4k]
  ------------------
  230|   142k|    if (c->k < min) min = c->k;
  ------------------
  |  Branch (230:9): [True: 36.9k, False: 105k]
  ------------------
  231|   142k|    if (min > 0) {
  ------------------
  |  Branch (231:9): [True: 94.3k, False: 48.4k]
  ------------------
  232|  94.3k|        c->i -= min;
  233|  94.3k|        c->j -= min;
  234|  94.3k|        c->k -= min;
  235|  94.3k|    }
  236|   142k|}
h3Index.c:_neighbor:
  602|  76.2k|static inline void _neighbor(CoordIJK *ijk, Direction digit) {
  603|  76.2k|    if (digit > CENTER_DIGIT && digit < NUM_DIGITS) {
  ------------------
  |  Branch (603:9): [True: 61.4k, False: 14.8k]
  |  Branch (603:33): [True: 58.0k, False: 3.35k]
  ------------------
  604|  58.0k|        _ijkAdd(ijk, &UNIT_VECS[digit], ijk);
  605|  58.0k|        _ijkNormalize(ijk);
  606|  58.0k|    }
  607|  76.2k|}

faceijk.c:vec3LinComb:
   65|  1.68k|static inline Vec3d vec3LinComb(double a, Vec3d v1, double b, Vec3d v2) {
   66|  1.68k|    Vec3d out = {
   67|  1.68k|        .x = a * v1.x + b * v2.x,
   68|  1.68k|        .y = a * v1.y + b * v2.y,
   69|  1.68k|        .z = a * v1.z + b * v2.z,
   70|  1.68k|    };
   71|  1.68k|    return out;
   72|  1.68k|}
faceijk.c:vec3NormSq:
   87|  1.12k|static inline double vec3NormSq(Vec3d v) { return vec3Dot(v, v); }
faceijk.c:vec3Dot:
   83|  1.68k|static inline double vec3Dot(Vec3d v1, Vec3d v2) {
   84|  1.68k|    return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
   85|  1.68k|}
faceijk.c:vec3Cross:
   74|    561|static inline Vec3d vec3Cross(Vec3d v1, Vec3d v2) {
   75|    561|    Vec3d out = {
   76|    561|        .x = v1.y * v2.z - v1.z * v2.y,
   77|    561|        .y = v1.z * v2.x - v1.x * v2.z,
   78|    561|        .z = v1.x * v2.y - v1.y * v2.x,
   79|    561|    };
   80|    561|    return out;
   81|    561|}
faceijk.c:vec3Normalize:
   91|  1.12k|static inline void vec3Normalize(Vec3d *v) {
   92|  1.12k|    double norm = vec3Norm(*v);
   93|       |
   94|       |    // Norm can be zero either from true zero vector, or from squaring
   95|       |    // underflowing to zero.
   96|       |    // If the norm is nonzero, we normalize v using it.
   97|       |    // If the norm is zero, we set the vector to be exactly zero.
   98|  1.12k|    double s = 0.0;
   99|  1.12k|    if (norm > 0.0) {
  ------------------
  |  Branch (99:9): [True: 1.12k, False: 0]
  ------------------
  100|  1.12k|        s = 1.0 / norm;
  101|  1.12k|    }
  102|       |
  103|  1.12k|    v->x *= s;
  104|  1.12k|    v->y *= s;
  105|  1.12k|    v->z *= s;
  106|  1.12k|}
faceijk.c:vec3Norm:
   89|  1.12k|static inline double vec3Norm(Vec3d v) { return sqrt(vec3NormSq(v)); }
faceijk.c:vec3ToLatLng:
   54|    561|static inline LatLng vec3ToLatLng(Vec3d v) {
   55|    561|    LatLng out = {
   56|       |        // atan2 rather than asin(z): near the poles asin loses about
   57|       |        // 1/cos(lat) in precision because it recovers cos(lat) from 1 - z^2,
   58|       |        // while sqrt(x^2 + y^2) is cos(lat) at full precision.
   59|    561|        .lat = atan2(v.z, sqrt(v.x * v.x + v.y * v.y)),
   60|    561|        .lng = atan2(v.y, v.x),
   61|    561|    };
   62|    561|    return out;
   63|    561|}

h3NeighborRotations:
  458|  5.90k|                            H3Index *out) {
  459|  5.90k|    H3Index current = origin;
  460|       |
  461|  5.90k|    if (dir < CENTER_DIGIT || dir >= INVALID_DIGIT) {
  ------------------
  |  Branch (461:9): [True: 0, False: 5.90k]
  |  Branch (461:31): [True: 0, False: 5.90k]
  ------------------
  462|      0|        return E_FAILED;
  463|      0|    }
  464|       |    // Ensure that rotations is modulo'd by 6 before any possible addition,
  465|       |    // to protect against signed integer overflow.
  466|  5.90k|    *rotations = *rotations % 6;
  467|  5.90k|    for (int i = 0; i < *rotations; i++) {
  ------------------
  |  Branch (467:21): [True: 0, False: 5.90k]
  ------------------
  468|      0|        dir = _rotate60ccw(dir);
  469|      0|    }
  470|       |
  471|  5.90k|    int newRotations = 0;
  472|  5.90k|    int oldBaseCell = H3_GET_BASE_CELL(current);
  ------------------
  |  |  120|  5.90k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  5.90k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  5.90k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  5.90k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  473|  5.90k|    if (NEVER(oldBaseCell < 0) || oldBaseCell >= NUM_BASE_CELLS) {
  ------------------
  |  |  119|  11.8k|#define NEVER(X) ((X) ? (assert(0), 1) : 0)
  |  |  ------------------
  |  |  |  Branch (119:18): [True: 0, False: 5.90k]
  |  |  |  Branch (119:19): [True: 0, False: 5.90k]
  |  |  ------------------
  ------------------
                  if (NEVER(oldBaseCell < 0) || oldBaseCell >= NUM_BASE_CELLS) {
  ------------------
  |  |   89|  5.90k|#define NUM_BASE_CELLS 122
  ------------------
  |  Branch (473:9): [Folded, False: 0]
  |  Branch (473:9): [Folded, False: 0]
  |  Branch (473:35): [True: 0, False: 5.90k]
  ------------------
  474|       |        // Base cells less than zero can not be represented in an index
  475|      0|        return E_CELL_INVALID;
  476|      0|    }
  477|  5.90k|    Direction oldLeadingDigit = _h3LeadingNonZeroDigit(current);
  478|       |
  479|       |    // Adjust the indexing digits and, if needed, the base cell.
  480|  5.90k|    int r = H3_GET_RESOLUTION(current) - 1;
  ------------------
  |  |  131|  5.90k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  5.90k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  5.90k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  5.90k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  481|  16.7k|    while (true) {
  ------------------
  |  Branch (481:12): [True: 16.7k, Folded]
  ------------------
  482|  16.7k|        if (r == -1) {
  ------------------
  |  Branch (482:13): [True: 1.56k, False: 15.1k]
  ------------------
  483|  1.56k|            H3_SET_BASE_CELL(current, baseCellNeighbors[oldBaseCell][dir]);
  ------------------
  |  |  126|  1.56k|    (h3) = (((h3) & H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))
  |  |  ------------------
  |  |  |  |   65|  1.56k|#define H3_BC_MASK_NEGATIVE (~H3_BC_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   62|  1.56k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   38|  1.56k|#define H3_BC_OFFSET 45
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (h3) = (((h3) & H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))
  |  |  ------------------
  |  |  |  |   38|  1.56k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  484|  1.56k|            newRotations = baseCellNeighbor60CCWRots[oldBaseCell][dir];
  485|       |
  486|  1.56k|            if (H3_GET_BASE_CELL(current) == INVALID_BASE_CELL) {
  ------------------
  |  |  120|  1.56k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  1.56k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  1.56k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  1.56k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
                          if (H3_GET_BASE_CELL(current) == INVALID_BASE_CELL) {
  ------------------
  |  |   38|  1.56k|#define INVALID_BASE_CELL 127
  ------------------
  |  Branch (486:17): [True: 42, False: 1.51k]
  ------------------
  487|       |                // Adjust for the deleted k vertex at the base cell level.
  488|       |                // This edge actually borders a different neighbor.
  489|     42|                H3_SET_BASE_CELL(current,
  ------------------
  |  |  126|     42|    (h3) = (((h3) & H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))
  |  |  ------------------
  |  |  |  |   65|     42|#define H3_BC_MASK_NEGATIVE (~H3_BC_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   62|     42|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   38|     42|#define H3_BC_OFFSET 45
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (h3) = (((h3) & H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))
  |  |  ------------------
  |  |  |  |   38|     42|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  490|     42|                                 baseCellNeighbors[oldBaseCell][IK_AXES_DIGIT]);
  491|     42|                newRotations =
  492|     42|                    baseCellNeighbor60CCWRots[oldBaseCell][IK_AXES_DIGIT];
  493|       |
  494|       |                // perform the adjustment for the k-subsequence we're skipping
  495|       |                // over.
  496|     42|                current = _h3Rotate60ccw(current);
  497|     42|                *rotations = *rotations + 1;
  498|     42|            }
  499|       |
  500|  1.56k|            break;
  501|  15.1k|        } else {
  502|  15.1k|            Direction oldDigit = H3_GET_INDEX_DIGIT(current, r + 1);
  ------------------
  |  |  144|  15.1k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  15.1k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  15.1k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|  15.1k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  15.1k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
  503|  15.1k|            Direction nextDir;
  504|  15.1k|            if (oldDigit == INVALID_DIGIT) {
  ------------------
  |  Branch (504:17): [True: 66, False: 15.1k]
  ------------------
  505|       |                // Only possible on invalid input
  506|     66|                return E_CELL_INVALID;
  507|  15.1k|            } else if (isResolutionClassIII(r + 1)) {
  ------------------
  |  Branch (507:24): [True: 8.77k, False: 6.32k]
  ------------------
  508|  8.77k|                H3_SET_INDEX_DIGIT(current, r + 1, NEW_DIGIT_II[oldDigit][dir]);
  ------------------
  |  |  165|  8.77k|    (h3) = (((h3) & ~((H3_DIGIT_MASK                                        \
  |  |  ------------------
  |  |  |  |   80|  8.77k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  |  |  166|  8.77k|                       << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   84|  8.77k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                                      << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   47|  8.77k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  167|  8.77k|            (((uint64_t)(digit))                                            \
  |  |  168|  8.77k|             << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   84|  8.77k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                            << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   47|  8.77k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  ------------------
  509|  8.77k|                nextDir = NEW_ADJUSTMENT_II[oldDigit][dir];
  510|  8.77k|            } else {
  511|  6.32k|                H3_SET_INDEX_DIGIT(current, r + 1,
  ------------------
  |  |  165|  6.32k|    (h3) = (((h3) & ~((H3_DIGIT_MASK                                        \
  |  |  ------------------
  |  |  |  |   80|  6.32k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  |  |  166|  6.32k|                       << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   84|  6.32k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                                      << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   47|  6.32k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  167|  6.32k|            (((uint64_t)(digit))                                            \
  |  |  168|  6.32k|             << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   84|  6.32k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                            << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   47|  6.32k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  ------------------
  512|  6.32k|                                   NEW_DIGIT_III[oldDigit][dir]);
  513|  6.32k|                nextDir = NEW_ADJUSTMENT_III[oldDigit][dir];
  514|  6.32k|            }
  515|       |
  516|  15.1k|            if (nextDir != CENTER_DIGIT) {
  ------------------
  |  Branch (516:17): [True: 10.8k, False: 4.27k]
  ------------------
  517|  10.8k|                dir = nextDir;
  518|  10.8k|                r--;
  519|  10.8k|            } else {
  520|       |                // No more adjustment to perform
  521|  4.27k|                break;
  522|  4.27k|            }
  523|  15.1k|        }
  524|  16.7k|    }
  525|       |
  526|  5.83k|    int newBaseCell = H3_GET_BASE_CELL(current);
  ------------------
  |  |  120|  5.83k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  5.83k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  5.83k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  5.83k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  527|  5.83k|    if (_isBaseCellPentagon(newBaseCell)) {
  ------------------
  |  Branch (527:9): [True: 2.82k, False: 3.00k]
  ------------------
  528|  2.82k|        int alreadyAdjustedKSubsequence = 0;
  529|       |
  530|       |        // force rotation out of missing k-axes sub-sequence
  531|  2.82k|        if (_h3LeadingNonZeroDigit(current) == K_AXES_DIGIT) {
  ------------------
  |  Branch (531:13): [True: 262, False: 2.56k]
  ------------------
  532|    262|            if (oldBaseCell != newBaseCell) {
  ------------------
  |  Branch (532:17): [True: 100, False: 162]
  ------------------
  533|       |                // in this case, we traversed into the deleted
  534|       |                // k subsequence of a pentagon base cell.
  535|       |                // We need to rotate out of that case depending
  536|       |                // on how we got here.
  537|       |                // check for a cw/ccw offset face; default is ccw
  538|       |
  539|    100|                if (ALWAYS(_baseCellIsCwOffset(
  ------------------
  |  |  118|    100|#define ALWAYS(X) ((X) ? 1 : (assert(0), 0))
  |  |  ------------------
  |  |  |  Branch (118:19): [True: 100, False: 0]
  |  |  |  Branch (118:20): [True: 100, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (539:21): [Folded, False: 0]
  |  Branch (539:21): [Folded, False: 0]
  ------------------
  540|    100|                        newBaseCell,
  541|    100|                        baseCellData[oldBaseCell].homeFijk.face))) {
  542|    100|                    current = _h3Rotate60cw(current);
  543|    100|                } else {
  544|       |                    // See cwOffsetPent in testGridDisk.c for why this is
  545|       |                    // unreachable.
  546|      0|                    current = _h3Rotate60ccw(current);
  547|      0|                }
  548|    100|                alreadyAdjustedKSubsequence = 1;
  549|    162|            } else {
  550|       |                // In this case, we traversed into the deleted
  551|       |                // k subsequence from within the same pentagon
  552|       |                // base cell.
  553|    162|                if (oldLeadingDigit == CENTER_DIGIT) {
  ------------------
  |  Branch (553:21): [True: 0, False: 162]
  ------------------
  554|       |                    // Undefined: the k direction is deleted from here
  555|      0|                    return E_PENTAGON;
  556|    162|                } else if (oldLeadingDigit == JK_AXES_DIGIT) {
  ------------------
  |  Branch (556:28): [True: 58, False: 104]
  ------------------
  557|       |                    // Rotate out of the deleted k subsequence
  558|       |                    // We also need an additional change to the direction we're
  559|       |                    // moving in
  560|     58|                    current = _h3Rotate60ccw(current);
  561|     58|                    *rotations = *rotations + 1;
  562|    104|                } else if (oldLeadingDigit == IK_AXES_DIGIT) {
  ------------------
  |  Branch (562:28): [True: 71, False: 33]
  ------------------
  563|       |                    // Rotate out of the deleted k subsequence
  564|       |                    // We also need an additional change to the direction we're
  565|       |                    // moving in
  566|     71|                    current = _h3Rotate60cw(current);
  567|     71|                    *rotations = *rotations + 5;
  568|     71|                } else {
  569|       |                    // Could occur on invalid inputs that were already within
  570|       |                    // the deleted k subsequence
  571|     33|                    return E_FAILED;
  572|     33|                }
  573|    162|            }
  574|    262|        }
  575|       |
  576|  3.47k|        for (int i = 0; i < newRotations; i++)
  ------------------
  |  Branch (576:25): [True: 684, False: 2.79k]
  ------------------
  577|    684|            current = _h3RotatePent60ccw(current);
  578|       |
  579|       |        // Account for differing orientation of the base cells (this edge
  580|       |        // might not follow properties of some other edges.)
  581|  2.79k|        if (oldBaseCell != newBaseCell) {
  ------------------
  |  Branch (581:13): [True: 430, False: 2.36k]
  ------------------
  582|    430|            if (_isBaseCellPolarPentagon(newBaseCell)) {
  ------------------
  |  Branch (582:17): [True: 217, False: 213]
  ------------------
  583|       |                // 'polar' base cells behave differently because they have all
  584|       |                // i neighbors.
  585|    217|                if (oldBaseCell != 118 && oldBaseCell != 8 &&
  ------------------
  |  Branch (585:21): [True: 181, False: 36]
  |  Branch (585:43): [True: 157, False: 24]
  ------------------
  586|    157|                    _h3LeadingNonZeroDigit(current) != JK_AXES_DIGIT) {
  ------------------
  |  Branch (586:21): [True: 116, False: 41]
  ------------------
  587|    116|                    *rotations = *rotations + 1;
  588|    116|                }
  589|    217|            } else if (_h3LeadingNonZeroDigit(current) == IK_AXES_DIGIT &&
  ------------------
  |  Branch (589:24): [True: 92, False: 121]
  ------------------
  590|     92|                       !alreadyAdjustedKSubsequence) {
  ------------------
  |  Branch (590:24): [True: 29, False: 63]
  ------------------
  591|       |                // account for distortion introduced to the 5 neighbor by the
  592|       |                // deleted k subsequence.
  593|     29|                *rotations = *rotations + 1;
  594|     29|            }
  595|    430|        }
  596|  3.00k|    } else {
  597|  5.06k|        for (int i = 0; i < newRotations; i++)
  ------------------
  |  Branch (597:25): [True: 2.05k, False: 3.00k]
  ------------------
  598|  2.05k|            current = _h3Rotate60ccw(current);
  599|  3.00k|    }
  600|       |
  601|  5.80k|    *rotations = (*rotations + newRotations) % 6;
  602|  5.80k|    *out = current;
  603|       |
  604|  5.80k|    return E_SUCCESS;
  605|  5.83k|}
directionForNeighbor:
  615|    158|Direction directionForNeighbor(H3Index origin, H3Index destination) {
  616|    158|    bool isPent = H3_EXPORT(isPentagon)(origin);
  ------------------
  |  |   36|    158|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    158|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    158|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|       |    // Checks each neighbor, in order, to determine which direction the
  618|       |    // destination neighbor is located. Skips CENTER_DIGIT since that
  619|       |    // would be the origin; skips deleted K direction for pentagons.
  620|    158|    for (Direction direction = isPent ? J_AXES_DIGIT : K_AXES_DIGIT;
  ------------------
  |  Branch (620:32): [True: 158, False: 0]
  ------------------
  621|    637|         direction < NUM_DIGITS; direction++) {
  ------------------
  |  Branch (621:10): [True: 617, False: 20]
  ------------------
  622|    617|        H3Index neighbor;
  623|    617|        int rotations = 0;
  624|    617|        H3Error neighborError =
  625|    617|            h3NeighborRotations(origin, direction, &rotations, &neighbor);
  626|    617|        if (!neighborError && neighbor == destination) {
  ------------------
  |  Branch (626:13): [True: 617, False: 0]
  |  Branch (626:31): [True: 138, False: 479]
  ------------------
  627|    138|            return direction;
  628|    138|        }
  629|    617|    }
  630|     20|    return INVALID_DIGIT;
  631|    158|}

_isBaseCellPentagon:
  824|  54.2k|int _isBaseCellPentagon(int baseCell) {
  825|  54.2k|    if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) {
  ------------------
  |  |   89|  54.2k|#define NUM_BASE_CELLS 122
  ------------------
  |  Branch (825:9): [True: 0, False: 54.2k]
  |  Branch (825:25): [True: 58, False: 54.1k]
  ------------------
  826|       |        // Base cells less than zero can not be represented in an index
  827|     58|        return false;
  828|     58|    }
  829|  54.1k|    return baseCellData[baseCell].isPentagon;
  830|  54.2k|}
_isBaseCellPolarPentagon:
  834|  2.86k|bool _isBaseCellPolarPentagon(int baseCell) {
  835|  2.86k|    return baseCell == 4 || baseCell == 117;
  ------------------
  |  Branch (835:12): [True: 580, False: 2.28k]
  |  Branch (835:29): [True: 478, False: 1.81k]
  ------------------
  836|  2.86k|}
_baseCellToFaceIjk:
  866|  7.41k|void _baseCellToFaceIjk(int baseCell, FaceIJK *h) {
  867|  7.41k|    *h = baseCellData[baseCell].homeFijk;
  868|  7.41k|}
_baseCellToCCWrot60:
  877|  7.41k|int _baseCellToCCWrot60(int baseCell, int face) {
  878|  7.41k|    if (face < 0 || face >= NUM_ICOSA_FACES) return INVALID_ROTATIONS;
  ------------------
  |  |   87|  7.41k|#define NUM_ICOSA_FACES 20
  ------------------
                  if (face < 0 || face >= NUM_ICOSA_FACES) return INVALID_ROTATIONS;
  ------------------
  |  |   49|      0|#define INVALID_ROTATIONS -1
  ------------------
  |  Branch (878:9): [True: 0, False: 7.41k]
  |  Branch (878:21): [True: 0, False: 7.41k]
  ------------------
  879|  12.6k|    for (int i = 0; i < 3; i++) {
  ------------------
  |  Branch (879:21): [True: 12.6k, False: 0]
  ------------------
  880|  31.7k|        for (int j = 0; j < 3; j++) {
  ------------------
  |  Branch (880:25): [True: 26.5k, False: 5.21k]
  ------------------
  881|  86.7k|            for (int k = 0; k < 3; k++) {
  ------------------
  |  Branch (881:29): [True: 67.5k, False: 19.1k]
  ------------------
  882|  67.5k|                if (faceIjkBaseCells[face][i][j][k].baseCell == baseCell) {
  ------------------
  |  Branch (882:21): [True: 7.41k, False: 60.1k]
  ------------------
  883|  7.41k|                    return faceIjkBaseCells[face][i][j][k].ccwRot60;
  884|  7.41k|                }
  885|  67.5k|            }
  886|  26.5k|        }
  887|  12.6k|    }
  888|      0|    return INVALID_ROTATIONS;
  ------------------
  |  |   49|      0|#define INVALID_ROTATIONS -1
  ------------------
  889|  7.41k|}
_baseCellIsCwOffset:
  893|    100|bool _baseCellIsCwOffset(int baseCell, int testFace) {
  894|    100|    return baseCellData[baseCell].cwOffsetPent[0] == testFace ||
  ------------------
  |  Branch (894:12): [True: 44, False: 56]
  ------------------
  895|     56|           baseCellData[baseCell].cwOffsetPent[1] == testFace;
  ------------------
  |  Branch (895:12): [True: 56, False: 0]
  ------------------
  896|    100|}

getDirectedEdgeOrigin:
  156|    388|H3Error H3_EXPORT(getDirectedEdgeOrigin)(H3Index edge, H3Index *out) {
  157|    388|    if (H3_GET_MODE(edge) != H3_DIRECTEDEDGE_MODE) {
  ------------------
  |  |  108|    388|#define H3_GET_MODE(h3) ((int)((((h3) & H3_MODE_MASK) >> H3_MODE_OFFSET)))
  |  |  ------------------
  |  |  |  |   56|    388|#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   35|    388|#define H3_MODE_OFFSET 59
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_MODE(h3) ((int)((((h3) & H3_MODE_MASK) >> H3_MODE_OFFSET)))
  |  |  ------------------
  |  |  |  |   35|    388|#define H3_MODE_OFFSET 59
  |  |  ------------------
  ------------------
                  if (H3_GET_MODE(edge) != H3_DIRECTEDEDGE_MODE) {
  ------------------
  |  |   99|    388|#define H3_DIRECTEDEDGE_MODE 2
  ------------------
  |  Branch (157:9): [True: 333, False: 55]
  ------------------
  158|    333|        return E_DIR_EDGE_INVALID;
  159|    333|    }
  160|     55|    H3Index origin = edge;
  161|     55|    H3_SET_MODE(origin, H3_CELL_MODE);
  ------------------
  |  |  114|     55|    (h3) =                 \
  |  |  115|     55|        (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   59|     55|#define H3_MODE_MASK_NEGATIVE (~H3_MODE_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   56|     55|#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   35|     55|#define H3_MODE_OFFSET 59
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   35|     55|#define H3_MODE_OFFSET 59
  |  |  ------------------
  ------------------
  162|     55|    H3_SET_RESERVED_BITS(origin, 0);
  ------------------
  |  |  152|     55|    (h3) = (((h3) & H3_RESERVED_MASK_NEGATIVE) | \
  |  |  ------------------
  |  |  |  |   77|     55|#define H3_RESERVED_MASK_NEGATIVE (~H3_RESERVED_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|     55|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|     55|#define H3_RESERVED_OFFSET 56
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  153|     55|            (((uint64_t)(v)) << H3_RESERVED_OFFSET))
  |  |  ------------------
  |  |  |  |   44|     55|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  163|     55|    *out = origin;
  164|     55|    return E_SUCCESS;
  165|    388|}
isValidDirectedEdge:
  189|    574|int H3_EXPORT(isValidDirectedEdge)(H3Index edge) {
  190|    574|    Direction neighborDirection = H3_GET_RESERVED_BITS(edge);
  ------------------
  |  |  159|    574|    ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   74|    574|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    574|#define H3_RESERVED_OFFSET 56
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   44|    574|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  191|    574|    if (neighborDirection <= CENTER_DIGIT || neighborDirection >= NUM_DIGITS) {
  ------------------
  |  Branch (191:9): [True: 127, False: 447]
  |  Branch (191:46): [True: 79, False: 368]
  ------------------
  192|    206|        return 0;
  193|    206|    }
  194|       |
  195|    368|    H3Index origin;
  196|       |    // Note: This call is also checking for H3_DIRECTEDEDGE_MODE
  197|    368|    H3Error originResult = H3_EXPORT(getDirectedEdgeOrigin)(edge, &origin);
  ------------------
  |  |   36|    368|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    368|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    368|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|    368|    if (originResult) {
  ------------------
  |  Branch (198:9): [True: 333, False: 35]
  ------------------
  199|    333|        return 0;
  200|    333|    }
  201|     35|    if (H3_EXPORT(isPentagon)(origin) && neighborDirection == K_AXES_DIGIT) {
  ------------------
  |  |   36|     35|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|     35|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|     35|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (201:9): [True: 6, False: 29]
  |  Branch (201:42): [True: 1, False: 5]
  ------------------
  202|      1|        return 0;
  203|      1|    }
  204|       |
  205|     34|    return H3_EXPORT(isValidCell)(origin);
  ------------------
  |  |   36|     34|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|     34|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|     34|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|     35|}

_faceIjkPentToCellBoundary:
  532|     25|                                int length, CellBoundary *g) {
  533|     25|    int adjRes = res;
  534|     25|    FaceIJK centerIJK = *h;
  535|     25|    FaceIJK fijkVerts[NUM_PENT_VERTS];
  536|     25|    _faceIjkPentToVerts(&centerIJK, &adjRes, fijkVerts);
  537|       |
  538|       |    // If we're returning the entire loop, we need one more iteration in case
  539|       |    // of a distortion vertex on the last edge
  540|     25|    int additionalIteration = length == NUM_PENT_VERTS ? 1 : 0;
  ------------------
  |  |   93|     25|#define NUM_PENT_VERTS 5
  ------------------
  |  Branch (540:31): [True: 0, False: 25]
  ------------------
  541|       |
  542|       |    // convert each vertex to lat/lng
  543|       |    // adjust the face of each vertex as appropriate and introduce
  544|       |    // edge-crossing vertices as needed
  545|     25|    g->numVerts = 0;
  546|     25|    FaceIJK lastFijk = {0};
  547|     50|    for (int vert = start; vert < start + length + additionalIteration;
  ------------------
  |  Branch (547:28): [True: 25, False: 25]
  ------------------
  548|     25|         vert++) {
  549|     25|        int v = vert % NUM_PENT_VERTS;
  ------------------
  |  |   93|     25|#define NUM_PENT_VERTS 5
  ------------------
  550|       |
  551|     25|        FaceIJK fijk = fijkVerts[v];
  552|       |
  553|     25|        _adjustPentVertOverage(&fijk, adjRes);
  554|       |
  555|       |        // all Class III pentagon edges cross icosa edges
  556|       |        // note that Class II pentagons have vertices on the edge,
  557|       |        // not edge intersections
  558|     25|        if (isResolutionClassIII(res) && vert > start) {
  ------------------
  |  Branch (558:13): [True: 10, False: 15]
  |  Branch (558:42): [True: 0, False: 10]
  ------------------
  559|       |            // find hex2d of the two vertexes on the last face
  560|       |
  561|      0|            FaceIJK tmpFijk = fijk;
  562|       |
  563|      0|            Vec2d orig2d0;
  564|      0|            _ijkToHex2d(&lastFijk.coord, &orig2d0);
  565|       |
  566|      0|            int currentToLastDir = adjacentFaceDir[tmpFijk.face][lastFijk.face];
  567|       |
  568|      0|            const FaceOrientIJK *fijkOrient =
  569|      0|                &faceNeighbors[tmpFijk.face][currentToLastDir];
  570|       |
  571|      0|            tmpFijk.face = fijkOrient->face;
  572|      0|            CoordIJK *ijk = &tmpFijk.coord;
  573|       |
  574|       |            // rotate and translate for adjacent face
  575|      0|            for (int i = 0; i < fijkOrient->ccwRot60; i++) _ijkRotate60ccw(ijk);
  ------------------
  |  Branch (575:29): [True: 0, False: 0]
  ------------------
  576|       |
  577|      0|            CoordIJK transVec = fijkOrient->translate;
  578|      0|            _ijkScale(&transVec, unitScaleByCIIres[adjRes] * 3);
  579|      0|            _ijkAdd(ijk, &transVec, ijk);
  580|      0|            _ijkNormalize(ijk);
  581|       |
  582|      0|            Vec2d orig2d1;
  583|      0|            _ijkToHex2d(ijk, &orig2d1);
  584|       |
  585|       |            // find the appropriate icosa face edge vertexes
  586|      0|            int maxDim = maxDimByCIIres[adjRes];
  587|      0|            Vec2d v0 = {3.0 * maxDim, 0.0};
  588|      0|            Vec2d v1 = {-1.5 * maxDim, 3.0 * M_SQRT3_2 * maxDim};
  ------------------
  |  |   52|      0|#define M_SQRT3_2 0.8660254037844386467637231707529361834714
  ------------------
  589|      0|            Vec2d v2 = {-1.5 * maxDim, -3.0 * M_SQRT3_2 * maxDim};
  ------------------
  |  |   52|      0|#define M_SQRT3_2 0.8660254037844386467637231707529361834714
  ------------------
  590|       |
  591|      0|            Vec2d *edge0;
  592|      0|            Vec2d *edge1;
  593|      0|            switch (adjacentFaceDir[tmpFijk.face][fijk.face]) {
  594|      0|                case IJ:
  ------------------
  |  |   53|      0|#define IJ 1
  ------------------
  |  Branch (594:17): [True: 0, False: 0]
  ------------------
  595|      0|                    edge0 = &v0;
  596|      0|                    edge1 = &v1;
  597|      0|                    break;
  598|      0|                case JK:
  ------------------
  |  |   57|      0|#define JK 3
  ------------------
  |  Branch (598:17): [True: 0, False: 0]
  ------------------
  599|      0|                    edge0 = &v1;
  600|      0|                    edge1 = &v2;
  601|      0|                    break;
  602|      0|                case KI:
  ------------------
  |  |   55|      0|#define KI 2
  ------------------
  |  Branch (602:17): [True: 0, False: 0]
  ------------------
  603|      0|                default:
  ------------------
  |  Branch (603:17): [True: 0, False: 0]
  ------------------
  604|      0|                    assert(adjacentFaceDir[tmpFijk.face][fijk.face] == KI);
  ------------------
  |  Branch (604:21): [True: 0, False: 0]
  |  Branch (604:21): [True: 0, False: 0]
  ------------------
  605|      0|                    edge0 = &v2;
  606|      0|                    edge1 = &v0;
  607|      0|                    break;
  608|      0|            }
  609|       |
  610|       |            // find the intersection and add the lat/lng point to the result
  611|      0|            Vec2d inter;
  612|      0|            _v2dIntersect(&orig2d0, &orig2d1, edge0, edge1, &inter);
  613|      0|            Vec3d v3;
  614|      0|            _hex2dToVec3(&inter, tmpFijk.face, adjRes, 1, &v3);
  615|      0|            g->verts[g->numVerts] = vec3ToLatLng(v3);
  616|      0|            g->numVerts++;
  617|      0|        }
  618|       |
  619|       |        // convert vertex to lat/lng and add to the result
  620|       |        // vert == start + NUM_PENT_VERTS is only used to test for possible
  621|       |        // intersection on last edge
  622|     25|        if (vert < start + NUM_PENT_VERTS) {
  ------------------
  |  |   93|     25|#define NUM_PENT_VERTS 5
  ------------------
  |  Branch (622:13): [True: 25, False: 0]
  ------------------
  623|     25|            Vec2d vec;
  624|     25|            _ijkToHex2d(&fijk.coord, &vec);
  625|     25|            Vec3d v3;
  626|     25|            _hex2dToVec3(&vec, fijk.face, adjRes, 1, &v3);
  627|     25|            g->verts[g->numVerts] = vec3ToLatLng(v3);
  628|     25|            g->numVerts++;
  629|     25|        }
  630|       |
  631|     25|        lastFijk = fijk;
  632|     25|    }
  633|     25|}
_faceIjkPentToVerts:
  642|     25|void _faceIjkPentToVerts(FaceIJK *fijk, int *res, FaceIJK *fijkVerts) {
  643|       |    // the vertexes of an origin-centered pentagon in a Class II resolution on a
  644|       |    // substrate grid with aperture sequence 33r. The aperture 3 gets us the
  645|       |    // vertices, and the 3r gets us back to Class II.
  646|       |    // vertices listed ccw from the i-axes
  647|     25|    CoordIJK vertsCII[NUM_PENT_VERTS] = {
  648|     25|        {2, 1, 0},  // 0
  649|     25|        {1, 2, 0},  // 1
  650|     25|        {0, 2, 1},  // 2
  651|     25|        {0, 1, 2},  // 3
  652|     25|        {1, 0, 2},  // 4
  653|     25|    };
  654|       |
  655|       |    // the vertexes of an origin-centered pentagon in a Class III resolution on
  656|       |    // a substrate grid with aperture sequence 33r7r. The aperture 3 gets us the
  657|       |    // vertices, and the 3r7r gets us to Class II. vertices listed ccw from the
  658|       |    // i-axes
  659|     25|    CoordIJK vertsCIII[NUM_PENT_VERTS] = {
  660|     25|        {5, 4, 0},  // 0
  661|     25|        {1, 5, 0},  // 1
  662|     25|        {0, 5, 4},  // 2
  663|     25|        {0, 1, 5},  // 3
  664|     25|        {4, 0, 5},  // 4
  665|     25|    };
  666|       |
  667|       |    // get the correct set of substrate vertices for this resolution
  668|     25|    CoordIJK *verts;
  669|     25|    if (isResolutionClassIII(*res))
  ------------------
  |  Branch (669:9): [True: 10, False: 15]
  ------------------
  670|     10|        verts = vertsCIII;
  671|     15|    else
  672|     15|        verts = vertsCII;
  673|       |
  674|       |    // adjust the center point to be in an aperture 33r substrate grid
  675|       |    // these should be composed for speed
  676|     25|    _downAp3(&fijk->coord);
  677|     25|    _downAp3r(&fijk->coord);
  678|       |
  679|       |    // if res is Class III we need to add a cw aperture 7 to get to
  680|       |    // icosahedral Class II
  681|     25|    if (isResolutionClassIII(*res)) {
  ------------------
  |  Branch (681:9): [True: 10, False: 15]
  ------------------
  682|     10|        _downAp7r(&fijk->coord);
  683|     10|        *res += 1;
  684|     10|    }
  685|       |
  686|       |    // The center point is now in the same substrate grid as the origin
  687|       |    // cell vertices. Add the center point substate coordinates
  688|       |    // to each vertex to translate the vertices to that cell.
  689|    150|    for (int v = 0; v < NUM_PENT_VERTS; v++) {
  ------------------
  |  |   93|    150|#define NUM_PENT_VERTS 5
  ------------------
  |  Branch (689:21): [True: 125, False: 25]
  ------------------
  690|    125|        fijkVerts[v].face = fijk->face;
  691|    125|        _ijkAdd(&fijk->coord, &verts[v], &fijkVerts[v].coord);
  692|    125|        _ijkNormalize(&fijkVerts[v].coord);
  693|    125|    }
  694|     25|}
_faceIjkToCellBoundary:
  707|    536|                            CellBoundary *g) {
  708|    536|    int adjRes = res;
  709|    536|    FaceIJK centerIJK = *h;
  710|    536|    FaceIJK fijkVerts[NUM_HEX_VERTS];
  711|    536|    _faceIjkToVerts(&centerIJK, &adjRes, fijkVerts);
  712|       |
  713|       |    // If we're returning the entire loop, we need one more iteration in case
  714|       |    // of a distortion vertex on the last edge
  715|    536|    int additionalIteration = length == NUM_HEX_VERTS ? 1 : 0;
  ------------------
  |  |   91|    536|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (715:31): [True: 0, False: 536]
  ------------------
  716|       |
  717|       |    // convert each vertex to lat/lng
  718|       |    // adjust the face of each vertex as appropriate and introduce
  719|       |    // edge-crossing vertices as needed
  720|    536|    g->numVerts = 0;
  721|    536|    int lastFace = -1;
  722|    536|    Overage lastOverage = NO_OVERAGE;
  723|  1.07k|    for (int vert = start; vert < start + length + additionalIteration;
  ------------------
  |  Branch (723:28): [True: 536, False: 536]
  ------------------
  724|    536|         vert++) {
  725|    536|        int v = vert % NUM_HEX_VERTS;
  ------------------
  |  |   91|    536|#define NUM_HEX_VERTS 6
  ------------------
  726|       |
  727|    536|        FaceIJK fijk = fijkVerts[v];
  728|       |
  729|    536|        const int pentLeading4 = 0;
  730|    536|        Overage overage = _adjustOverageClassII(&fijk, adjRes, pentLeading4, 1);
  731|       |
  732|       |        /*
  733|       |        Check for edge-crossing. Each face of the underlying icosahedron is a
  734|       |        different projection plane. So if an edge of the hexagon crosses an
  735|       |        icosahedron edge, an additional vertex must be introduced at that
  736|       |        intersection point. Then each half of the cell edge can be projected
  737|       |        to geographic coordinates using the appropriate icosahedron face
  738|       |        projection. Note that Class II cell edges have vertices on the face
  739|       |        edge, with no edge line intersections.
  740|       |        */
  741|    536|        if (isResolutionClassIII(res) && vert > start &&
  ------------------
  |  Branch (741:13): [True: 399, False: 137]
  |  Branch (741:42): [True: 0, False: 399]
  ------------------
  742|      0|            fijk.face != lastFace && lastOverage != FACE_EDGE) {
  ------------------
  |  Branch (742:13): [True: 0, False: 0]
  |  Branch (742:38): [True: 0, False: 0]
  ------------------
  743|       |            // find hex2d of the two vertexes on original face
  744|      0|            int lastV = (v + 5) % NUM_HEX_VERTS;
  ------------------
  |  |   91|      0|#define NUM_HEX_VERTS 6
  ------------------
  745|      0|            Vec2d orig2d0;
  746|      0|            _ijkToHex2d(&fijkVerts[lastV].coord, &orig2d0);
  747|       |
  748|      0|            Vec2d orig2d1;
  749|      0|            _ijkToHex2d(&fijkVerts[v].coord, &orig2d1);
  750|       |
  751|       |            // find the appropriate icosa face edge vertexes
  752|      0|            int maxDim = maxDimByCIIres[adjRes];
  753|      0|            Vec2d v0 = {3.0 * maxDim, 0.0};
  754|      0|            Vec2d v1 = {-1.5 * maxDim, 3.0 * M_SQRT3_2 * maxDim};
  ------------------
  |  |   52|      0|#define M_SQRT3_2 0.8660254037844386467637231707529361834714
  ------------------
  755|      0|            Vec2d v2 = {-1.5 * maxDim, -3.0 * M_SQRT3_2 * maxDim};
  ------------------
  |  |   52|      0|#define M_SQRT3_2 0.8660254037844386467637231707529361834714
  ------------------
  756|       |
  757|      0|            int face2 = ((lastFace == centerIJK.face) ? fijk.face : lastFace);
  ------------------
  |  Branch (757:26): [True: 0, False: 0]
  ------------------
  758|      0|            Vec2d *edge0;
  759|      0|            Vec2d *edge1;
  760|      0|            switch (adjacentFaceDir[centerIJK.face][face2]) {
  761|      0|                case IJ:
  ------------------
  |  |   53|      0|#define IJ 1
  ------------------
  |  Branch (761:17): [True: 0, False: 0]
  ------------------
  762|      0|                    edge0 = &v0;
  763|      0|                    edge1 = &v1;
  764|      0|                    break;
  765|      0|                case JK:
  ------------------
  |  |   57|      0|#define JK 3
  ------------------
  |  Branch (765:17): [True: 0, False: 0]
  ------------------
  766|      0|                    edge0 = &v1;
  767|      0|                    edge1 = &v2;
  768|      0|                    break;
  769|       |                // case KI:
  770|      0|                default:
  ------------------
  |  Branch (770:17): [True: 0, False: 0]
  ------------------
  771|      0|                    assert(adjacentFaceDir[centerIJK.face][face2] == KI);
  ------------------
  |  Branch (771:21): [True: 0, False: 0]
  |  Branch (771:21): [True: 0, False: 0]
  ------------------
  772|      0|                    edge0 = &v2;
  773|      0|                    edge1 = &v0;
  774|      0|                    break;
  775|      0|            }
  776|       |
  777|       |            // find the intersection and add the lat/lng point to the result
  778|      0|            Vec2d inter;
  779|      0|            _v2dIntersect(&orig2d0, &orig2d1, edge0, edge1, &inter);
  780|       |            /*
  781|       |            If a point of intersection occurs at a hexagon vertex, then each
  782|       |            adjacent hexagon edge will lie completely on a single icosahedron
  783|       |            face, and no additional vertex is required.
  784|       |            */
  785|      0|            bool isIntersectionAtVertex = _v2dAlmostEquals(&orig2d0, &inter) ||
  ------------------
  |  Branch (785:43): [True: 0, False: 0]
  ------------------
  786|      0|                                          _v2dAlmostEquals(&orig2d1, &inter);
  ------------------
  |  Branch (786:43): [True: 0, False: 0]
  ------------------
  787|      0|            if (!isIntersectionAtVertex) {
  ------------------
  |  Branch (787:17): [True: 0, False: 0]
  ------------------
  788|      0|                Vec3d v3;
  789|      0|                _hex2dToVec3(&inter, centerIJK.face, adjRes, 1, &v3);
  790|      0|                g->verts[g->numVerts] = vec3ToLatLng(v3);
  791|      0|                g->numVerts++;
  792|      0|            }
  793|      0|        }
  794|       |
  795|       |        // convert vertex to lat/lng and add to the result
  796|       |        // vert == start + NUM_HEX_VERTS is only used to test for possible
  797|       |        // intersection on last edge
  798|    536|        if (vert < start + NUM_HEX_VERTS) {
  ------------------
  |  |   91|    536|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (798:13): [True: 536, False: 0]
  ------------------
  799|    536|            Vec2d vec;
  800|    536|            _ijkToHex2d(&fijk.coord, &vec);
  801|    536|            Vec3d v3;
  802|    536|            _hex2dToVec3(&vec, fijk.face, adjRes, 1, &v3);
  803|    536|            g->verts[g->numVerts] = vec3ToLatLng(v3);
  804|    536|            g->numVerts++;
  805|    536|        }
  806|       |
  807|    536|        lastFace = fijk.face;
  808|    536|        lastOverage = overage;
  809|    536|    }
  810|    536|}
_faceIjkToVerts:
  819|    536|void _faceIjkToVerts(FaceIJK *fijk, int *res, FaceIJK *fijkVerts) {
  820|       |    // the vertexes of an origin-centered cell in a Class II resolution on a
  821|       |    // substrate grid with aperture sequence 33r. The aperture 3 gets us the
  822|       |    // vertices, and the 3r gets us back to Class II.
  823|       |    // vertices listed ccw from the i-axes
  824|    536|    CoordIJK vertsCII[NUM_HEX_VERTS] = {
  825|    536|        {2, 1, 0},  // 0
  826|    536|        {1, 2, 0},  // 1
  827|    536|        {0, 2, 1},  // 2
  828|    536|        {0, 1, 2},  // 3
  829|    536|        {1, 0, 2},  // 4
  830|    536|        {2, 0, 1}   // 5
  831|    536|    };
  832|       |
  833|       |    // the vertexes of an origin-centered cell in a Class III resolution on a
  834|       |    // substrate grid with aperture sequence 33r7r. The aperture 3 gets us the
  835|       |    // vertices, and the 3r7r gets us to Class II.
  836|       |    // vertices listed ccw from the i-axes
  837|    536|    CoordIJK vertsCIII[NUM_HEX_VERTS] = {
  838|    536|        {5, 4, 0},  // 0
  839|    536|        {1, 5, 0},  // 1
  840|    536|        {0, 5, 4},  // 2
  841|    536|        {0, 1, 5},  // 3
  842|    536|        {4, 0, 5},  // 4
  843|    536|        {5, 0, 1}   // 5
  844|    536|    };
  845|       |
  846|       |    // get the correct set of substrate vertices for this resolution
  847|    536|    CoordIJK *verts;
  848|    536|    if (isResolutionClassIII(*res))
  ------------------
  |  Branch (848:9): [True: 399, False: 137]
  ------------------
  849|    399|        verts = vertsCIII;
  850|    137|    else
  851|    137|        verts = vertsCII;
  852|       |
  853|       |    // adjust the center point to be in an aperture 33r substrate grid
  854|       |    // these should be composed for speed
  855|    536|    _downAp3(&fijk->coord);
  856|    536|    _downAp3r(&fijk->coord);
  857|       |
  858|       |    // if res is Class III we need to add a cw aperture 7 to get to
  859|       |    // icosahedral Class II
  860|    536|    if (isResolutionClassIII(*res)) {
  ------------------
  |  Branch (860:9): [True: 399, False: 137]
  ------------------
  861|    399|        _downAp7r(&fijk->coord);
  862|    399|        *res += 1;
  863|    399|    }
  864|       |
  865|       |    // The center point is now in the same substrate grid as the origin
  866|       |    // cell vertices. Add the center point substate coordinates
  867|       |    // to each vertex to translate the vertices to that cell.
  868|  3.75k|    for (int v = 0; v < NUM_HEX_VERTS; v++) {
  ------------------
  |  |   91|  3.75k|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (868:21): [True: 3.21k, False: 536]
  ------------------
  869|  3.21k|        fijkVerts[v].face = fijk->face;
  870|  3.21k|        _ijkAdd(&fijk->coord, &verts[v], &fijkVerts[v].coord);
  871|  3.21k|        _ijkNormalize(&fijkVerts[v].coord);
  872|  3.21k|    }
  873|    536|}
_adjustOverageClassII:
  888|  12.3k|                              int substrate) {
  889|  12.3k|    Overage overage = NO_OVERAGE;
  890|       |
  891|  12.3k|    CoordIJK *ijk = &fijk->coord;
  892|       |
  893|       |    // get the maximum dimension value; scale if a substrate grid
  894|  12.3k|    int maxDim = maxDimByCIIres[res];
  895|  12.3k|    if (substrate) maxDim *= 3;
  ------------------
  |  Branch (895:9): [True: 575, False: 11.8k]
  ------------------
  896|       |
  897|       |    // check for overage
  898|  12.3k|    if (substrate && ijk->i + ijk->j + ijk->k == maxDim)  // on edge
  ------------------
  |  Branch (898:9): [True: 575, False: 11.8k]
  |  Branch (898:22): [True: 69, False: 506]
  ------------------
  899|     69|        overage = FACE_EDGE;
  900|  12.3k|    else if (ijk->i + ijk->j + ijk->k > maxDim)  // overage
  ------------------
  |  Branch (900:14): [True: 5.56k, False: 6.75k]
  ------------------
  901|  5.56k|    {
  902|  5.56k|        overage = NEW_FACE;
  903|       |
  904|  5.56k|        const FaceOrientIJK *fijkOrient;
  905|  5.56k|        if (ijk->k > 0) {
  ------------------
  |  Branch (905:13): [True: 3.58k, False: 1.98k]
  ------------------
  906|  3.58k|            if (ijk->j > 0)  // jk "quadrant"
  ------------------
  |  Branch (906:17): [True: 1.15k, False: 2.42k]
  ------------------
  907|  1.15k|                fijkOrient = &faceNeighbors[fijk->face][JK];
  ------------------
  |  |   57|  1.15k|#define JK 3
  ------------------
  908|  2.42k|            else  // ik "quadrant"
  909|  2.42k|            {
  910|  2.42k|                fijkOrient = &faceNeighbors[fijk->face][KI];
  ------------------
  |  |   55|  2.42k|#define KI 2
  ------------------
  911|       |
  912|       |                // adjust for the pentagonal missing sequence
  913|  2.42k|                if (pentLeading4) {
  ------------------
  |  Branch (913:21): [True: 538, False: 1.88k]
  ------------------
  914|       |                    // translate origin to center of pentagon
  915|    538|                    CoordIJK origin;
  916|    538|                    _setIJK(&origin, maxDim, 0, 0);
  917|    538|                    CoordIJK tmp;
  918|    538|                    _ijkSub(ijk, &origin, &tmp);
  919|       |                    // rotate to adjust for the missing sequence
  920|    538|                    _ijkRotate60cw(&tmp);
  921|       |                    // translate the origin back to the center of the triangle
  922|    538|                    _ijkAdd(&tmp, &origin, ijk);
  923|    538|                }
  924|  2.42k|            }
  925|  3.58k|        } else  // ij "quadrant"
  926|  1.98k|            fijkOrient = &faceNeighbors[fijk->face][IJ];
  ------------------
  |  |   53|  1.98k|#define IJ 1
  ------------------
  927|       |
  928|  5.56k|        fijk->face = fijkOrient->face;
  929|       |
  930|       |        // rotate and translate for adjacent face
  931|  22.7k|        for (int i = 0; i < fijkOrient->ccwRot60; i++) _ijkRotate60ccw(ijk);
  ------------------
  |  Branch (931:25): [True: 17.1k, False: 5.56k]
  ------------------
  932|       |
  933|  5.56k|        CoordIJK transVec = fijkOrient->translate;
  934|  5.56k|        int unitScale = unitScaleByCIIres[res];
  935|  5.56k|        if (substrate) unitScale *= 3;
  ------------------
  |  Branch (935:13): [True: 45, False: 5.51k]
  ------------------
  936|  5.56k|        _ijkScale(&transVec, unitScale);
  937|  5.56k|        _ijkAdd(ijk, &transVec, ijk);
  938|  5.56k|        _ijkNormalize(ijk);
  939|       |
  940|       |        // overage points on pentagon boundaries can end up on edges
  941|  5.56k|        if (substrate && ijk->i + ijk->j + ijk->k == maxDim)  // on edge
  ------------------
  |  Branch (941:13): [True: 45, False: 5.51k]
  |  Branch (941:26): [True: 10, False: 35]
  ------------------
  942|     10|            overage = FACE_EDGE;
  943|  5.56k|    }
  944|       |
  945|  12.3k|    return overage;
  946|  12.3k|}
_adjustPentVertOverage:
  956|     25|Overage _adjustPentVertOverage(FaceIJK *fijk, int res) {
  957|     25|    int pentLeading4 = 0;
  958|     25|    Overage overage;
  959|     39|    do {
  960|     39|        overage = _adjustOverageClassII(fijk, res, pentLeading4, 1);
  961|     39|    } while (overage == NEW_FACE);
  ------------------
  |  Branch (961:14): [True: 14, False: 25]
  ------------------
  962|     25|    return overage;
  963|     25|}
faceijk.c:_vec3TangentBasis:
  375|    561|static inline void _vec3TangentBasis(Vec3d p, Vec3d *north, Vec3d *east) {
  376|    561|    Vec3d northPole = {0.0, 0.0, 1.0};
  377|    561|    *north = vec3LinComb(1.0, northPole, -vec3Dot(northPole, p), p);
  378|    561|    vec3Normalize(north);
  379|    561|    *east = vec3Cross(*north, p);
  380|    561|}
faceijk.c:_hex2dToVec3:
  459|    561|                         Vec3d *v3) {
  460|       |    // calculate (r, theta) in hex2d
  461|    561|    double r = _v2dMag(v);
  462|       |
  463|    561|    if (r < EPSILON) {
  ------------------
  |  |   50|    561|#define EPSILON 0.0000000000000001
  ------------------
  |  Branch (463:9): [True: 0, False: 561]
  ------------------
  464|      0|        *v3 = faceCenterPoint[face];
  465|      0|        return;
  466|      0|    }
  467|       |
  468|    561|    double theta = atan2(v->y, v->x);
  469|       |
  470|       |    // scale for current resolution length u
  471|  6.33k|    for (int i = 0; i < res; i++) r *= M_RSQRT7;
  ------------------
  |  |   37|  6.33k|#define M_RSQRT7 0.37796447300922722721451653623418006081576
  ------------------
  |  Branch (471:21): [True: 5.77k, False: 561]
  ------------------
  472|       |
  473|       |    // scale accordingly if this is a substrate grid
  474|    561|    if (substrate) {
  ------------------
  |  Branch (474:9): [True: 561, False: 0]
  ------------------
  475|    561|        r *= M_ONETHIRD;
  ------------------
  |  |   59|    561|#define M_ONETHIRD 0.333333333333333333333333333333333333333
  ------------------
  476|       |        // Never occurs because every case where this function is called with
  477|       |        // substrate=1, the res has been adjusted by _faceIjkPentToVerts, which
  478|       |        // adjusts the res by +1, making it no longer Class III.
  479|    561|        if (NEVER(isResolutionClassIII(res))) {
  ------------------
  |  |  119|    561|#define NEVER(X) ((X) ? (assert(0), 1) : 0)
  |  |  ------------------
  |  |  |  Branch (119:18): [True: 0, False: 561]
  |  |  |  Branch (119:19): [True: 0, False: 561]
  |  |  ------------------
  ------------------
  |  Branch (479:13): [Folded, False: 0]
  |  Branch (479:13): [Folded, False: 0]
  ------------------
  480|      0|            r *= M_RSQRT7;
  ------------------
  |  |   37|      0|#define M_RSQRT7 0.37796447300922722721451653623418006081576
  ------------------
  481|      0|        }
  482|    561|    }
  483|       |
  484|    561|    r *= RES0_U_GNOMONIC;
  ------------------
  |  |   80|    561|#define RES0_U_GNOMONIC 0.38196601125010500003
  ------------------
  485|       |
  486|       |    // perform inverse gnomonic scaling of r
  487|    561|    r = atan(r);
  488|       |
  489|       |    // adjust theta for Class III
  490|       |    // if a substrate grid, then it's already been adjusted for Class III
  491|    561|    if (!substrate && isResolutionClassIII(res))
  ------------------
  |  Branch (491:9): [True: 0, False: 561]
  |  Branch (491:23): [True: 0, False: 0]
  ------------------
  492|      0|        theta = _posAngleRads(theta + M_AP7_ROT_RADS);
  ------------------
  |  |   66|      0|#define M_AP7_ROT_RADS 0.333473172251832115336090755351601070065900389
  ------------------
  493|       |
  494|       |    // find theta as an azimuth
  495|    561|    theta = _posAngleRads(faceAxesAzRadsCII[face][0] - theta);
  496|       |
  497|       |    // now find the point at (r,theta) from the face center
  498|    561|    Vec3d northDir, eastDir;
  499|    561|    _vec3TangentBasis(faceCenterPoint[face], &northDir, &eastDir);
  500|       |
  501|    561|    Vec3d dir = vec3LinComb(cos(theta), northDir, sin(theta), eastDir);
  502|       |
  503|    561|    *v3 = vec3LinComb(cos(r), faceCenterPoint[face], sin(r), dir);
  504|    561|    vec3Normalize(v3);
  505|    561|}

getBaseCellNumber:
   98|  7.41k|int H3_EXPORT(getBaseCellNumber)(H3Index h) { return H3_GET_BASE_CELL(h); }
  ------------------
  |  |  120|  7.41k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  7.41k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  7.41k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  7.41k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
isValidCell:
  343|    261|int H3_EXPORT(isValidCell)(H3Index h) {
  344|       |    /*
  345|       |    Look for bit patterns that would disqualify an H3Index from
  346|       |    being valid. If identified, exit early.
  347|       |
  348|       |    For reference the H3 index bit layout:
  349|       |
  350|       |    |   Region   | # bits |
  351|       |    |------------|--------|
  352|       |    | High       |      1 |
  353|       |    | Mode       |      4 |
  354|       |    | Reserved   |      3 |
  355|       |    | Resolution |      4 |
  356|       |    | Base Cell  |      7 |
  357|       |    | Digit 1    |      3 |
  358|       |    | Digit 2    |      3 |
  359|       |    | ...        |    ... |
  360|       |    | Digit 15   |      3 |
  361|       |
  362|       |    Speed benefits come from using bit manipulation instead of loops,
  363|       |    whenever possible.
  364|       |    */
  365|    261|    if (!_hasGoodTopBits(h)) return false;
  ------------------
  |  Branch (365:9): [True: 7, False: 254]
  ------------------
  366|       |
  367|       |    // No need to check resolution; any 4 bits give a valid resolution.
  368|    254|    const int res = H3_GET_RESOLUTION(h);
  ------------------
  |  |  131|    254|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|    254|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|    254|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|    254|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  369|       |
  370|       |    // Get base cell number and check that it is valid.
  371|    254|    const int bc = H3_GET_BASE_CELL(h);
  ------------------
  |  |  120|    254|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|    254|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|    254|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|    254|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  372|    254|    if (bc >= NUM_BASE_CELLS) return false;
  ------------------
  |  |   89|    254|#define NUM_BASE_CELLS 122
  ------------------
  |  Branch (372:9): [True: 2, False: 252]
  ------------------
  373|       |
  374|    252|    if (_hasAny7UptoRes(h, res)) return false;
  ------------------
  |  Branch (374:9): [True: 35, False: 217]
  ------------------
  375|    217|    if (!_hasAll7AfterRes(h, res)) return false;
  ------------------
  |  Branch (375:9): [True: 68, False: 149]
  ------------------
  376|    149|    if (_hasDeletedSubsequence(h, bc)) return false;
  ------------------
  |  Branch (376:9): [True: 6, False: 143]
  ------------------
  377|       |
  378|       |    // If no disqualifications were identified, the index is a valid H3 cell.
  379|    143|    return true;
  380|    149|}
isPentagon:
  845|  14.6k|int H3_EXPORT(isPentagon)(H3Index h) {
  846|  14.6k|    return _isBaseCellPentagon(H3_GET_BASE_CELL(h)) &&
  ------------------
  |  |  120|  14.6k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  14.6k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  14.6k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  14.6k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  |  Branch (846:12): [True: 6.47k, False: 8.15k]
  ------------------
  847|  6.47k|           !_h3LeadingNonZeroDigit(h);
  ------------------
  |  Branch (847:12): [True: 814, False: 5.65k]
  ------------------
  848|  14.6k|}
_h3LeadingNonZeroDigit:
  855|  30.3k|Direction _h3LeadingNonZeroDigit(H3Index h) {
  856|  89.2k|    for (int r = 1; r <= H3_GET_RESOLUTION(h); r++)
  ------------------
  |  |  131|  89.2k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  89.2k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  89.2k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  89.2k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  |  Branch (856:21): [True: 85.3k, False: 3.92k]
  ------------------
  857|  85.3k|        if (H3_GET_INDEX_DIGIT(h, r)) return H3_GET_INDEX_DIGIT(h, r);
  ------------------
  |  |  144|  85.3k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  85.3k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  85.3k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  |  Branch (144:5): [True: 26.4k, False: 58.9k]
  |  |  ------------------
  |  |  145|  85.3k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  85.3k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
                      if (H3_GET_INDEX_DIGIT(h, r)) return H3_GET_INDEX_DIGIT(h, r);
  ------------------
  |  |  144|  26.4k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  26.4k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  26.4k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|  26.4k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  26.4k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
  858|       |
  859|       |    // if we're here it's all 0's
  860|  3.92k|    return CENTER_DIGIT;
  861|  30.3k|}
_h3RotatePent60ccw:
  867|    684|H3Index _h3RotatePent60ccw(H3Index h) {
  868|       |    // rotate in place; skips any leading 1 digits (k-axis)
  869|       |
  870|    684|    int foundFirstNonZeroDigit = 0;
  871|  5.35k|    for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
  ------------------
  |  |  131|    684|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|    684|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|    684|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|    684|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  |  Branch (871:49): [True: 4.67k, False: 684]
  ------------------
  872|       |        // rotate this digit
  873|  4.67k|        H3_SET_INDEX_DIGIT(h, r, _rotate60ccw(H3_GET_INDEX_DIGIT(h, r)));
  ------------------
  |  |  165|  4.67k|    (h3) = (((h3) & ~((H3_DIGIT_MASK                                        \
  |  |  ------------------
  |  |  |  |   80|  4.67k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  |  |  166|  4.67k|                       << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   84|  4.67k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                                      << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   47|  4.67k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  167|  4.67k|            (((uint64_t)(digit))                                            \
  |  |  168|  4.67k|             << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   84|  4.67k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                            << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   47|  4.67k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  ------------------
  874|       |
  875|       |        // look for the first non-zero digit so we
  876|       |        // can adjust for deleted k-axes sequence
  877|       |        // if necessary
  878|  4.67k|        if (!foundFirstNonZeroDigit && H3_GET_INDEX_DIGIT(h, r) != 0) {
  ------------------
  |  |  144|    567|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|    567|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|    567|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|    567|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|    567|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
  |  Branch (878:13): [True: 567, False: 4.10k]
  |  Branch (878:40): [True: 567, False: 0]
  ------------------
  879|    567|            foundFirstNonZeroDigit = 1;
  880|       |
  881|       |            // adjust for deleted k-axes sequence
  882|    567|            if (_h3LeadingNonZeroDigit(h) == K_AXES_DIGIT)
  ------------------
  |  Branch (882:17): [True: 197, False: 370]
  ------------------
  883|    197|                h = _h3Rotate60ccw(h);
  884|    567|        }
  885|  4.67k|    }
  886|    684|    return h;
  887|    684|}
_h3Rotate60ccw:
  918|  2.35k|H3Index _h3Rotate60ccw(H3Index h) {
  919|  9.40k|    for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
  ------------------
  |  |  131|  2.35k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  2.35k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  2.35k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  2.35k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  |  Branch (919:49): [True: 7.05k, False: 2.35k]
  ------------------
  920|  7.05k|        Direction oldDigit = H3_GET_INDEX_DIGIT(h, r);
  ------------------
  |  |  144|  7.05k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  7.05k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  7.05k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|  7.05k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  7.05k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
  921|  7.05k|        H3_SET_INDEX_DIGIT(h, r, _rotate60ccw(oldDigit));
  ------------------
  |  |  165|  7.05k|    (h3) = (((h3) & ~((H3_DIGIT_MASK                                        \
  |  |  ------------------
  |  |  |  |   80|  7.05k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  |  |  166|  7.05k|                       << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   84|  7.05k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                                      << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   47|  7.05k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  167|  7.05k|            (((uint64_t)(digit))                                            \
  |  |  168|  7.05k|             << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   84|  7.05k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                            << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   47|  7.05k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  ------------------
  922|  7.05k|    }
  923|       |
  924|  2.35k|    return h;
  925|  2.35k|}
_h3Rotate60cw:
  931|    727|H3Index _h3Rotate60cw(H3Index h) {
  932|  8.19k|    for (int r = 1, res = H3_GET_RESOLUTION(h); r <= res; r++) {
  ------------------
  |  |  131|    727|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|    727|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|    727|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|    727|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  |  Branch (932:49): [True: 7.46k, False: 727]
  ------------------
  933|  7.46k|        H3_SET_INDEX_DIGIT(h, r, _rotate60cw(H3_GET_INDEX_DIGIT(h, r)));
  ------------------
  |  |  165|  7.46k|    (h3) = (((h3) & ~((H3_DIGIT_MASK                                        \
  |  |  ------------------
  |  |  |  |   80|  7.46k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  |  |  166|  7.46k|                       << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   84|  7.46k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                                      << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
  |  |  ------------------
  |  |  |  |   47|  7.46k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  167|  7.46k|            (((uint64_t)(digit))                                            \
  |  |  168|  7.46k|             << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   84|  7.46k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                            << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
  |  |  ------------------
  |  |  |  |   47|  7.46k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  ------------------
  934|  7.46k|    }
  935|       |
  936|    727|    return h;
  937|    727|}
_h3ToFaceIjkWithInitializedFijk:
 1090|  7.98k|int _h3ToFaceIjkWithInitializedFijk(H3Index h, FaceIJK *fijk) {
 1091|  7.98k|    CoordIJK *ijk = &fijk->coord;
 1092|  7.98k|    int res = H3_GET_RESOLUTION(h);
  ------------------
  |  |  131|  7.98k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  7.98k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  7.98k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  7.98k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
 1093|       |
 1094|       |    // center base cell hierarchy is entirely on this face
 1095|  7.98k|    int possibleOverage = 1;
 1096|  7.98k|    if (!_isBaseCellPentagon(H3_GET_BASE_CELL(h)) &&
  ------------------
  |  |  120|  7.98k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  7.98k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  7.98k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  7.98k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
  |  Branch (1096:9): [True: 4.57k, False: 3.40k]
  ------------------
 1097|  4.57k|        (res == 0 ||
  ------------------
  |  Branch (1097:10): [True: 729, False: 3.84k]
  ------------------
 1098|  3.84k|         (fijk->coord.i == 0 && fijk->coord.j == 0 && fijk->coord.k == 0)))
  ------------------
  |  Branch (1098:11): [True: 2.22k, False: 1.62k]
  |  Branch (1098:33): [True: 1.01k, False: 1.20k]
  |  Branch (1098:55): [True: 239, False: 776]
  ------------------
 1099|    968|        possibleOverage = 0;
 1100|       |
 1101|  84.2k|    for (int r = 1; r <= res; r++) {
  ------------------
  |  Branch (1101:21): [True: 76.2k, False: 7.98k]
  ------------------
 1102|  76.2k|        if (isResolutionClassIII(r)) {
  ------------------
  |  Branch (1102:13): [True: 41.0k, False: 35.2k]
  ------------------
 1103|       |            // Class III == rotate ccw
 1104|  41.0k|            _downAp7(ijk);
 1105|  41.0k|        } else {
 1106|       |            // Class II == rotate cw
 1107|  35.2k|            _downAp7r(ijk);
 1108|  35.2k|        }
 1109|       |
 1110|  76.2k|        _neighbor(ijk, H3_GET_INDEX_DIGIT(h, r));
  ------------------
  |  |  144|  76.2k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  76.2k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  76.2k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|  76.2k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  76.2k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
 1111|  76.2k|    }
 1112|       |
 1113|  7.98k|    return possibleOverage;
 1114|  7.98k|}
_h3ToFaceIjk:
 1121|  8.00k|H3Error _h3ToFaceIjk(H3Index h, FaceIJK *fijk) {
 1122|  8.00k|    int baseCell = H3_GET_BASE_CELL(h);
  ------------------
  |  |  120|  8.00k|#define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   62|  8.00k|#define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   38|  8.00k|#define H3_BC_OFFSET 45
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_BASE_CELL(h3) ((int)((((h3) & H3_BC_MASK) >> H3_BC_OFFSET)))
  |  |  ------------------
  |  |  |  |   38|  8.00k|#define H3_BC_OFFSET 45
  |  |  ------------------
  ------------------
 1123|  8.00k|    if (NEVER(baseCell < 0) || baseCell >= NUM_BASE_CELLS) {
  ------------------
  |  |  119|  16.0k|#define NEVER(X) ((X) ? (assert(0), 1) : 0)
  |  |  ------------------
  |  |  |  Branch (119:18): [True: 0, False: 8.00k]
  |  |  |  Branch (119:19): [True: 0, False: 8.00k]
  |  |  ------------------
  ------------------
                  if (NEVER(baseCell < 0) || baseCell >= NUM_BASE_CELLS) {
  ------------------
  |  |   89|  8.00k|#define NUM_BASE_CELLS 122
  ------------------
  |  Branch (1123:9): [Folded, False: 0]
  |  Branch (1123:9): [Folded, False: 0]
  |  Branch (1123:32): [True: 27, False: 7.98k]
  ------------------
 1124|       |        // Base cells less than zero can not be represented in an index
 1125|       |        // To prevent reading uninitialized memory, we zero the output.
 1126|     27|        fijk->face = 0;
 1127|     27|        fijk->coord.i = fijk->coord.j = fijk->coord.k = 0;
 1128|     27|        return E_CELL_INVALID;
 1129|     27|    }
 1130|       |    // adjust for the pentagonal missing sequence; all of sub-sequence 5 needs
 1131|       |    // to be adjusted (and some of sub-sequence 4 below)
 1132|  7.98k|    if (_isBaseCellPentagon(baseCell) && _h3LeadingNonZeroDigit(h) == 5)
  ------------------
  |  Branch (1132:9): [True: 3.40k, False: 4.57k]
  |  Branch (1132:42): [True: 556, False: 2.84k]
  ------------------
 1133|    556|        h = _h3Rotate60cw(h);
 1134|       |
 1135|       |    // start with the "home" face and ijk+ coordinates for the base cell of c
 1136|  7.98k|    *fijk = baseCellData[baseCell].homeFijk;
 1137|  7.98k|    if (!_h3ToFaceIjkWithInitializedFijk(h, fijk))
  ------------------
  |  Branch (1137:9): [True: 968, False: 7.01k]
  ------------------
 1138|    968|        return E_SUCCESS;  // no overage is possible; h lies on this face
 1139|       |
 1140|       |    // if we're here we have the potential for an "overage"; i.e., it is
 1141|       |    // possible that c lies on an adjacent face
 1142|       |
 1143|  7.01k|    CoordIJK origIJK = fijk->coord;
 1144|       |
 1145|       |    // if we're in Class III, drop into the next finer Class II grid
 1146|  7.01k|    int res = H3_GET_RESOLUTION(h);
  ------------------
  |  |  131|  7.01k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  7.01k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  7.01k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  7.01k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
 1147|  7.01k|    if (isResolutionClassIII(res)) {
  ------------------
  |  Branch (1147:9): [True: 5.65k, False: 1.36k]
  ------------------
 1148|       |        // Class III
 1149|  5.65k|        _downAp7r(&fijk->coord);
 1150|  5.65k|        res++;
 1151|  5.65k|    }
 1152|       |
 1153|       |    // adjust for overage if needed
 1154|       |    // a pentagon base cell with a leading 4 digit requires special handling
 1155|  7.01k|    int pentLeading4 =
 1156|  7.01k|        (_isBaseCellPentagon(baseCell) && _h3LeadingNonZeroDigit(h) == 4);
  ------------------
  |  Branch (1156:10): [True: 3.40k, False: 3.61k]
  |  Branch (1156:43): [True: 1.02k, False: 2.37k]
  ------------------
 1157|  7.01k|    if (_adjustOverageClassII(fijk, res, pentLeading4, 0) != NO_OVERAGE) {
  ------------------
  |  Branch (1157:9): [True: 3.35k, False: 3.65k]
  ------------------
 1158|       |        // if the base cell is a pentagon we have the potential for secondary
 1159|       |        // overages
 1160|  3.35k|        if (_isBaseCellPentagon(baseCell)) {
  ------------------
  |  Branch (1160:13): [True: 2.64k, False: 714]
  ------------------
 1161|  4.80k|            while (_adjustOverageClassII(fijk, res, 0, 0) != NO_OVERAGE)
  ------------------
  |  Branch (1161:20): [True: 2.16k, False: 2.64k]
  ------------------
 1162|  2.16k|                continue;
 1163|  2.64k|        }
 1164|       |
 1165|  3.35k|        if (res != H3_GET_RESOLUTION(h)) _upAp7r(&fijk->coord);
  ------------------
  |  |  131|  3.35k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  3.35k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  3.35k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  3.35k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  |  Branch (1165:13): [True: 2.79k, False: 557]
  ------------------
 1166|  3.65k|    } else if (res != H3_GET_RESOLUTION(h)) {
  ------------------
  |  |  131|  3.65k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  3.65k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  3.65k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  3.65k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  |  Branch (1166:16): [True: 2.85k, False: 805]
  ------------------
 1167|  2.85k|        fijk->coord = origIJK;
 1168|  2.85k|    }
 1169|  7.01k|    return E_SUCCESS;
 1170|  7.98k|}
isResolutionClassIII:
 1359|   100k|int isResolutionClassIII(int res) { return res % 2; }
h3Index.c:_hasGoodTopBits:
  216|    261|static inline bool _hasGoodTopBits(H3Index h) {
  217|    261|    h >>= (64 - 8);
  218|    261|    return h == 0b00001000;
  219|    261|}
h3Index.c:_hasAny7UptoRes:
  264|    252|static inline bool _hasAny7UptoRes(H3Index h, int res) {
  265|    252|    const uint64_t MHI = 0b100100100100100100100100100100100100100100100;
  266|    252|    const uint64_t MLO = MHI >> 2;
  267|       |
  268|    252|    int shift = 3 * (15 - res);
  269|    252|    h >>= shift;
  270|    252|    h <<= shift;
  271|    252|    h = (h & MHI & (~h - MLO));
  272|       |
  273|    252|    return h != 0;
  274|    252|}
h3Index.c:_hasAll7AfterRes:
  280|    217|static inline bool _hasAll7AfterRes(H3Index h, int res) {
  281|       |    // NOTE: res check is needed because we can't shift by 64
  282|    217|    if (res < 15) {
  ------------------
  |  Branch (282:9): [True: 122, False: 95]
  ------------------
  283|    122|        int shift = 19 + 3 * res;
  284|       |
  285|    122|        h = ~h;
  286|    122|        h <<= shift;
  287|    122|        h >>= shift;
  288|       |
  289|    122|        return h == 0;
  290|    122|    }
  291|     95|    return true;
  292|    217|}
h3Index.c:_hasDeletedSubsequence:
  327|    149|static inline bool _hasDeletedSubsequence(H3Index h, int base_cell) {
  328|    149|    if (isBaseCellPentagonArr[base_cell]) {
  ------------------
  |  Branch (328:9): [True: 88, False: 61]
  ------------------
  329|     88|        h <<= 19;
  330|     88|        h >>= 19;
  331|       |
  332|     88|        if (h == 0) return false;  // all zeros: res 15 pentagon
  ------------------
  |  Branch (332:13): [True: 2, False: 86]
  ------------------
  333|     86|        return _firstOneIndex(h) % 3 == 0;
  334|     88|    }
  335|     61|    return false;
  336|    149|}
h3Index.c:_firstOneIndex:
  300|     86|static inline int _firstOneIndex(H3Index h) {
  301|     86|#if defined(__GNUC__) || defined(__clang__)
  302|     86|    return 63 - __builtin_clzll(h);
  303|       |#elif defined(_MSC_VER) && defined(_M_X64)  // doesn't work on win32
  304|       |    unsigned long index;
  305|       |    _BitScanReverse64(&index, h);
  306|       |    return (int)index;
  307|       |#else
  308|       |    // Portable fallback
  309|       |    int pos = 63 - 19;
  310|       |    H3Index m = 1;
  311|       |    while ((h & (m << pos)) == 0) pos--;
  312|       |    return pos;
  313|       |#endif
  314|     86|}

_posAngleRads:
   36|    561|double _posAngleRads(double rads) {
   37|    561|    double tmp = ((rads < 0.0) ? rads + M_2PI : rads);
  ------------------
  |  |   42|     65|#define M_2PI 6.28318530717958647692528676655900576839433
  ------------------
  |  Branch (37:19): [True: 65, False: 496]
  ------------------
   38|    561|    if (rads >= M_2PI) tmp -= M_2PI;
  ------------------
  |  |   42|    561|#define M_2PI 6.28318530717958647692528676655900576839433
  ------------------
                  if (rads >= M_2PI) tmp -= M_2PI;
  ------------------
  |  |   42|     46|#define M_2PI 6.28318530717958647692528676655900576839433
  ------------------
  |  Branch (38:9): [True: 46, False: 515]
  ------------------
   39|    561|    return tmp;
   40|    561|}

_v2dMag:
   31|    561|double _v2dMag(const Vec2d *v) { return sqrt(v->x * v->x + v->y * v->y); }

vertexNumForDirection:
  131|  2.15k|int vertexNumForDirection(const H3Index origin, const Direction direction) {
  132|  2.15k|    int isPent = H3_EXPORT(isPentagon)(origin);
  ------------------
  |  |   36|  2.15k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  2.15k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  2.15k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  133|       |    // Check for invalid directions
  134|  2.15k|    if (direction == CENTER_DIGIT || direction >= INVALID_DIGIT ||
  ------------------
  |  Branch (134:9): [True: 0, False: 2.15k]
  |  Branch (134:38): [True: 20, False: 2.13k]
  ------------------
  135|  2.13k|        (isPent && direction == K_AXES_DIGIT))
  ------------------
  |  Branch (135:10): [True: 143, False: 1.99k]
  |  Branch (135:20): [True: 0, False: 143]
  ------------------
  136|     20|        return INVALID_VERTEX_NUM;
  ------------------
  |  |   36|     20|#define INVALID_VERTEX_NUM -1
  ------------------
  137|       |
  138|       |    // Determine the vertex rotations for this cell
  139|  2.13k|    int rotations;
  140|  2.13k|    H3Error err = vertexRotations(origin, &rotations);
  141|  2.13k|    if (err) {
  ------------------
  |  Branch (141:9): [True: 0, False: 2.13k]
  ------------------
  142|      0|        return INVALID_VERTEX_NUM;
  ------------------
  |  |   36|      0|#define INVALID_VERTEX_NUM -1
  ------------------
  143|      0|    }
  144|       |
  145|       |    // Find the appropriate vertex, rotating CCW if necessary
  146|  2.13k|    if (isPent) {
  ------------------
  |  Branch (146:9): [True: 143, False: 1.99k]
  ------------------
  147|    143|        return (directionToVertexNumPent[direction] + NUM_PENT_VERTS -
  ------------------
  |  |   93|    143|#define NUM_PENT_VERTS 5
  ------------------
  148|    143|                rotations) %
  149|    143|               NUM_PENT_VERTS;
  ------------------
  |  |   93|    143|#define NUM_PENT_VERTS 5
  ------------------
  150|  1.99k|    } else {
  151|  1.99k|        return (directionToVertexNumHex[direction] + NUM_HEX_VERTS -
  ------------------
  |  |   91|  1.99k|#define NUM_HEX_VERTS 6
  ------------------
  152|  1.99k|                rotations) %
  153|  1.99k|               NUM_HEX_VERTS;
  ------------------
  |  |   91|  1.99k|#define NUM_HEX_VERTS 6
  ------------------
  154|  1.99k|    }
  155|  2.13k|}
directionForVertexNum:
  174|  5.30k|Direction directionForVertexNum(const H3Index origin, const int vertexNum) {
  175|  5.30k|    int isPent = H3_EXPORT(isPentagon)(origin);
  ------------------
  |  |   36|  5.30k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  5.30k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  5.30k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  176|       |    // Check for invalid vertexes
  177|  5.30k|    if (vertexNum < 0 ||
  ------------------
  |  Branch (177:9): [True: 0, False: 5.30k]
  ------------------
  178|  5.30k|        vertexNum > (isPent ? NUM_PENT_VERTS : NUM_HEX_VERTS) - 1)
  ------------------
  |  |   93|    108|#define NUM_PENT_VERTS 5
  ------------------
                      vertexNum > (isPent ? NUM_PENT_VERTS : NUM_HEX_VERTS) - 1)
  ------------------
  |  |   91|  5.19k|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (178:9): [True: 0, False: 5.30k]
  |  Branch (178:22): [True: 108, False: 5.19k]
  ------------------
  179|      0|        return INVALID_DIGIT;
  180|       |
  181|       |    // Determine the vertex rotations for this cell
  182|  5.30k|    int rotations;
  183|  5.30k|    H3Error err = vertexRotations(origin, &rotations);
  184|  5.30k|    if (err) {
  ------------------
  |  Branch (184:9): [True: 14, False: 5.28k]
  ------------------
  185|     14|        return INVALID_DIGIT;
  186|     14|    }
  187|       |
  188|       |    // Find the appropriate direction, rotating CW if necessary
  189|  5.28k|    return isPent ? vertexNumToDirectionPent[(vertexNum + rotations) %
  ------------------
  |  Branch (189:12): [True: 108, False: 5.17k]
  ------------------
  190|    108|                                             NUM_PENT_VERTS]
  ------------------
  |  |   93|    108|#define NUM_PENT_VERTS 5
  ------------------
  191|  5.28k|                  : vertexNumToDirectionHex[(vertexNum + rotations) %
  192|  5.17k|                                            NUM_HEX_VERTS];
  ------------------
  |  |   91|  5.17k|#define NUM_HEX_VERTS 6
  ------------------
  193|  5.30k|}
cellToVertex:
  213|  3.69k|H3Error H3_EXPORT(cellToVertex)(H3Index cell, int vertexNum, H3Index *out) {
  214|  3.69k|    int cellIsPentagon = H3_EXPORT(isPentagon)(cell);
  ------------------
  |  |   36|  3.69k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  3.69k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  3.69k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|  3.69k|    int cellNumVerts = cellIsPentagon ? NUM_PENT_VERTS : NUM_HEX_VERTS;
  ------------------
  |  |   93|    166|#define NUM_PENT_VERTS 5
  ------------------
                  int cellNumVerts = cellIsPentagon ? NUM_PENT_VERTS : NUM_HEX_VERTS;
  ------------------
  |  |   91|  3.52k|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (215:24): [True: 166, False: 3.52k]
  ------------------
  216|  3.69k|    int res = H3_GET_RESOLUTION(cell);
  ------------------
  |  |  131|  3.69k|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|  3.69k|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|  3.69k|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|  3.69k|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  217|       |
  218|       |    // Check for invalid vertexes
  219|  3.69k|    if (vertexNum < 0 || vertexNum > cellNumVerts - 1) return E_DOMAIN;
  ------------------
  |  Branch (219:9): [True: 183, False: 3.51k]
  |  Branch (219:26): [True: 256, False: 3.25k]
  ------------------
  220|       |
  221|       |    // Default the owner and vertex number to the input cell
  222|  3.25k|    H3Index owner = cell;
  223|  3.25k|    int ownerVertexNum = vertexNum;
  224|       |
  225|       |    // Determine the owner, looking at the three cells that share the vertex.
  226|       |    // By convention, the owner is the cell with the lowest numerical index.
  227|       |
  228|       |    // If the cell is the center child of its parent, it will always have
  229|       |    // the lowest index of any neighbor, so we can skip determining the owner
  230|  3.25k|    if (res == 0 || H3_GET_INDEX_DIGIT(cell, res) != CENTER_DIGIT) {
  ------------------
  |  |  144|  2.92k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  2.92k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  2.92k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|  2.92k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  2.92k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
  |  Branch (230:9): [True: 332, False: 2.92k]
  |  Branch (230:21): [True: 2.56k, False: 358]
  ------------------
  231|       |        // Get the left neighbor of the vertex, with its rotations
  232|  2.89k|        Direction left = directionForVertexNum(cell, vertexNum);
  233|  2.89k|        if (left == INVALID_DIGIT) return E_FAILED;
  ------------------
  |  Branch (233:13): [True: 14, False: 2.88k]
  ------------------
  234|  2.88k|        int lRotations = 0;
  235|  2.88k|        H3Index leftNeighbor;
  236|  2.88k|        H3Error leftNeighborError =
  237|  2.88k|            h3NeighborRotations(cell, left, &lRotations, &leftNeighbor);
  238|  2.88k|        if (leftNeighborError) return leftNeighborError;
  ------------------
  |  Branch (238:13): [True: 80, False: 2.80k]
  ------------------
  239|       |        // Set to owner if lowest index
  240|  2.80k|        if (leftNeighbor < owner) owner = leftNeighbor;
  ------------------
  |  Branch (240:13): [True: 1.64k, False: 1.15k]
  ------------------
  241|       |
  242|       |        // As above, skip the right neighbor if the left is known lowest
  243|  2.80k|        if (res == 0 || H3_GET_INDEX_DIGIT(leftNeighbor, res) != CENTER_DIGIT) {
  ------------------
  |  |  144|  2.47k|    ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   84|  2.47k|#define MAX_H3_RES 15
  |  |  ------------------
  |  |                   ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & \
  |  |  ------------------
  |  |  |  |   47|  2.47k|#define H3_PER_DIGIT_OFFSET 3
  |  |  ------------------
  |  |  145|  2.47k|                  H3_DIGIT_MASK)))
  |  |  ------------------
  |  |  |  |   80|  2.47k|#define H3_DIGIT_MASK ((uint64_t)(7))
  |  |  ------------------
  ------------------
  |  Branch (243:13): [True: 329, False: 2.47k]
  |  Branch (243:25): [True: 2.07k, False: 398]
  ------------------
  244|       |            // Get the right neighbor of the vertex, with its rotations
  245|       |            // Note that vertex - 1 is the right side, as vertex numbers are CCW
  246|  2.40k|            Direction right = directionForVertexNum(
  247|  2.40k|                cell, (vertexNum - 1 + cellNumVerts) % cellNumVerts);
  248|       |            // This case should be unreachable; invalid verts fail earlier
  249|  2.40k|            if (NEVER(right == INVALID_DIGIT)) return E_FAILED;
  ------------------
  |  |  119|  2.40k|#define NEVER(X) ((X) ? (assert(0), 1) : 0)
  |  |  ------------------
  |  |  |  Branch (119:18): [True: 0, False: 2.40k]
  |  |  |  Branch (119:19): [True: 0, False: 2.40k]
  |  |  ------------------
  ------------------
  |  Branch (249:17): [Folded, False: 0]
  |  Branch (249:17): [Folded, False: 0]
  ------------------
  250|  2.40k|            int rRotations = 0;
  251|  2.40k|            H3Index rightNeighbor;
  252|  2.40k|            H3Error rightNeighborError =
  253|  2.40k|                h3NeighborRotations(cell, right, &rRotations, &rightNeighbor);
  254|  2.40k|            if (rightNeighborError) return rightNeighborError;
  ------------------
  |  Branch (254:17): [True: 19, False: 2.38k]
  ------------------
  255|       |            // Set to owner if lowest index
  256|  2.38k|            if (rightNeighbor < owner) {
  ------------------
  |  Branch (256:17): [True: 1.06k, False: 1.31k]
  ------------------
  257|  1.06k|                owner = rightNeighbor;
  258|  1.06k|                Direction dir =
  259|  1.06k|                    H3_EXPORT(isPentagon)(owner)
  ------------------
  |  |   36|  1.06k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  1.06k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  1.06k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (259:21): [True: 87, False: 980]
  ------------------
  260|  1.06k|                        ? directionForNeighbor(owner, cell)
  261|  1.06k|                        : DIRECTIONS[(revNeighborDirectionsHex[right] +
  262|    980|                                      rRotations) %
  263|    980|                                     NUM_HEX_VERTS];
  ------------------
  |  |   91|    980|#define NUM_HEX_VERTS 6
  ------------------
  264|  1.06k|                ownerVertexNum = vertexNumForDirection(owner, dir);
  265|  1.06k|            }
  266|  2.38k|        }
  267|       |
  268|       |        // Determine the vertex number for the left neighbor
  269|  2.78k|        if (owner == leftNeighbor) {
  ------------------
  |  Branch (269:13): [True: 1.06k, False: 1.71k]
  ------------------
  270|  1.06k|            int ownerIsPentagon = H3_EXPORT(isPentagon)(owner);
  ------------------
  |  |   36|  1.06k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  1.06k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  1.06k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|  1.06k|            Direction dir =
  272|  1.06k|                ownerIsPentagon
  ------------------
  |  Branch (272:17): [True: 71, False: 995]
  ------------------
  273|  1.06k|                    ? directionForNeighbor(owner, cell)
  274|  1.06k|                    : DIRECTIONS[(revNeighborDirectionsHex[left] + lRotations) %
  275|    995|                                 NUM_HEX_VERTS];
  ------------------
  |  |   91|    995|#define NUM_HEX_VERTS 6
  ------------------
  276|       |
  277|       |            // For the left neighbor, we need the second vertex of the
  278|       |            // edge, which may involve looping around the vertex nums
  279|  1.06k|            ownerVertexNum = vertexNumForDirection(owner, dir) + 1;
  280|  1.06k|            if (ownerVertexNum == NUM_HEX_VERTS ||
  ------------------
  |  |   91|  2.13k|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (280:17): [True: 188, False: 878]
  ------------------
  281|    878|                (ownerIsPentagon && ownerVertexNum == NUM_PENT_VERTS)) {
  ------------------
  |  |   93|     71|#define NUM_PENT_VERTS 5
  ------------------
  |  Branch (281:18): [True: 71, False: 807]
  |  Branch (281:37): [True: 9, False: 62]
  ------------------
  282|    197|                ownerVertexNum = 0;
  283|    197|            }
  284|  1.06k|        }
  285|  2.78k|    }
  286|       |
  287|       |    // Create the vertex index
  288|  3.14k|    H3Index vertex = owner;
  289|  3.14k|    H3_SET_MODE(vertex, H3_VERTEX_MODE);
  ------------------
  |  |  114|  3.14k|    (h3) =                 \
  |  |  115|  3.14k|        (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   59|  3.14k|#define H3_MODE_MASK_NEGATIVE (~H3_MODE_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   56|  3.14k|#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   35|  3.14k|#define H3_MODE_OFFSET 59
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   35|  3.14k|#define H3_MODE_OFFSET 59
  |  |  ------------------
  ------------------
  290|  3.14k|    H3_SET_RESERVED_BITS(vertex, ownerVertexNum);
  ------------------
  |  |  152|  3.14k|    (h3) = (((h3) & H3_RESERVED_MASK_NEGATIVE) | \
  |  |  ------------------
  |  |  |  |   77|  3.14k|#define H3_RESERVED_MASK_NEGATIVE (~H3_RESERVED_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  3.14k|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|  3.14k|#define H3_RESERVED_OFFSET 56
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  153|  3.14k|            (((uint64_t)(v)) << H3_RESERVED_OFFSET))
  |  |  ------------------
  |  |  |  |   44|  3.14k|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  291|  3.14k|    *out = vertex;
  292|       |
  293|  3.14k|    return E_SUCCESS;
  294|  3.25k|}
cellToVertexes:
  301|    574|H3Error H3_EXPORT(cellToVertexes)(H3Index cell, H3Index *vertexes) {
  302|       |    // Get all vertexes. If the cell is a pentagon, will fill the final slot
  303|       |    // with H3_NULL.
  304|    574|    bool isPent = H3_EXPORT(isPentagon)(cell);
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|  3.45k|    for (int i = 0; i < NUM_HEX_VERTS; i++) {
  ------------------
  |  |   91|  3.45k|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (305:21): [True: 2.98k, False: 474]
  ------------------
  306|  2.98k|        if (i == 5 && isPent) {
  ------------------
  |  Branch (306:13): [True: 474, False: 2.50k]
  |  Branch (306:23): [True: 25, False: 449]
  ------------------
  307|     25|            vertexes[i] = H3_NULL;
  ------------------
  |  |   76|     25|#define H3_NULL 0
  ------------------
  308|  2.95k|        } else {
  309|  2.95k|            H3Error cellError = H3_EXPORT(cellToVertex)(cell, i, &vertexes[i]);
  ------------------
  |  |   36|  2.95k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  2.95k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  2.95k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  310|  2.95k|            if (cellError) {
  ------------------
  |  Branch (310:17): [True: 100, False: 2.85k]
  ------------------
  311|    100|                return cellError;
  312|    100|            }
  313|  2.95k|        }
  314|  2.98k|    }
  315|    474|    return E_SUCCESS;
  316|    574|}
edgeToVertexes:
  327|    574|H3Error H3_EXPORT(edgeToVertexes)(H3Index edge, H3Index *v1, H3Index *v2) {
  328|       |    // Validate the edge and get its origin cell
  329|    574|    if (!H3_EXPORT(isValidDirectedEdge)(edge)) {
  ------------------
  |  |   36|    574|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    574|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    574|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (329:9): [True: 554, False: 20]
  ------------------
  330|    554|        return E_DIR_EDGE_INVALID;
  331|    554|    }
  332|     20|    H3Index origin;
  333|     20|    H3Error originError = H3_EXPORT(getDirectedEdgeOrigin)(edge, &origin);
  ------------------
  |  |   36|     20|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|     20|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|     20|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  334|     20|    if (originError) {
  ------------------
  |  Branch (334:9): [True: 0, False: 20]
  ------------------
  335|      0|        return originError;
  336|      0|    }
  337|       |
  338|       |    // Get the first (start) vertex number for the edge's direction
  339|     20|    Direction direction = H3_GET_RESERVED_BITS(edge);
  ------------------
  |  |  159|     20|    ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   74|     20|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define H3_RESERVED_OFFSET 56
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   44|     20|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  340|     20|    int startVertexNum = vertexNumForDirection(origin, direction);
  341|       |    // This is unreachable, since isValidDirectedEdge validates the direction
  342|     20|    if (NEVER(startVertexNum == INVALID_VERTEX_NUM)) {
  ------------------
  |  |  119|     20|#define NEVER(X) ((X) ? (assert(0), 1) : 0)
  |  |  ------------------
  |  |  |  Branch (119:18): [True: 0, False: 20]
  |  |  |  Branch (119:19): [True: 0, False: 20]
  |  |  ------------------
  ------------------
  |  Branch (342:9): [Folded, False: 0]
  |  Branch (342:9): [Folded, False: 0]
  ------------------
  343|      0|        return E_DIR_EDGE_INVALID;
  344|      0|    }
  345|       |
  346|       |    // The second (end) vertex is the next one in CCW order
  347|     20|    int cellNumVerts =
  348|     20|        H3_EXPORT(isPentagon)(origin) ? NUM_PENT_VERTS : NUM_HEX_VERTS;
  ------------------
  |  |   36|     20|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|     20|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|     20|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      H3_EXPORT(isPentagon)(origin) ? NUM_PENT_VERTS : NUM_HEX_VERTS;
  ------------------
  |  |   93|      5|#define NUM_PENT_VERTS 5
  ------------------
                      H3_EXPORT(isPentagon)(origin) ? NUM_PENT_VERTS : NUM_HEX_VERTS;
  ------------------
  |  |   91|     15|#define NUM_HEX_VERTS 6
  ------------------
  |  Branch (348:9): [True: 5, False: 15]
  ------------------
  349|     20|    int endVertexNum = (startVertexNum + 1) % cellNumVerts;
  350|       |
  351|       |    // Convert the vertex numbers to H3 vertex indexes
  352|     20|    H3Error v1Error = H3_EXPORT(cellToVertex)(origin, startVertexNum, v1);
  ------------------
  |  |   36|     20|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|     20|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|     20|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|     20|    if (v1Error) {
  ------------------
  |  Branch (353:9): [True: 0, False: 20]
  ------------------
  354|      0|        return v1Error;
  355|      0|    }
  356|     20|    return H3_EXPORT(cellToVertex)(origin, endVertexNum, v2);
  ------------------
  |  |   36|     20|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|     20|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|     20|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  357|     20|}
vertexToLatLng:
  364|    574|H3Error H3_EXPORT(vertexToLatLng)(H3Index vertex, LatLng *coord) {
  365|       |    // Get the vertex number and owner from the vertex
  366|    574|    int vertexNum = H3_GET_RESERVED_BITS(vertex);
  ------------------
  |  |  159|    574|    ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   74|    574|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    574|#define H3_RESERVED_OFFSET 56
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   44|    574|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  367|    574|    H3Index owner = vertex;
  368|    574|    H3_SET_MODE(owner, H3_CELL_MODE);
  ------------------
  |  |  114|    574|    (h3) =                 \
  |  |  115|    574|        (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   59|    574|#define H3_MODE_MASK_NEGATIVE (~H3_MODE_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   56|    574|#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   35|    574|#define H3_MODE_OFFSET 59
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   35|    574|#define H3_MODE_OFFSET 59
  |  |  ------------------
  ------------------
  369|    574|    H3_SET_RESERVED_BITS(owner, 0);
  ------------------
  |  |  152|    574|    (h3) = (((h3) & H3_RESERVED_MASK_NEGATIVE) | \
  |  |  ------------------
  |  |  |  |   77|    574|#define H3_RESERVED_MASK_NEGATIVE (~H3_RESERVED_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|    574|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|    574|#define H3_RESERVED_OFFSET 56
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  153|    574|            (((uint64_t)(v)) << H3_RESERVED_OFFSET))
  |  |  ------------------
  |  |  |  |   44|    574|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  370|       |
  371|       |    // Get the single vertex from the boundary
  372|    574|    CellBoundary gb;
  373|    574|    FaceIJK fijk;
  374|    574|    H3Error fijkError = _h3ToFaceIjk(owner, &fijk);
  375|    574|    if (fijkError) {
  ------------------
  |  Branch (375:9): [True: 13, False: 561]
  ------------------
  376|     13|        return fijkError;
  377|     13|    }
  378|    561|    int res = H3_GET_RESOLUTION(owner);
  ------------------
  |  |  131|    561|#define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   68|    561|#define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|    561|#define H3_RES_OFFSET 52
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_RESOLUTION(h3) ((int)((((h3) & H3_RES_MASK) >> H3_RES_OFFSET)))
  |  |  ------------------
  |  |  |  |   41|    561|#define H3_RES_OFFSET 52
  |  |  ------------------
  ------------------
  379|       |
  380|    561|    if (H3_EXPORT(isPentagon)(owner)) {
  ------------------
  |  |   36|    561|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    561|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    561|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (380:9): [True: 25, False: 536]
  ------------------
  381|     25|        _faceIjkPentToCellBoundary(&fijk, res, vertexNum, 1, &gb);
  382|    536|    } else {
  383|    536|        _faceIjkToCellBoundary(&fijk, res, vertexNum, 1, &gb);
  384|    536|    }
  385|       |
  386|       |    // Copy from boundary to output coord
  387|    561|    *coord = gb.verts[0];
  388|    561|    return E_SUCCESS;
  389|    574|}
isValidVertex:
  396|    574|int H3_EXPORT(isValidVertex)(H3Index vertex) {
  397|    574|    if (H3_GET_MODE(vertex) != H3_VERTEX_MODE) {
  ------------------
  |  |  108|    574|#define H3_GET_MODE(h3) ((int)((((h3) & H3_MODE_MASK) >> H3_MODE_OFFSET)))
  |  |  ------------------
  |  |  |  |   56|    574|#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   35|    574|#define H3_MODE_OFFSET 59
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define H3_GET_MODE(h3) ((int)((((h3) & H3_MODE_MASK) >> H3_MODE_OFFSET)))
  |  |  ------------------
  |  |  |  |   35|    574|#define H3_MODE_OFFSET 59
  |  |  ------------------
  ------------------
                  if (H3_GET_MODE(vertex) != H3_VERTEX_MODE) {
  ------------------
  |  |  101|    574|#define H3_VERTEX_MODE 4
  ------------------
  |  Branch (397:9): [True: 347, False: 227]
  ------------------
  398|    347|        return 0;
  399|    347|    }
  400|       |
  401|    227|    int vertexNum = H3_GET_RESERVED_BITS(vertex);
  ------------------
  |  |  159|    227|    ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   74|    227|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    227|#define H3_RESERVED_OFFSET 56
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((int)((((h3) & H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
  |  |  ------------------
  |  |  |  |   44|    227|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  402|    227|    H3Index owner = vertex;
  403|    227|    H3_SET_MODE(owner, H3_CELL_MODE);
  ------------------
  |  |  114|    227|    (h3) =                 \
  |  |  115|    227|        (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   59|    227|#define H3_MODE_MASK_NEGATIVE (~H3_MODE_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   56|    227|#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   35|    227|#define H3_MODE_OFFSET 59
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       (((h3) & H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
  |  |  ------------------
  |  |  |  |   35|    227|#define H3_MODE_OFFSET 59
  |  |  ------------------
  ------------------
  404|    227|    H3_SET_RESERVED_BITS(owner, 0);
  ------------------
  |  |  152|    227|    (h3) = (((h3) & H3_RESERVED_MASK_NEGATIVE) | \
  |  |  ------------------
  |  |  |  |   77|    227|#define H3_RESERVED_MASK_NEGATIVE (~H3_RESERVED_MASK)
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|    227|#define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|    227|#define H3_RESERVED_OFFSET 56
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  153|    227|            (((uint64_t)(v)) << H3_RESERVED_OFFSET))
  |  |  ------------------
  |  |  |  |   44|    227|#define H3_RESERVED_OFFSET 56
  |  |  ------------------
  ------------------
  405|       |
  406|    227|    if (!H3_EXPORT(isValidCell)(owner)) {
  ------------------
  |  |   36|    227|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    227|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    227|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (406:9): [True: 104, False: 123]
  ------------------
  407|    104|        return 0;
  408|    104|    }
  409|       |
  410|       |    // The easiest way to ensure that the owner + vertex number is valid,
  411|       |    // and that the vertex is canonical, is to recreate and compare.
  412|    123|    H3Index canonical;
  413|    123|    if (H3_EXPORT(cellToVertex)(owner, vertexNum, &canonical)) {
  ------------------
  |  |   36|    123|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|    123|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|    123|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (413:9): [True: 8, False: 115]
  ------------------
  414|      8|        return 0;
  415|      8|    }
  416|       |
  417|    115|    return vertex == canonical ? 1 : 0;
  ------------------
  |  Branch (417:12): [True: 17, False: 98]
  ------------------
  418|    123|}
vertex.c:vertexRotations:
   53|  7.43k|static H3Error vertexRotations(H3Index cell, int *out) {
   54|       |    // Get the face and other info for the origin
   55|  7.43k|    FaceIJK fijk;
   56|  7.43k|    H3Error err = _h3ToFaceIjk(cell, &fijk);
   57|  7.43k|    if (err) {
  ------------------
  |  Branch (57:9): [True: 14, False: 7.41k]
  ------------------
   58|     14|        return err;
   59|     14|    }
   60|  7.41k|    int baseCell = H3_EXPORT(getBaseCellNumber)(cell);
  ------------------
  |  |   36|  7.41k|#define H3_EXPORT(name) TJOIN(H3_PREFIX, name)
  |  |  ------------------
  |  |  |  |   33|  7.41k|#define TJOIN(a, b) XTJOIN(a, b)
  |  |  |  |  ------------------
  |  |  |  |  |  |   32|  7.41k|#define XTJOIN(a, b) a##b
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   61|  7.41k|    int cellLeadingDigit = _h3LeadingNonZeroDigit(cell);
   62|       |
   63|       |    // get the base cell face
   64|  7.41k|    FaceIJK baseFijk;
   65|  7.41k|    _baseCellToFaceIjk(baseCell, &baseFijk);
   66|       |
   67|  7.41k|    int ccwRot60 = _baseCellToCCWrot60(baseCell, fijk.face);
   68|       |
   69|  7.41k|    if (_isBaseCellPentagon(baseCell)) {
  ------------------
  |  Branch (69:9): [True: 3.14k, False: 4.27k]
  ------------------
   70|       |        // Find the appropriate direction-to-face mapping
   71|       |        // Zero-initialized to silence a spurious maybe-uninitialized warning.
   72|  3.14k|        PentagonDirectionFaces dirFaces = {0, {0}};
   73|       |        // We never hit the end condition
   74|  3.14k|        int p = 0;
   75|       |        // Don't use a for loop here, for coverage reasons.
   76|  20.1k|        while (ALWAYS(p < NUM_PENTAGONS)) {
  ------------------
  |  |  118|  20.1k|#define ALWAYS(X) ((X) ? 1 : (assert(0), 0))
  |  |  ------------------
  |  |  |  Branch (118:19): [True: 20.1k, False: 0]
  |  |  |  Branch (118:20): [True: 20.1k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (76:16): [Folded, False: 0]
  |  Branch (76:16): [Folded, False: 0]
  ------------------
   77|  20.1k|            if (pentagonDirectionFaces[p].baseCell == baseCell) {
  ------------------
  |  Branch (77:17): [True: 3.14k, False: 16.9k]
  ------------------
   78|  3.14k|                dirFaces = pentagonDirectionFaces[p];
   79|  3.14k|                break;
   80|  3.14k|            }
   81|  16.9k|            p++;
   82|  16.9k|        }
   83|  3.14k|        if (NEVER(p == NUM_PENTAGONS)) {
  ------------------
  |  |  119|  3.14k|#define NEVER(X) ((X) ? (assert(0), 1) : 0)
  |  |  ------------------
  |  |  |  Branch (119:18): [True: 0, False: 3.14k]
  |  |  |  Branch (119:19): [True: 0, False: 3.14k]
  |  |  ------------------
  ------------------
  |  Branch (83:13): [Folded, False: 0]
  |  Branch (83:13): [Folded, False: 0]
  ------------------
   84|      0|            return E_FAILED;
   85|      0|        }
   86|       |
   87|       |        // additional CCW rotation for polar neighbors or IK neighbors
   88|  3.14k|        if (fijk.face != baseFijk.face &&
  ------------------
  |  Branch (88:13): [True: 2.43k, False: 706]
  ------------------
   89|  2.43k|            (_isBaseCellPolarPentagon(baseCell) ||
  ------------------
  |  Branch (89:14): [True: 841, False: 1.59k]
  ------------------
   90|  1.59k|             fijk.face ==
  ------------------
  |  Branch (90:14): [True: 475, False: 1.12k]
  ------------------
   91|  1.59k|                 dirFaces.faces[IK_AXES_DIGIT - DIRECTION_INDEX_OFFSET])) {
  ------------------
  |  |   32|  1.59k|#define DIRECTION_INDEX_OFFSET 2
  ------------------
   92|  1.31k|            ccwRot60 = (ccwRot60 + 1) % 6;
   93|  1.31k|        }
   94|       |
   95|       |        // Check whether the cell crosses a deleted pentagon subsequence
   96|  3.14k|        if (cellLeadingDigit == JK_AXES_DIGIT &&
  ------------------
  |  Branch (96:13): [True: 613, False: 2.53k]
  ------------------
   97|    613|            fijk.face ==
  ------------------
  |  Branch (97:13): [True: 203, False: 410]
  ------------------
   98|    613|                dirFaces.faces[IK_AXES_DIGIT - DIRECTION_INDEX_OFFSET]) {
  ------------------
  |  |   32|    613|#define DIRECTION_INDEX_OFFSET 2
  ------------------
   99|       |            // Crosses from JK to IK: Rotate CW
  100|    203|            ccwRot60 = (ccwRot60 + 5) % 6;
  101|  2.94k|        } else if (cellLeadingDigit == IK_AXES_DIGIT &&
  ------------------
  |  Branch (101:20): [True: 519, False: 2.42k]
  ------------------
  102|    519|                   fijk.face ==
  ------------------
  |  Branch (102:20): [True: 47, False: 472]
  ------------------
  103|    519|                       dirFaces.faces[JK_AXES_DIGIT - DIRECTION_INDEX_OFFSET]) {
  ------------------
  |  |   32|    519|#define DIRECTION_INDEX_OFFSET 2
  ------------------
  104|       |            // Crosses from IK to JK: Rotate CCW
  105|     47|            ccwRot60 = (ccwRot60 + 1) % 6;
  106|     47|        }
  107|  3.14k|    }
  108|  7.41k|    *out = ccwRot60;
  109|  7.41k|    return E_SUCCESS;
  110|  7.41k|}

