Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.42k stars 3.4k forks source link

Create a Wormhole-like Connection in car.lua for Global Routes #7033

Open maxmaxmaxmaxmaxmaxmax opened 1 month ago

maxmaxmaxmaxmaxmaxmax commented 1 month ago

Hi,

I’m working on a game and would like to generate something similar to a wormhole.

The basic idea is to modify the car.lua profile so that I can create a connection, for example, from the USA to Asia that goes through the Pacific, making the Earth “round.”

I was thinking that the simplest approach would be to create a connection between two points and set the distance to 0. However, this doesn’t seem to work as expected.

Does anyone have any ideas or could help me with this?

jcoupey commented 1 month ago

You could probably start with a real OSM extract and add "phantom" ways between chosen nodes. I don't think you can really "set the distance to 0", as distances are computed based on coordinates. What you could do instead is making sure the profile sets a weight (internal OSRM cost metric) of 0 to those ways. That would happen by tagging the special ways with a custom "highway"=worm_hole or similar, then adding the matching logic in lua.

maxmaxmaxmaxmaxmaxmax commented 1 month ago

Thanks so much @jcoupey . Could you help me find the documentation for the Lua files related to this? I’ve already tried adding them, but I couldn’t find any documentation on the profile Lua scripts. Which method would I need to adjust? I tried using process_way but without success. Also, that would change the distance in the calculation, which ultimately affects the fuel consumption. Would you recommend breaking out the “worm_hole” way in a second layer and determining the distance separately?

if data.highway == "worm_hole" then
        result.weight = 0     
  end

also this is not working

if data.highway == "worm_hole" then
        result.weight = 0     
        return 
  end
jcoupey commented 1 month ago

More background info on profiles: https://github.com/Project-OSRM/osrm-backend/blob/master/docs/profiles.md.