Skip to content

Implement turning circle support for u-turns#7388

Draft
Claude wants to merge 10 commits intomasterfrom
claude/use-turning-circles-u-turns
Draft

Implement turning circle support for u-turns#7388
Claude wants to merge 10 commits intomasterfrom
claude/use-turning-circles-u-turns

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 1, 2026

Implements support for using highway=turning_circle, highway=turning_loop, and highway=mini_roundabout nodes for u-turn maneuvers, eliminating unnecessary u-turn penalties at designated turning facilities.

Implementation

C++ Core Changes

  • Added has_turning_facility field to ExtractionTurn structure
  • Modified edge_based_graph_factory.cpp to detect turning facilities at intersections using ObstacleMap
  • Updated graph_compressor.cpp to handle turning facilities during node compression
  • Extended scripting_environment_lua.cpp to expose the field to Lua profiles (API v3 and v4)

Routing Logic

  • Modified profiles/car.lua to check turn.has_turning_facility before applying u-turn penalty
  • U-turns at turning facilities: 0 second penalty (no penalty)
  • U-turns elsewhere: 20 second penalty (existing behavior preserved)

Testing

  • Created comprehensive test suite in features/car/turning_circle_uturn.feature
  • Tests validate preference for turning facilities, multiple facility types, dead ends, one-way streets, and regression scenarios

Code Formatting

  • Applied clang-format-18 to src/extractor/graph_compressor.cpp to fix constructor alignment violations

Documentation

  • Added has_turning_facility field to process_turn API documentation in docs/profiles.md
  • Updated CHANGELOG.md with feature entry under Routing section

The has_turning_facility boolean is now available in Lua profiles:

function process_turn(profile, turn)
  if turn.is_u_turn then
    -- No penalty at designated turning facilities
    if not turn.has_turning_facility then
      turn.duration = turn.duration + profile.properties.u_turn_penalty
    end
  end
end

Design Decisions

  • Penalty Amount: 0 seconds at turning facilities (simplest approach)
  • Scope: Includes turning_circle, turning_loop, and mini_roundabout
  • Profile: Car profile only (extensible to others later)

Files Modified

  • include/extractor/extraction_turn.hpp - Add field (~9 lines)
  • src/extractor/edge_based_graph_factory.cpp - Detect facility (~3 lines)
  • src/extractor/graph_compressor.cpp - Handle compression & formatting (~18 lines)
  • src/extractor/scripting_environment_lua.cpp - Expose to Lua (~4 lines)
  • profiles/car.lua - Adjust penalty (~5 lines)
  • features/car/turning_circle_uturn.feature - Tests (new, ~140 lines)
  • CHANGELOG.md - Document feature (~1 line)
  • docs/profiles.md - Document API (~1 line)

Total: ~180 lines across 8 files

Original prompt

This section details on the original issue you should resolve

<issue_title>highway=turning_circle should be used for u-turns</issue_title>
<issue_description># Feature

OSRM should use nearby turning circles for u-turns.

Current situation

OSRM ignores perfectly good turning opportunities and instead routes you literally through the woods, like here: (Note that there is no road where OSRM tells you to turn!)

Screenshot from 2024-12-31 11-47-19

https://map.project-osrm.org/?z=18&center=46.562307%2C11.718265&loc=46.562099%2C11.718770&loc=46.562176%2C11.718206&loc=46.562121%2C11.718603&hl=en&alt=0&srv=0

Maybe duplicate of: #620, but that one was closed without proper resolution and I'm not allowed to reopen it.</issue_description>

<agent_instructions>Investigate how to do this. Propose an analysis and a plan including test coverage. But don’t start coding just yet. </agent_instructions>

Comments on the Issue (you are @claude[agent] in this section)

Todo

  • Find examples for turning facilities in the Monaco test set
  • Add tape tests for each of the above examples
  • Post comment with a screenshot showing changes routing behavior

@Claude Claude AI changed the title [WIP] Add support for using turning circles in u-turn routing Investigation: Enable turning circles for u-turns Mar 1, 2026
@DennisOSRM
Copy link
Collaborator

@claude[agent] proceed with implementation

- Add has_turning_facility field to ExtractionTurn structure
- Detect turning facilities (turning_circle, turning_loop, mini_roundabout) at intersections
- Expose has_turning_facility to Lua profiles via scripting environment
- Modify car.lua to eliminate u-turn penalty at turning facilities
- Add comprehensive test scenarios for turning circle u-turn behavior

