diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index b46d154c0..2f6124854 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index d29dd51d9..1a2927753 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/apps/testapps/testCompactCells.c b/src/apps/testapps/testCompactCells.c index 56ae5baee..bab73abc2 100644 --- a/src/apps/testapps/testCompactCells.c +++ b/src/apps/testapps/testCompactCells.c @@ -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); diff --git a/src/h3lib/lib/algos.c b/src/h3lib/lib/algos.c index 949988a08..1b20bf5ef 100644 --- a/src/h3lib/lib/algos.c +++ b/src/h3lib/lib/algos.c @@ -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) {