Skip to content

Commit

Permalink
Fix for edge cases with bbox overlap and out-of-bounds polygons (#817)
Browse files Browse the repository at this point in the history
* Adds tests for CONTAINMENT_OVERLAPPING_BBOX and fixes the out-of-bounds write when using bbox overlap on a one-vertex polygon

* Fixes CONTAINMENT_OVERLAPPING results for polygons outside of the normal lat/lng range. The issue here was the test for cell-contains-polygon, which used latLngToCell, which will return results for out-of-bounds input. I updated this to include a bbox check first, which will exclude polygons with all points outside of the normal range.
  • Loading branch information
nrabinowitz committed Feb 13, 2024
1 parent b57df8b commit a523fc6
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 99 deletions.
26 changes: 0 additions & 26 deletions src/apps/testapps/testPolyfillInternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ static GeoPolygon sfGeoPolygon = {
{0.6599990002976, -2.1376771158464}}},
.numHoles = 0};

static GeoPolygon invalidGeoPolygon = {
.geoloop = {.numVerts = 4,
.verts = (LatLng[]){{NAN, -2.1364398519396},
{0.6595011102219, NAN},
{NAN, -2.1354884206045},
{0.6581220034068, NAN}}},
.numHoles = 0};

SUITE(polyfillInternal) {
TEST(iterInitPolygonCompact_errors) {
IterCellsPolygonCompact iter;
Expand Down Expand Up @@ -142,24 +134,6 @@ SUITE(polyfillInternal) {
t_assert(iter.cell == H3_NULL, "Got null output for invalid cell");
}

TEST(iterStepPolygonCompact_invalidPolygonErrors) {
IterCellsPolygonCompact iter;

// Start with a good polygon, otherwise we error out early
iter =
iterInitPolygonCompact(&sfGeoPolygon, 5, CONTAINMENT_OVERLAPPING);
t_assertSuccess(iter.error);

// Give the iterator a bad polygon and a cell at target res
iter._polygon = &invalidGeoPolygon;
iter.cell = 0x85283473fffffff;

iterStepPolygonCompact(&iter);
t_assert(iter.error == E_LATLNG_DOMAIN,
"Got expected error for invalid polygon");
t_assert(iter.cell == H3_NULL, "Got null output for invalid cell");
}

TEST(iterDestroyPolygonCompact) {
IterCellsPolygonCompact iter =
iterInitPolygonCompact(&sfGeoPolygon, 9, CONTAINMENT_CENTER);
Expand Down
Loading

0 comments on commit a523fc6

Please sign in to comment.