Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixes and tests for 0-, 1-, and 2-vertex geoloops and holes #816

Merged
merged 2 commits into from
Feb 9, 2024

Conversation

nrabinowitz
Copy link
Collaborator

This includes the fixes from #800, plus one more fix for estimating a 1-vertex polygon. Includes the following tests:

  • 0-vertex polygon, all modes
  • 1-vertex polygon, all modes
  • 2-vertex polygon, all modes
  • polygon with 0-vertex hole, all modes
  • polygon with 1-vertex hole, all modes
  • polygon with 2-vertex hole, all modes

Hopefully #800 will be green once rebased on top of this.

@coveralls
Copy link

coveralls commented Feb 9, 2024

Coverage Status

coverage: 98.829% (+0.005%) from 98.824%
when pulling c9154c3 on nrabinowitz:polyfill-pathological
into 8207a9c on uber:master.

Comment on lines 624 to 667
TEST(polygonToCellsNullPolygon) {
int64_t numHexagons;
t_assertSuccess(H3_EXPORT(maxPolygonToCellsSizeExperimental)(
&nullGeoPolygon, 9, CONTAINMENT_CENTER, &numHexagons));
t_assert(numHexagons == 0, "got expected estimated size");
H3Index *hexagons = calloc(numHexagons, sizeof(H3Index));

t_assertSuccess(H3_EXPORT(polygonToCellsExperimental)(
&nullGeoPolygon, 9, CONTAINMENT_CENTER, hexagons));
int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons);

t_assert(actualNumIndexes == 0, "got expected polygonToCells size");
free(hexagons);
}

TEST(polygonToCellsNullPolygon_full) {
int64_t numHexagons;
t_assertSuccess(H3_EXPORT(maxPolygonToCellsSizeExperimental)(
&nullGeoPolygon, 9, CONTAINMENT_FULL, &numHexagons));
t_assert(numHexagons == 0, "got expected estimated size");
H3Index *hexagons = calloc(numHexagons, sizeof(H3Index));

t_assertSuccess(H3_EXPORT(polygonToCellsExperimental)(
&nullGeoPolygon, 9, CONTAINMENT_FULL, hexagons));
int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons);

t_assert(actualNumIndexes == 0, "got expected polygonToCells size");
free(hexagons);
}

TEST(polygonToCellsNullPolygon_overlapping) {
int64_t numHexagons;
t_assertSuccess(H3_EXPORT(maxPolygonToCellsSizeExperimental)(
&nullGeoPolygon, 9, CONTAINMENT_OVERLAPPING, &numHexagons));
t_assert(numHexagons == 0, "got expected estimated size");
H3Index *hexagons = calloc(numHexagons, sizeof(H3Index));

t_assertSuccess(H3_EXPORT(polygonToCellsExperimental)(
&nullGeoPolygon, 9, CONTAINMENT_OVERLAPPING, hexagons));
int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons);

t_assert(actualNumIndexes == 0, "got expected polygonToCells size");
free(hexagons);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe these could be collapsed to the same test and just loop through which flags to test? Might be easier to read that way?

Copy link
Collaborator Author

@nrabinowitz nrabinowitz Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that's what you did in #800. I can collapse this one, and the null hole, but not the other two (where OVERLAPPING and FULL behave differently)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually this is the only one I can collapse, the others have different results per mode

@nrabinowitz nrabinowitz merged commit b57df8b into uber:master Feb 9, 2024
34 checks passed
@nrabinowitz nrabinowitz deleted the polyfill-pathological branch February 9, 2024 16:08

t_assert(actualNumIndexes == 1, "got expected polygonToCells size");
free(hexagons);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a test missing in this PR for polygonToCellsPointPolygon_overlappingBbox (and same for the below), which is why the fuzzer is still failing

Comment on lines +714 to +718
// Special case: 1-vertex polygon
if (polygon->geoloop.numVerts == 1) {
*out = 1;
return E_SUCCESS;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In overlapping BBOX mode, this will not be correct as more than one cell bounding box may overlap a vertex.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I'll have a new PR up for this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants