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 H3Error for core indexing functions #436

Merged
merged 7 commits into from
Apr 9, 2021

Conversation

isaacbrodsky
Copy link
Collaborator

First implementation of the error code RFC work for v4. In this PR the error codes are applied to only geoToH3, h3ToGeo, and h3ToGeoBoundary in order to get feedback on these core functions first.

H3Error is not made an enum type since from what I could determine setting the base type of the enum is a C++ feature. (Although when I test using Apple Clang it permits it even with -std=c89?)

@coveralls
Copy link

coveralls commented Mar 7, 2021

Coverage Status

Coverage decreased (-0.1%) to 99.317% when pulling 63732e5 on isaacbrodsky:error-returns-h3togeo into ae07ee0 on uber:master.

Copy link
Collaborator

@dfellis dfellis left a comment

Choose a reason for hiding this comment

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

Nonblocking comments. Can always come up in a followup PR.

if (e == E_SUCCESS) {
h3Println(h);
} else {
h3Println(H3_NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally it would print some nice data about which error it ran into to stderr instead. :)

Comment on lines +74 to +96
typedef enum {
E_SUCCESS = 0, // Success (no error)
E_FAILED =
1, // The operation failed but a more specific error is not available
E_DOMAIN = 2, // Argument was outside of acceptable range (when a more
// specific error code is not available)
E_LATLON_DOMAIN =
3, // Latitude or longitude arguments were outside of acceptable range
E_RES_DOMAIN = 4, // Resolution argument was outside of acceptable range
E_CELL_INVALID = 5, // `H3Index` cell argument was not valid
E_DIR_EDGE_INVALID = 6, // `H3Index` directed edge argument was not valid
E_UNDIR_EDGE_INVALID =
7, // `H3Index` undirected edge argument was not valid
E_VERTEX_INVALID = 8, // `H3Index` vertex argument was not valid
E_PENTAGON = 9, // Pentagon distortion was encountered which the algorithm
// could not handle it
E_DUPLICATE_INPUT = 10, // Duplicate input was encountered in the arguments
// and the algorithm could not handle it
E_NOT_NEIGHBORS = 11, // `H3Index` cell arguments were not neighbors
E_RES_MISMATCH =
12, // `H3Index` cell arguments had incompatible resolutions
E_MEMORY = 13 // Necessary memory allocation failed
} H3ErrorCodes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be really nice if these comments were available in an exported array of strings (and/or a function to convert error code to error string). Could be used by the bindings as well as the filter apps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree, we duplicate a lot of this in JS

```

Finds the centroid of the index.

## h3ToGeoBoundary

```
void h3ToGeoBoundary(H3Index h3, GeoBoundary *gp);
H3Error h3ToGeoBoundary(H3Index h3, GeoBoundary *gp);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This should be gb?

printf(" ");
geoPrintlnNoFmt(&g);
H3Index h;
if (!H3_EXPORT(geoToH3)(&g, res, &h)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use != E_SUCCESS in this and similar cases?

Comment on lines +74 to +96
typedef enum {
E_SUCCESS = 0, // Success (no error)
E_FAILED =
1, // The operation failed but a more specific error is not available
E_DOMAIN = 2, // Argument was outside of acceptable range (when a more
// specific error code is not available)
E_LATLON_DOMAIN =
3, // Latitude or longitude arguments were outside of acceptable range
E_RES_DOMAIN = 4, // Resolution argument was outside of acceptable range
E_CELL_INVALID = 5, // `H3Index` cell argument was not valid
E_DIR_EDGE_INVALID = 6, // `H3Index` directed edge argument was not valid
E_UNDIR_EDGE_INVALID =
7, // `H3Index` undirected edge argument was not valid
E_VERTEX_INVALID = 8, // `H3Index` vertex argument was not valid
E_PENTAGON = 9, // Pentagon distortion was encountered which the algorithm
// could not handle it
E_DUPLICATE_INPUT = 10, // Duplicate input was encountered in the arguments
// and the algorithm could not handle it
E_NOT_NEIGHBORS = 11, // `H3Index` cell arguments were not neighbors
E_RES_MISMATCH =
12, // `H3Index` cell arguments had incompatible resolutions
E_MEMORY = 13 // Necessary memory allocation failed
} H3ErrorCodes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree, we duplicate a lot of this in JS

@isaacbrodsky isaacbrodsky force-pushed the error-returns-h3togeo branch from 2c87037 to 70d4b6a Compare April 8, 2021 00:35
Comment on lines 33 to 34
SUITE(h3UniEdge) {
TEST(h3IndexesAreNeighbors) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert these names?

Copy link
Collaborator

@dfellis dfellis left a comment

Choose a reason for hiding this comment

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

Just one accidental revert when you rebased that needs to be cleaned up, as far as I can see.

@isaacbrodsky
Copy link
Collaborator Author

I updated this PR based on master, note that I removed the website changes until we're ready to make a v4 website

@isaacbrodsky isaacbrodsky merged commit 71e8851 into uber:master Apr 9, 2021
@isaacbrodsky isaacbrodsky deleted the error-returns-h3togeo branch April 9, 2021 17:02
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.

5 participants