Skip to content

All remaining subcommands for the h3 cli program#924

Merged
dfellis merged 37 commits intomasterfrom
h3-cli-remaining-subcommands
Oct 16, 2024
Merged

All remaining subcommands for the h3 cli program#924
dfellis merged 37 commits intomasterfrom
h3-cli-remaining-subcommands

Conversation

@dfellis
Copy link
Collaborator

@dfellis dfellis commented Oct 10, 2024

After implementing the region subcommands, all of the rest documented on h3geo.org were "trivial" as all patterns of subcommand had been implemented, so I just slogged through writing all of them while I had the drive to do it. ;)

There may be some test failures with degsToRads and friends due to floating point rounding errors on different CPU architectures. I hope not, but if so, then I'll have to figure out how to test them better.

  • areNeighborCells
  • cellsToDirectedEdge
  • isValidDirectedEdge
  • getDirectedEdgeOrigin
  • getDirectedEdgeDestination
  • directedEdgeToCells
  • originToDirectedEdges
  • directedEdgeToBoundary
  • cellToVertex
  • cellToVertexes
  • vertexToLatLng
  • isValidVertex
  • degsToRads radsToDegs
  • getHexagonAreaAvgKm2
  • getHexagonAreaAvgM2
  • cellAreaRads2
  • cellAreaKm2
  • cellAreaM2
  • getHexagonEdgeLengthAvgKm
  • getHexagonEdgeLengthAvgM
  • edgeLengthKm
  • edgeLengthM
  • edgeLengthRads
  • getNumCells
  • getRes0Cells
  • getPentagons
  • pentagonCount
  • greatCircleDistanceKm
  • greatCircleDistanceM
  • greatCircleDistanceRads
  • describeH3Error

@dfellis dfellis self-assigned this Oct 10, 2024
@dfellis
Copy link
Collaborator Author

dfellis commented Oct 10, 2024

Oh, this currently includes the region subcommands in this PR, since it depends on that one, but once it gets approved and merged, this'll be reduced to only the new commands.

I did (almost) every command in a separate commit, for easier reviewing.

@coveralls
Copy link

coveralls commented Oct 10, 2024

Coverage Status

coverage: 98.782%. remained the same
when pulling d63accf on h3-cli-remaining-subcommands
into 33681ff on master.

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.

This looks good to me, pending #923 merging in

@dfellis dfellis force-pushed the h3-cli-remaining-subcommands branch 3 times, most recently from cd00c06 to de30ae0 Compare October 14, 2024 20:04
@dfellis dfellis force-pushed the h3-cli-remaining-subcommands branch from d5b44ad to d63accf Compare October 14, 2024 20:54
Comment on lines +2204 to +2209
SUBCOMMAND(pentagonCount, "Returns 12") {
Arg *args[] = {&pentagonCountArg, &helpArg};
PARSE_SUBCOMMAND(argc, argv, args);
printf("12\n");
return E_SUCCESS;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if we really need to bind this, but ok

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 personally find it hilarious, so I want it in. ;)

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.

A few questions and nits, but otherwise looks great!

Arg *args[] = {&isValidDirectedEdgeArg, &helpArg, &cellArg};
PARSE_SUBCOMMAND(argc, argv, args);
bool isValid = H3_EXPORT(isValidDirectedEdge)(cell);
printf("%s", isValid ? "true\n" : "false\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

No strong opinion here, but would 1 and 0 be more flexible outputs?

return err;
}
// Using WKT formatting for the output. TODO: Add support for JSON
// formatting
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 weird that we use WKT here but raw lat,lng polygons for cellsToMultiPolygon?

if (err) {
return err;
}
printf("%" PRIx64 "\n", out);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Should we use h3Println here?

.helpText = "Angle in radians"};
Arg *args[] = {&radsToDegsArg, &radArg, &helpArg};
PARSE_SUBCOMMAND(argc, argv, args);
printf("%.10lf\n", H3_EXPORT(radsToDegs)(rad));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Worth making a common printDouble function to help us always print with the same format?

hasPrinted = true;
}
}
printf("]\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

For polygonToCells we print newline-delimited cells, but most of the multi-cell outputs here use JSON arrays. Should this be consistent?

"to use greatCircleDistanceKm");
exit(1);
}
FILE *fp = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: It feels like we could share a lot of code between greatCircleDistanceKm and greatCircleDistanceRads and greatCircleDistanceM

@dfellis
Copy link
Collaborator Author

dfellis commented Oct 16, 2024

Discussed offline, some of the inconsistencies will be taken care of in a follow-up PR.

@dfellis dfellis merged commit a434272 into master Oct 16, 2024
@dfellis dfellis deleted the h3-cli-remaining-subcommands branch October 16, 2024 17:30
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.

4 participants