Skip to content

Commit

Permalink
ratio for calculation of bbox area should always be > 1 (uber#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebisteiner committed Oct 12, 2022
1 parent 59a4196 commit 3c6a2d0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/h3lib/lib/bbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ H3Error bboxHexEstimate(const BBox *bbox, int res, int64_t *out) {
p2.lat = bbox->south;
p2.lng = bbox->west;
double d = H3_EXPORT(greatCircleDistanceKm)(&p1, &p2);
double diffLng = fabs(p1.lng - p2.lng);
double diffLat = fabs(p1.lat - p2.lat);
double length = fmax(diffLng, diffLat);
double width = fmin(diffLng, diffLat);
double ratio = length / width;
// Derived constant based on: https://math.stackexchange.com/a/1921940
// Clamped to 3 as higher values tend to rapidly drag the estimate to zero.
double a = d * d / fmin(3.0, fabs((p1.lng - p2.lng) / (p1.lat - p2.lat)));
double a = d * d / fmin(3.0, ratio);

// Divide the two to get an estimate of the number of hexagons needed
double estimateDouble = ceil(a / pentagonAreaKm2);
Expand Down

0 comments on commit 3c6a2d0

Please sign in to comment.