Skip to content

Commit

Permalink
Merge branch 'master' into compact_all_res1_tes-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacbrodsky committed Oct 1, 2024
2 parents 51ba258 + d6f2701 commit 7ee428c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ on:

jobs:
tests:
name: Test Compile ${{ matrix.build_type }}
runs-on: macos-latest
name: ${{ matrix.build_type }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-12, macos-13, macos-latest]
build_type: ["Debug", "Release"]

steps:
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ The public API of this library consists of the functions declared in file
[h3api.h.in](./src/h3lib/include/h3api.h.in).

## [Unreleased]
### Fixed
- Fixed compacting all or many resolution 1 cells (#919)

### Changed
- Replace internal algorithm for `polygonToCells` with a new version that is more memory-efficient (#785)
- Reorganize tests into public / internal. (#762)
- Performance enhancement for aarch64, may improve other platforms (#790, #792, #852, #905)
- Performance enhancement for aarch64, may improve other platforms (#790, #792, #852, #905, #913)
- `clang-format` upgraded to version 14. (#834)
- Fixed tests that incorrectly did not test resolution 15. (#820)
- Use `CMAKE_INSTALL_LIBDIR` when choosing where to install library files. (#819)
Expand Down
53 changes: 47 additions & 6 deletions src/apps/testapps/testCompactCells.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,58 @@ SUITE(compactCells) {
t_assertSuccess(
H3_EXPORT(uncompactCells)(cells0, numRes0, cells1, numRes1, 1));

// Fails at compactCells.
// However:
// Passes if numUncompacted <= 40
// Fails if numUncompacted >= 41.
int64_t numUncompacted = numRes1;
t_assertSuccess(H3_EXPORT(compactCells)(cells1, out, numUncompacted));

// TODO: check that output matches cells0
// Assert that the output of this function matches exactly the set of
// res 0 cells
size_t foundCount = 0;
for (size_t res1Idx = 0; res1Idx < numRes1; res1Idx++) {
H3Index compactedCell = out[res1Idx];

if (compactedCell) {
for (size_t res1DupIdx = 0; res1DupIdx < res1Idx;
res1DupIdx++) {
t_assert(out[res1DupIdx] != compactedCell,
"Duplicated output found");
}

bool found = false;
for (size_t res0Idx = 0; res0Idx < numRes0; res0Idx++) {
if (cells0[res0Idx] == compactedCell) {
found = true;
break;
}
}
t_assert(found, "Res 0 cell is found");
foundCount++;
}
}
t_assert(foundCount == numRes0, "all res 0 cells found");

free(cells0);
free(cells1);
free(out);
}

TEST(allRes1_variousRanges) {
const int64_t numRes0 = 122;
const int64_t numRes1 = 842;
H3Index *cells0 = calloc(numRes0, sizeof(H3Index));
H3Index *cells1 = calloc(numRes1, sizeof(H3Index));
H3Index *out = calloc(numRes1, sizeof(H3Index));

H3_EXPORT(getRes0Cells)(cells0);
t_assert(cells0[0] == 0x8001fffffffffff,
"got expected first res0 cell");

t_assertSuccess(
H3_EXPORT(uncompactCells)(cells0, numRes0, cells1, numRes1, 1));

// Test various (but not all possible combinations) ranges of res 1
// cells
for (int64_t offset = 0; offset < numRes1; offset++) {
for (numUncompacted = numRes1 - offset; numUncompacted >= 0;
for (int64_t numUncompacted = numRes1 - offset; numUncompacted >= 0;
numUncompacted--) {
memset(out, 0, sizeof(H3Index) * numRes1);

Expand Down
9 changes: 5 additions & 4 deletions src/h3lib/lib/algos.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,13 @@ H3Error _getEdgeHexagons(const GeoLoop *geoloop, int64_t numHexagons, int res,
}
for (int64_t j = 0; j < numHexesEstimate; j++) {
LatLng interpolate;
double invNumHexesEst = 1.0 / numHexesEstimate;
interpolate.lat =
(origin.lat * (numHexesEstimate - j) / numHexesEstimate) +
(destination.lat * j / numHexesEstimate);
(origin.lat * (numHexesEstimate - j) * invNumHexesEst) +
(destination.lat * j * invNumHexesEst);
interpolate.lng =
(origin.lng * (numHexesEstimate - j) / numHexesEstimate) +
(destination.lng * j / numHexesEstimate);
(origin.lng * (numHexesEstimate - j) * invNumHexesEst) +
(destination.lng * j * invNumHexesEst);
H3Index pointHex;
H3Error e = H3_EXPORT(latLngToCell)(&interpolate, res, &pointHex);
if (e) {
Expand Down

0 comments on commit 7ee428c

Please sign in to comment.