Permalink
Browse files

Merge pull request #176 from zachasme/feature-get-basecells

Add function to get all base cells
  • Loading branch information...
nrabinowitz committed Jan 9, 2019
2 parents f844901 + 8539cfb commit d0a0860db8a9dfd4372e90aaaf18afefbbd45e90
Showing with 67 additions and 1 deletion.
  1. +2 −1 CHANGELOG.md
  2. +1 −0 CMakeLists.txt
  3. +30 −0 src/apps/testapps/testBaseCells.c
  4. +11 −0 src/h3lib/include/h3api.h.in
  5. +23 −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
- `getRes0Indexes` function for getting all base cells, and helper function `res0IndexCount` (#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,30 @@
/*
* Copyright 2017-2019 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 "h3api.h"
#include "test.h"

SUITE(baseCells) {
TEST(getRes0Indexes) {
int count = H3_EXPORT(res0IndexCount)();
H3Index* indexes = malloc(count * sizeof(H3Index));
H3_EXPORT(getRes0Indexes)(indexes);
t_assert(indexes[0] == 0x8001fffffffffff, "correct first basecell");
t_assert(indexes[121] == 0x80f3fffffffffff, "correct last basecell");
free(indexes);
}
}
@@ -282,6 +282,17 @@ double H3_EXPORT(edgeLengthM)(int res);
int64_t H3_EXPORT(numHexagons)(int res);
/** @} */

/** @defgroup getRes0Indexes getRes0Indexes
* Functions for getRes0Indexes
* @{
*/
/** @brief returns the number of resolution 0 indexes */
int H3_EXPORT(res0IndexCount)();

/** @brief provides all base cells */
void H3_EXPORT(getRes0Indexes)(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,25 @@ Direction _getBaseCellDirection(int originBaseCell, int neighboringBaseCell) {
}
return INVALID_DIGIT;
}

/**
* res0IndexCount returns the number of resolution 0 indexes
*
* @return int count of resolution 0 indexes
*/
int H3_EXPORT(res0IndexCount)() { return NUM_BASE_CELLS; }

/**
* getRes0Indexes generates all base cells storing them into the provided
* memory pointer. Buffer must be of size NUM_BASE_CELLS * sizeof(H3Index).
*
* @param out H3Index* the memory to store the resulting base cells in
*/
void H3_EXPORT(getRes0Indexes)(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 d0a0860

Please sign in to comment.