Permalink
Browse files

ENH: Add getBaseCells function

  • Loading branch information...
zachasme committed Jan 4, 2019
1 parent f844901 commit 420929173beac7e7989f85a8c26cbaaf26bf1c0f
Showing with 56 additions and 1 deletion.
  1. +2 −1 CHANGELOG.md
  2. +1 −0 CMakeLists.txt
  3. +29 −0 src/apps/testapps/testBaseCells.c
  4. +8 −0 src/h3lib/include/h3api.h.in
  5. +16 −0 src/h3lib/lib/baseCells.c
@@ -7,7 +7,8 @@ The public API of this library consists of the functions declared in file

## [Unreleased]
### Added
- Include defined constants for current library version
- `getBaseCells` function for getting all base cells (#174)
- Include defined constants for current library version (#173)

## [3.3.0] - 2018-12-25
### Added
@@ -485,6 +485,7 @@ if(BUILD_TESTING)
add_h3_test(testH3Distance src/apps/testapps/testH3Distance.c)
add_h3_test(testH3Line src/apps/testapps/testH3Line.c)
add_h3_test(testCoordIj src/apps/testapps/testCoordIj.c)
add_h3_test(testBaseCells src/apps/testapps/testBaseCells.c)

add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 0)
add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 1)
@@ -0,0 +1,29 @@
/*
* Copyright 2017-2018 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdlib.h>
#include "constants.h"
#include "h3api.h"
#include "test.h"

SUITE(baseCells) {
TEST(getBaseCells) {
H3Index* baseCells = calloc(NUM_BASE_CELLS, sizeof(H3Index));
H3_EXPORT(getBaseCells)(baseCells);
t_assert(baseCells[0] == 0x8001fffffffffff, "correct first basecell");
t_assert(baseCells[121] == 0x80f3fffffffffff, "correct last basecell");
}
}
@@ -282,6 +282,14 @@ double H3_EXPORT(edgeLengthM)(int res);
int64_t H3_EXPORT(numHexagons)(int res);
/** @} */

/** @defgroup getBaseCells getBaseCells
* Functions for getBaseCells
* @{
*/
/** @brief provides all base cells */
void H3_EXPORT(getBaseCells)(H3Index *out);
/** @} */

/** @defgroup h3GetResolution h3GetResolution
* Functions for h3GetResolution
* @{
@@ -18,6 +18,7 @@
*/

#include "baseCells.h"
#include "h3Index.h"

/** @struct BaseCellOrient
* @brief base cell at a given ijk and required rotations into its system
@@ -886,3 +887,18 @@ Direction _getBaseCellDirection(int originBaseCell, int neighboringBaseCell) {
}
return INVALID_DIGIT;
}

/**
* getBaseCells generates all base cells storing them into the provided
* memory pointer.
*
* @param out H3Index* the memory to store the resulting base cells in
*/
void H3_EXPORT(getBaseCells)(H3Index* out) {
for (int bc = 0; bc < NUM_BASE_CELLS; bc++) {
H3Index baseCell = H3_INIT;
H3_SET_MODE(baseCell, H3_HEXAGON_MODE);
H3_SET_BASE_CELL(baseCell, bc);
out[bc] = baseCell;
}
}

0 comments on commit 4209291

Please sign in to comment.