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.
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. |
| */ | ||
| bool isIntersectionAtVertex = | ||
| _v2dEquals(&orig2d0, &inter) || _v2dEquals(&orig2d1, &inter); | ||
| bool isIntersectionAtVertex = _v2dAlmostEquals(&orig2d0, &inter) || |
There was a problem hiding this comment.
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.
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.
Is this specifically how rand05cells.txt was generated in this PR?
| H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); | ||
| } | ||
|
|
||
| TEST(kRingResolutions) { |
There was a problem hiding this comment.
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; | ||
| } No newline at end of file |
There was a problem hiding this comment.
nit: newline at end of file
There was a problem hiding this comment.
Can fix - is there a reason clang-format doesn't take care of that?
There was a problem hiding this comment.
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.
Why does this function do comparisons in single precision float instead of double?
There was a problem hiding this comment.
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
floattodoubleas suggested, and adds tests forcellsToLinkedMultiPolygon(which depends on geo coordinate precision) that confirm improved precision in the output.