8000 WIP: Constrain longitude between -180 and 180 by zachasme · Pull Request #93 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WIP: Constrain longitude between -180 and 180 #93

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

Merged
merged 6 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/apps/testapps/testH3Api.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ TEST(h3ToGeoBoundary_classIIIEdgeVertex_exact) {
H3Index h3 = H3_EXPORT(stringToH3)("894cc536537ffff");
GeoBoundary boundary;
boundary.numVerts = 7;
setGeoDegs(&boundary.verts[0], 18.043333154, 293.721634765);
setGeoDegs(&boundary.verts[1], 18.042238363, 293.720709372);
setGeoDegs(&boundary.verts[2], 18.040818259, 293.721458061);
setGeoDegs(&boundary.verts[3], 18.040492975, 293.723132133);
setGeoDegs(&boundary.verts[4], 18.041040385, 293.723594817);
setGeoDegs(&boundary.verts[5], 18.041757122, 293.724032885);
setGeoDegs(&boundary.verts[6], 18.043007860, 293.723308818);
setGeoDegs(&boundary.verts[0], 18.043333154, -66.27836523500002);
setGeoDegs(&boundary.verts[1], 18.042238363, -66.27929062800001);
setGeoDegs(&boundary.verts[2], 18.040818259, -66.27854193899998);
setGeoDegs(&boundary.verts[3], 18.040492975, -66.27686786700002);
setGeoDegs(&boundary.verts[4], 18.041040385, -66.27640518300001);
setGeoDegs(&boundary.verts[5], 18.041757122, -66.27596711500001);
setGeoDegs(&boundary.verts[6], 18.043007860, -66.27669118199998);
t_assertBoundary(h3, &boundary);
}

END_TESTS();
END_TESTS();
10 changes: 6 additions & 4 deletions src/apps/testapps/testH3SetToLinkedGeo.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ TEST(hole) {
H3_EXPORT(h3SetToLinkedGeo)(set, numHexes, &polygon);

t_assert(countLinkedLoops(&polygon) == 2, "2 loops added to polygon");
t_assert(countLinkedCoords(polygon.first) == 6 * 3,
"All outer coords added to first loop");
t_assert(countLinkedCoords(polygon.first->next) == 6,
"All inner coords added to second loop");
// Note: This isn't strictly correct, and should be reversed when
// https://github.com/uber/h3/issues/53 is resolved
t_assert(countLinkedCoords(polygon.first) == 6,
"All inner coords added to first loop");
t_assert(countLinkedCoords(polygon.first->next) == 6 * 3,
"All outer coords added to second loop");

H3_EXPORT(destroyLinkedPolygon)(&polygon);
free(set);
Expand Down
7 changes: 5 additions & 2 deletions src/h3lib/lib/geoCoord.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ double constrainLng(double lng) {
while (lng > M_PI) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be nice to replace this with something constant time in the future

lng = lng - (2 * M_PI);
}
while (lng < -M_PI) {
lng = lng + (2 * M_PI);
}
return lng;
}

