8000 Add docs for h3Distance by isaacbrodsky · Pull Request #101 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add docs for h3Distance #101

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 1 commit into from
Jul 30, 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
13 changes: 13 additions & 0 deletions docs/api/distance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Distance functions

## h3Distance

```
int h3Distance(H3Index origin, H3Index h3);
```

Returns the distance in grid cells between the two indexes.

Returns a negative number if finding the distance failed. Finding the distance can fail because the two
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it worth outlining the meaning of the different error codes here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

h3Distance itself only returns -1 on any kind of error right now, it doesn't preserve the more specific error code from h3ToIjk

indexes are not comparable (different resolutions), too far apart, or are separated by pentagonal
distortion.
12 changes: 7 additions & 5 deletions examples/distance.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/
/**
* Example program that calculates the distance in kilometers between two
* hexagon indices.
* Example program that calculates the distance in hexagons and in kilometers
* between two hexagon indices.
*/

// mean Earth radius
Expand Down Expand Up @@ -59,12 +59,14 @@ int main(int argc, char *argv[]) {
printf(
5E3C "origin: (%lf, %lf)\n"
"destination: (%lf, %lf)\n"
"distance: %lfkm\n",
"grid distance: %d\n"
"distance in km: %lfkm\n",
radsToDegs(geoHQ1.lat), radsToDegs(geoHQ1.lon), radsToDegs(geoHQ2.lat),
radsToDegs(geoHQ2.lon),
radsToDegs(geoHQ2.lon), h3Distance(h3HQ1, h3HQ2),
haversineDistance(geoHQ1.lat, geoHQ1.lon, geoHQ2.lat, geoHQ2.lon));
// Output:
// origin: (37.775236, 237.580245)
// destination: (37.789991, 237.597879)
// distance: 2.256850km
// grid distance: 2340
// distance in km: 2.256850km
}
0