Co-authored-by: DennisOSRM <1067895+DennisOSRM@users.noreply.github.com>
@Claude
Copy link
Contributor Author

Claude AI commented Mar 1, 2026

@claude[agent] proceed with implementation

Implementation complete in commit 1e2d0e5.

Changes made:

  • Added has_turning_facility field to detect turning circles/loops at intersections
  • Modified car.lua to eliminate u-turn penalty (0s) at turning facilities vs. 20s elsewhere
  • Created comprehensive test suite in features/car/turning_circle_uturn.feature

Design decisions applied:

  • Zero penalty at turning facilities (simplest approach)
  • Includes turning_circle, turning_loop, and mini_roundabout
  • Car profile only

Total: ~165 lines across 6 files. Ready for build and test validation.

@Claude Claude AI changed the title Investigation: Enable turning circles for u-turns Enable turning circles for u-turns Mar 1, 2026
- Apply clang-format to graph_compressor.cpp
- Add turning circle feature to CHANGELOG.md
- Document has_turning_facility field in profiles.md

Co-authored-by: DennisOSRM <1067895+DennisOSRM@users.noreply.github.com>
@Claude Claude AI changed the title Enable turning circles for u-turns Fix formatting and update documentation for turning circle u-turn feature Mar 1, 2026
@DennisOSRM
Copy link
Collaborator

@claude[agent] update the title of the pr

@Claude
Copy link
Contributor Author

Claude AI commented Mar 1, 2026

@claude[agent] update the title of the pr

Updated PR title suggestion:

"Implement turning circle support for u-turns"

This better reflects that the PR implements the complete feature (detection, routing logic, tests, and documentation) rather than just formatting/documentation fixes.

Alternative titles:

  • "Add support for using turning circles in u-turn routing"
  • "Use turning_circle, turning_loop, and mini_roundabout for u-turns"

The current commits include both the implementation (1e2d0e5) and documentation/formatting (080cf39).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr view --json title,body /home/REDACTED/.nvm/bash_completion /home/REDACTED/.nvm/install.sh /home/REDACTED/.nvm/nvm-exec /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test (http block)
    • Triggering command: /usr/bin/gh gh pr edit --title Implement turning circle support for u-turns /home/REDACTED/.nvm/bash_completion /home/REDACTED/.nvm/install.sh /home/REDACTED/.nvm/nvm-exec /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Claude Claude AI changed the title Fix formatting and update documentation for turning circle u-turn feature Implement turning circle support for u-turns Mar 1, 2026
Copilot AI and others added 7 commits March 2, 2026 06:42
* Initial plan

* Fix turning facility detection by adding explicit highway-to-obstacle-type mapping

The Lua profile was attempting to use obstacle_type[highway] as a table lookup,
but Sol2's new_enum() doesn't automatically create string-indexed access. Added
an explicit mapping table (highway_to_obstacle_type) to correctly map highway tag
values like "turning_circle", "turning_loop", and "mini_roundabout" to their
corresponding obstacle type enums.

This fixes the issue where turning facilities were not being recognized during
route calculation, causing u-turns to use direct u-turn penalties instead of
taking advantage of designated turning facilities.

Co-authored-by: DennisOSRM <1067895+DennisOSRM@users.noreply.github.com>

---------

Co-authored-by: anthropic-code-agent[bot] <242468646+Claude@users.noreply.github.com>
Co-authored-by: DennisOSRM <1067895+DennisOSRM@users.noreply.github.com>
- Add bearings (90,10 270,10) to all directional u-turn scenarios so
  OSRM is forced to make a real turn rather than returning a trivial
  zero-distance route for same start/end waypoints
- Add no_u_turn turn restrictions to scenarios 1-3, modeling the
  real-world case where turning circles exist precisely because
  direct u-turns on the road are restricted
- Fix expected routes: side-street turning facilities produce
  abc,bd,bd,abc,abc (not abc,bd,abc) since the outbound and
  inbound traversals of the spur road are reported separately
- Fix expected turns: continue uturn + turn left (not turn right twice)
- Fix one-way scenario: with bd being one-way the turning circle at d
  is inaccessible for u-turns, so OSRM correctly falls back to a
  regular u-turn on the main road (abc,abc,abc, continue uturn)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Instead of zero penalty, u-turns at turning circles, turning loops,
and mini roundabouts now incur a small 5-second delay. This reflects
the real-world time cost of navigating the facility while still being
much cheaper than a regular u-turn penalty (20 seconds).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

highway=turning_circle should be used for u-turns

3 participants