Expand Down Expand Up @@ -224,7 +227,7 @@ void _geoAzDistanceRads(const GeoCoord* p1, double az, double distance,
p2->lat = -M_PI_2;
p2->lon = 0.0L;
} else
p2->lon = _posAngleRads(p1->lon);
p2->lon = constrainLng(p1->lon);
} else // not due north or south
{
sinlat = sin(p1->lat) * cos(distance) +
Expand All @@ -248,7 +251,7 @@ void _geoAzDistanceRads(const GeoCoord* p1, double az, double distance,
if (sinlon < -1.0L) sinlon = -1.0L;
if (coslon > 1.0L) sinlon = 1.0L;
if (coslon < -1.0L) sinlon = -1.0L;
p2->lon = _posAngleRads(p1->lon + atan2(sinlon, coslon));
p2->lon = constrainLng(p1->lon + atan2(sinlon, coslon));
}
}
}
Expand Down
70 changes: 35 additions & 35 deletions tests/inputfiles/bc14r08cells.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
881c000001fffff
{
50.106680117 216.522671164
50.104984627 216.516710592
50.100824873 216.517383017
50.099949437 216.523758314
50.103568027 216.527026838
50.106680117 -143.477328836
50.104984627 -143.483289408
50.100824873 -143.482616983
50.099949437 -143.476241686
50.103568027 -143.472973162
}
881c000005fffff
{
50.098447935 216.513256142
50.100824873 216.517383017
50.104984627 216.516710592
50.106767710 216.511910473
50.104390715 216.507782989
50.100230694 216.508456233
50.098447935 -143.486743858
50.100824873 -143.482616983
50.104984627 -143.483289408
50.106767710 -143.488089527
50.104390715 -143.492217011
50.100230694 -143.491543767
}
881c000007fffff
{
50.100824873 216.517383017
50.098447935 216.513256142
50.095195618 216.515504665
50.094320218 216.521879736
50.096697099 216.526006510
50.099949437 216.523758314
50.100824873 -143.482616983
50.098447935 -143.486743858
50.095195618 -143.484495335
50.094320218 -143.478120264
50.096697099 -143.473993490
50.099949437 -143.476241686
}
881c000009fffff
{
50.110159008 216.523832601
50.106680117 216.522671164
50.103568027 216.527026838
50.103934338 216.532544198
50.107413158 216.533706709
50.110525737 216.529350786
50.110159008 -143.476167399
50.106680117 -143.477328836
50.103568027 -143.472973162
50.103934338 -143.467455802
50.107413158 -143.466293291
50.110525737 -143.470649214
}
881c00000bfffff
{
50.097063209 216.531523244
50.100681858 216.534792408
50.103934338 216.532544198
50.103568027 216.527026838
50.099949437 216.523758314
50.096697099 216.526006510
50.097063209 -143.468476756
50.100681858 -143.465207592
50.103934338 -143.467455802
50.103568027 -143.472973162
50.099949437 -143.476241686
50.096697099 -143.473993490
}
881c00000dfffff
{
50.111942652 216.519032318
50.110246845 216.513070762
50.106767710 216.511910473
50.104984627 216.516710592
50.106680117 216.522671164
50.110159008 216.523832601
50.111942652 -143.480967682
50.110246845 -143.486929238
50.106767710 -143.488089527
50.104984627 -143.483289408
50.106680117 -143.477328836
50.110159008 -143.476167399
}
12 changes: 6 additions & 6 deletions tests/inputfiles/bc14r08centers.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
881c000001fffff 50.103201 216.521510
881c000005fffff 50.102608 216.512583
881c000007fffff 50.097573 216.519631
881c000009fffff 50.107047 216.528189
881c00000bfffff 50.100316 216.529275
881c00000dfffff 50.108464 216.517871
881c000001fffff 50.103201 -143.478490
881c000005fffff 50.102608 -143.487417
881c000007fffff 50.097573 -143.480369
881c000009fffff 50.107047 -143.471811
881c00000bfffff 50.100316 -143.470725
881c00000dfffff 50.108464 -143.482129
90 changes: 45 additions & 45 deletions tests/inputfiles/bc14r09cells.txt
10000
< 98F5 td class="blob-code blob-code-addition js-file-line"> 50.103541400 -143.482411622
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
891c0000003ffff
{
50.104450101 216.521156123
50.103795870 216.519910268
50.103371455 216.519549221
50.102409316 216.520134319
50.102057919 216.520652044
50.102117500 216.522259443
50.102324725 216.522940467
50.103323690 216.523348879
50.103803169 216.523252071
50.104360999 216.521897016
50.104450101 -143.478843877
50.103795870 -143.480089732
50.103371455 -143.480450779
50.102409316 -143.479865681
50.102057919 -143.479347956
50.102117500 -143.477740557
50.102324725 -143.477059533
50.103323690 -143.476651121
50.103803169 -143.476747929
50.104360999 -143.478102984
}
891c000000bffff
{
50.100914312 216.519794115
50.102057919 216.520652044
50.102409316 216.520134319
50.103371455 216.519549221
50.103541400 216.517588378
50.102268091 216.516505269
50.100824873 216.517383017
50.100914312 -143.480205885
50.102057919 -143.479347956
50.102409316 -143.479865681
50.103371455 -143.480450779
50.103541400 -143.482411622
50.102268091 -143.483494731
50.100824873 -143.482616983
}
891c000000fffff
{
50.102057919 216.520652044
50.100914312 216.519794115
50.099860075 216.521347266
50.099949437 216.523758314
50.101447922 216.524370943
50.102324725 216.522940467
50.102117500 216.522259443
50.102057919 -143.479347956
50.100914312 -143.480205885
50.099860075 -143.478652734
50.099949437 -143.476241686
50.101447922 -143.475629057
50.102324725 -143.477059533
50.102117500 -143.477740557
}
891c0000013ffff
{
50.105698759 216.520802231
50.104450101 216.521156123
50.104360999 216.521897016
50.103803169 216.523252071
50.104404850 216.524994258
50.105843343 216.524703879
50.106680117 216.522671164
50.105698759 -143.479197769
50.104450101 -143.478843877
50.104360999 -143.478102984
50.103803169 -143.476747929
50.104404850 -143.475005742
50.105843343 -143.475296121
50.106680117 -143.477328836
}
891c0000017ffff
{
50.102069559 216.526414110
50.103568027 216.527026838
50.104404850 216.524994258
50.103803169 216.523252071
50.103323690 216.523348879
50.102324725 216.522940467
50.101447922 216.524370943
50.102069559 -143.473585890
50.103568027 -143.472973162
50.104404850 -143.475005742
50.103803169 -143.476747929
50.103323690 -143.476651121
50.102324725 -143.477059533
50.101447922 -143.475629057
}
891c000001bffff
{
50.105966052 216.518579401
50.104984627 216.516710592
50.103541400 216.517588378
50.103371455 216.519549221
50.103795870 216.519910268
50.104450101 216.521156123
50.105698759 216.520802231
50.105966052 -143.481420599
50.104984627 -143.483289408
50.103371455 -143.480450779
50.103795870 -143.480089732
50.104450101 -143.478843877
50.105698759 -143.479197769
}
12 changes: 6 additions & 6 deletions tests/inputfiles/bc14r09centers.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
891c0000003ffff 50.103201 216.521510
891c000000bffff 50.102098 216.518466
891c000000fffff 50.101004 216.522205
891c0000013ffff 50.105242 216.522962
891c0000017ffff 50.102946 216.524984
891c000001bffff 50.104717 216.518933
891c0000003ffff 50.103201 -143.478490
891c000000bffff 50.102098 -143.481534
891c000000fffff 50.101004 -143.477795
891c0000013ffff 50.105242 -143.477038
891c0000017ffff 50.102946 -143.475016
891c000001bffff 50.104717 -143.481067
Loading
0