Skip to content

Commit

Permalink
Optimization in getEdgeHexagons (#913)
Browse files Browse the repository at this point in the history
* Optimization in getEdgeHexagons

Replace 4 fpdiv's with 1 fpdiv and 4 fpmul's

* Updated changelog to add #913
  • Loading branch information
heshpdx authored Sep 26, 2024
1 parent 4899d29 commit 9cc20fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The public API of this library consists of the functions declared in file
### 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
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 9cc20fd

Please sign in to comment.