Skip to content

14213 Logic to determine which LineString matches direction #8

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mdorford
Copy link

@mdorford mdorford commented Jun 9, 2025

The logic to determine which LineString(s) to return is moved into GraphHopper.
Some nice advantages are:

  1. 'Both directions' is handled now.
  2. 'Unknown' is handled much better.
  3. Determination of direction is more accurate because it is based on the furthest-from-start endpoint of each LineString rather than end-to-start of one LineString. This will be much more acccurate in certain, unusual circumstances such as curvy mountain roads.
  4. Processing speed is faster because the cardinal directions no longer calculate bearing.

@mdorford mdorford changed the title Logic to determine which LineString matches direction 14213 Logic to determine which LineString matches direction Jun 9, 2025
@payneBrandon payneBrandon requested a review from Copilot June 9, 2025 21:30
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.PrecisionModel;
import org.locationtech.jts.geom.*;

Choose a reason for hiding this comment

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

question: are we using all the sub ".*" options in here to warrant importing them all?

Copy link
Author

Choose a reason for hiding this comment

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

The change in the imports was done by IntelliJ itself. I don't know where its threshold is. Maybe once it was using four or five imports from the same library it just automatically switches to import them all. Maybe it uses some more sophisticated way to decide or maybe it really needed them.

Copy link
Author

Choose a reason for hiding this comment

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

I cleanup up the imports.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds direction-based filtering to the buffer endpoint so that returned LineStrings can be limited to a requested compass direction.

  • Introduces a Direction enum and direction query parameter
  • Implements filterByDirection(...) with cardinal and diagonal logic
  • Refactors imports and delegates to bearing-based selection for non-cardinal directions
Comments suppressed due to low confidence (3)

web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java:92

  • Parsing the direction parameter with valueOf may throw IllegalArgumentException for invalid input. Consider validating the input or catching the exception and returning a 400 Bad Request with a clear error message.
Direction directionEnum = Direction.valueOf(directionUpperCase);

web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java:116

  • The new direction-filtering logic covers many branches (cardinal, diagonal, both/unknown). Please add unit tests for each direction and edge cases (empty list, BOTH, UNKNOWN).
private List<LineString> filterByDirection(List<LineString> lineStrings, Boolean buildUpstream, Direction directionEnum) {

web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java:78

  • The new direction parameter is not documented in the Javadoc or REST API docs. Please update the endpoint documentation to list valid values and describe the filtering behavior.
@QueryParam("direction") @DefaultValue("unknown") String direction,

Copy link

@payneBrandon payneBrandon left a comment

Choose a reason for hiding this comment

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

Couple questions

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.

3 participants