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

Implement the traversal subcommands for the H3 cli #839

Merged
merged 13 commits into from
May 24, 2024

Conversation

dfellis
Copy link
Collaborator

@dfellis dfellis commented May 11, 2024

This implements all of the traversal subcommands.

The test suite has not been implemented yet, as I intend to rework the way CLI tests are structured, as requested by @nrabinowitz.

But I'm putting this up now before I start on that in case there are any changes to the input and output formats to be done before I start codifying them into the tests.

@dfellis dfellis self-assigned this May 11, 2024
@coveralls
Copy link

coveralls commented May 11, 2024

Coverage Status

coverage: 98.826% (+0.002%) from 98.824%
when pulling 336c3b9 on cli-traversal-subcommands
into 77b6215 on master.

src/apps/filters/h3.c Outdated Show resolved Hide resolved
src/apps/filters/h3.c Outdated Show resolved Hide resolved
src/apps/filters/h3.c Outdated Show resolved Hide resolved
src/h3lib/include/h3api.h.in Outdated Show resolved Hide resolved
src/h3lib/lib/h3Index.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@isaacbrodsky isaacbrodsky left a comment

Choose a reason for hiding this comment

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

please note we will need to add tests, docs and fuzzer (or document its exemption, should never be a problem) for describeH3Error since it is in the public API.

@dfellis dfellis marked this pull request as ready for review May 18, 2024 02:47
src/h3lib/lib/h3Index.c Show resolved Hide resolved
if (err) {
return err;
}
H3Index *out = calloc(len, sizeof(H3Index));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to check for failed memory allocation 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.

Technically yes, but the app is going to die if this happens no matter what if this happens. But I'd also assume anybody on a machine that cannot allocate 8 bytes is having a much harder time, which is why I left that error handling out?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be much larger than 8 bytes with larger values of k. I think the program is better behaved if it explicitly tells the user that memory allocation failed rather than risk what happens with segfaulting, as in that case the user would have a much harder time tracking down what happened (they would need to attach a debugger to find out the problem is the k value.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed. There's now a print to stderr and an exit for each if the pointer is NULL.

.valueName = "distance",
.value = &k,
.helpText = "Maximum grid distance for the output set"};
Arg prettyArg = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, I'd skip - interested callers have access to plenty of other pretty-printing tools

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably true. But I wasn't sure if we should rely on the users having jq, especially if they're more on the traditional geospatial/data analyst side of things and less familiar with the terminal.

src/apps/filters/h3.c Show resolved Hide resolved
// Since we don't know *actually* how many cells are in the output (usually
// the max, but sometimes not), we need to do a quick scan to figure out the
// true length in order to properly serialize to a JSON array
int64_t trueLen = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is all for comma handling, right? Could this be simplified if you output a leading comma, not a trailing one, for every cell but out[0]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't do that because I can't assume out[0] has a value.

That's what I originally had until @isaacbrodsky pointed out my mistake there.

src/apps/filters/h3.c Show resolved Hide resolved
src/apps/filters/h3.c Show resolved Hide resolved
src/apps/filters/h3.c Show resolved Hide resolved
tests/cli/cellToBoundary.txt Outdated Show resolved Hide resolved
website/docs/api/misc.mdx Outdated Show resolved Hide resolved
if (err) {
return err;
}
H3Index *out = calloc(len, sizeof(H3Index));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be much larger than 8 bytes with larger values of k. I think the program is better behaved if it explicitly tells the user that memory allocation failed rather than risk what happens with segfaulting, as in that case the user would have a much harder time tracking down what happened (they would need to attach a debugger to find out the problem is the k value.)

@@ -13,56 +13,57 @@ The public API of H3 is covered in the following fuzzers:

| Function | File or status
| -------- | --------------
| latLngToCell | [fuzzerLatLngToCell](./fuzzerLatLngToCell.c)
| cellToLatLng | [fuzzerCellToLatLng](./fuzzerCellToLatLng.c)
| areNeighborCells | [fuzzerDirectedEdge](./fuzzerDirectedEdge.c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

for my curiosity - was this an editor feature you used to sort this? or did you manually alphabetize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simple :sort in vim after highlighting the lines I wanted to sort. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I figured it must be some vim thing :)

website/docs/api/misc.mdx Outdated Show resolved Hide resolved
Copy link
Collaborator

@nrabinowitz nrabinowitz left a comment

Choose a reason for hiding this comment

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

LGTM!

@dfellis dfellis merged commit c18cd89 into master May 24, 2024
34 checks passed
@dfellis dfellis deleted the cli-traversal-subcommands branch May 24, 2024 19:11
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.

None yet

4 participants