Skip to content

Conversation

@dnesbitt61
Copy link
Member

Clamp grades and weighted grades to +/- 3% on bridges and tunnels. Thispatches a bug where elevation is not corrected properly in elevation builder on consecutive connected bridges/tunnels. Since we "fix" the elevation returned along routes for these cases, this patch should fix cases where routes detour around these bridge/tunnel cases due to extreme weighted grade.

Issue

fixes #5708

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog
  • If you made changes to the lua files, update the taginfo too
  • If you made changes to a translation file, update transifex too

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

patches a bug where elevation is not corrected properly in elevation
builder on consecutive connected bridges/tunnels. Since we "fix" the
elevation returned along routes for these cases, this patch should fix
cases where routes detour around these bridge/tunnel cases due to
extreme weighted grade.
Comment on lines 242 to 247
if (max_up_slope > 3.0f) {
max_up_slope = 3.0f;
}
if (max_down_slope < -3.0f) {
max_down_slope = -3.0f;
}
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
if (max_up_slope > 3.0f) {
max_up_slope = 3.0f;
}
if (max_down_slope < -3.0f) {
max_down_slope = -3.0f;
}
max_up_slope = std::min(3.0f, max_up_slope);
max_down_slope = std::max(-3.0f, max_down_slope);

kevinkreiser
kevinkreiser previously approved these changes Nov 20, 2025
Copy link
Member

@kevinkreiser kevinkreiser left a comment

Choose a reason for hiding this comment

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

while im certain there are tunnels/bridges who are steeper than +-3%, we cant know what they really are so this seems reasonable to me!

@dnesbitt61
Copy link
Member Author

We don't really know the elevation along bridges or tunnels. Just trying to prevent extreme weighted grades due to reading elevation "above" a tunnel or "below" a bridge.

Copy link
Member

@chrstnbwnkl chrstnbwnkl left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable and easy solution. Do you think this could be improved some time in the future by using actual routes through the tunnel (assuming its not a network of tunnels but rather one coherent path) and calculating the elevation diff between one side and the other? (a naive question perhaps, I've never looked at the elevation builder code before)

@dnesbitt61
Copy link
Member Author

dnesbitt61 commented Nov 20, 2025

Elevation builder "corrects" elevation on single bridge/tunnel edges by looking up elevation at each end and doing a linear interpolation between the 2 ends. This, of course, makes the bridge "flat" but removes the issue of elevation falling to the water below a bridge or rising to the hill above the tunnel (both of which are usually worse than incorrectly making the bridge/tunnel flat).
Elevation along a route is "corrected" in serializers.h for cases of consecutive bridges and tunnels - again by linear interpolation between the elevation at the beginning and end of the sequence of bridge/tunnel edges.
The only way I can think to find the true elevation along bridges/tunnels is by using actual ride data taken with accurate elevation sensors (e.g. bicycle computers with barometric pressure sensors for elevation).

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.

Consecutive tunnels/bridges have bad elevation and weighted grade

4 participants