-
Notifications
You must be signed in to change notification settings - Fork 471
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
Change float to double in vec2d #652
Conversation
H3Index indexes[] = {0, 0, 0, 0, 0, 0, 0}; | ||
int numHexes = 7; | ||
|
||
for (int res = 1; res < 15; res++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that even with this fix, both of these tests fail at res 0. I'm not sure where the additional imprecision lies for that case, but I think we need vertex mode to fix it.
This may address uber/h3-py#277 - it's probably worth checking whether that case is now covered. |
Please add to the CHANGELOG describing this change. As I understand it, the impact is that cellToBoundary results for distortion vertexes were calculated at a lower precision (and cellToLinkedMultiPolygon and edge boundary calculations that use the same code path). Please also add a test for one or more of the specific cells in the issue. While cellsToLinkedMultiPolygon exercises this today, it will not cover this in the future because the plan is to change that function to not do coordinate comparisons. |
It looks like the tests are failing since distortion vertexes will be calculated slightly differently due to the precision change. |
I see a few things in the tests:
Does any of this raise concerns? I don't think we've promised that the geo boundary would remain stable within FPE, but it seems possible this might come across as a breaking change for some users. |
Actually, testing the output here what I see are failures in |
Ok, I've fixed the tests:
The res 1 and res 3 cells in the issue should be covered by the regen'd test files - I don't think we need extra tests for this (since the issue was not that the vertices were wrong, but that we might want to use Now the question is: Do we want to do this? On the one hand, I'd rather rely on a more precise calculation, and I feel weird about the idea that the canonical boundaries are defined by a bad implementation detail. On the other hand, I don't know the ramifications of changing the boundaries, which are sort of meant to be canonical and unchanging. One argument in favor is that presumably the more correct boundaries would enclose some points that are indexed to the cell but would otherwise fall outside the boundary with a point-in-spherical-poly check. |
@@ -747,8 +747,8 @@ void _faceIjkToCellBoundary(const FaceIJK *h, int res, int start, int length, | |||
adjacent hexagon edge will lie completely on a single icosahedron | |||
face, and no additional vertex is required. | |||
*/ | |||
bool isIntersectionAtVertex = | |||
_v2dEquals(&orig2d0, &inter) || _v2dEquals(&orig2d1, &inter); | |||
bool isIntersectionAtVertex = _v2dAlmostEquals(&orig2d0, &inter) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this remove the only two usage of _v2dEquals
So I guess you could either rename _v2dAlmostEquals
or get rid of _v2dEquals
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will drop the exact version
For a random sample of cells at a given res: | ||
|
||
./bin/mkRandGeoBoundary -n 5000 -r 5 > tests/inputfiles/rand05cells.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this specifically how rand05cells.txt was generated in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
@@ -297,4 +297,66 @@ SUITE(cellsToLinkedMultiPolygon) { | |||
|
|||
H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); | |||
} | |||
|
|||
TEST(kRingResolutions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kRing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh, will update
src/h3lib/lib/vec2d.c
Outdated
bool _v2dAlmostEquals(const Vec2d *v1, const Vec2d *v2) { | ||
return fabs(v1->x - v2->x) < FLT_EPSILON && | ||
fabs(v1->y - v2->y) < FLT_EPSILON; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can fix - is there a reason clang-format doesn't take care of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From some quick searches, clang-format does not do that.
So I tried for the better part of a day to construct a case where a point that indexed to the cell was not physically inside the cell boundary when the value was a
This has identified a number of cases with res 1 cells where the assertion fails, but in all cases it fails for both
I've verified that the only vertexes this affects are distortion vertexes - all others are unchanged. |
@nrabinowitz Doesn't |
|
b1542ba
to
082cf8a
Compare
OK, I found a single point (one of the float-based distortion vertexes) that fails my test with |
b15f3f1
to
e7d72e9
Compare
bool _v2dAlmostEquals(const Vec2d *v1, const Vec2d *v2) { | ||
return fabs(v1->x - v2->x) < FLT_EPSILON && | ||
fabs(v1->y - v2->y) < FLT_EPSILON; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function do comparisons in single precision float instead of double?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fabs
takes and returns a double, so the comparison here is still in double precision I believe. FLT_EPSILON
was chosen as a reasonable threshold here; a number of boundary tests fail when we use the stricter DBL_EPSILON
threshold.
Fixes #651
This changes
float
todouble
as suggested, and adds tests forcellsToLinkedMultiPolygon
(which depends on geo coordinate precision) that confirm improved precision in the output.