ext/h3/src/src/h3lib/lib/baseCells.c in h3-3.6.2 vs ext/h3/src/src/h3lib/lib/baseCells.c in h3-3.7.1

- old
+ new

@@ -1,7 +1,7 @@ /* - * Copyright 2016-2018 Uber Technologies, Inc. + * Copyright 2016-2020 Uber Technologies, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -16,20 +16,21 @@ /** @file baseCells.c * @brief Base cell related lookup tables and access functions. */ #include "baseCells.h" + #include "h3Index.h" -/** @struct BaseCellOrient +/** @struct BaseCellRotation * @brief base cell at a given ijk and required rotations into its system */ typedef struct { int baseCell; ///< base cell number int ccwRot60; ///< number of ccw 60 degree rotations relative to current /// face -} BaseCellOrient; +} BaseCellRotation; /** @brief Neighboring base cell ID in each IJK direction. * * For each base cell, for each direction, the neighboring base * cell ID is given. 127 indicates there is no neighbor in that direction. @@ -302,11 +303,11 @@ * Valid lookup coordinates are from (0, 0, 0) to (2, 2, 2). * * This table can be accessed using the functions `_faceIjkToBaseCell` and * `_faceIjkToBaseCellCCWrot60` */ -static const BaseCellOrient faceIjkBaseCells[NUM_ICOSA_FACES][3][3][3] = { +static const BaseCellRotation faceIjkBaseCells[NUM_ICOSA_FACES][3][3][3] = { {// face 0 { // i 0 {{16, 0}, {18, 0}, {24, 0}}, // j 0 {{33, 0}, {30, 0}, {32, 3}}, // j 1 @@ -858,9 +859,30 @@ /** @brief Find the FaceIJK given a base cell. */ void _baseCellToFaceIjk(int baseCell, FaceIJK* h) { *h = baseCellData[baseCell].homeFijk; +} + +/** + * @brief Given a base cell and the face it appears on, return + * the number of 60' ccw rotations for that base cell's + * coordinate system. + * @returns The number of rotations, or INVALID_ROTATIONS if the base + * cell is not found on the given face + */ +int _baseCellToCCWrot60(int baseCell, int face) { + if (face < 0 || face > NUM_ICOSA_FACES) return INVALID_ROTATIONS; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + for (int k = 0; k < 3; k++) { + if (faceIjkBaseCells[face][i][j][k].baseCell == baseCell) { + return faceIjkBaseCells[face][i][j][k].ccwRot60; + } + } + } + } + return INVALID_ROTATIONS; } /** @brief Return whether or not the tested face is a cw offset face. */ bool _baseCellIsCwOffset(int baseCell, int testFace) { \ No newline at end of file