| 1253 | } |
| 1254 | |
| 1255 | void Sol2ScriptingEnvironment::ProcessTurn(ExtractionTurn &turn) |
| 1256 | { |
| 1257 | auto &context = GetSol2Context(); |
| 1258 | |
| 1259 | switch (context.api_version) |
| 1260 | { |
| 1261 | case 4: |
| 1262 | case 3: |
| 1263 | case 2: |
| 1264 | if (context.has_turn_penalty_function) |
| 1265 | { |
| 1266 | auto luares = context.turn_function(context.profile_table, std::ref(turn)); |
| 1267 | if (!luares.valid()) |
| 1268 | handle_lua_error(luares); |
| 1269 | |
| 1270 | // Turn weight falls back to the duration value in deciseconds |
| 1271 | // or uses the extracted unit-less weight value |
| 1272 | if (context.properties.fallback_to_duration) |
| 1273 | turn.weight = turn.duration; |
| 1274 | else |
| 1275 | // cap turn weight to max turn weight, which depend on weight precision |
| 1276 | turn.weight = std::min(turn.weight, context.properties.GetMaxTurnWeight()); |
| 1277 | } |
| 1278 | |
| 1279 | break; |
| 1280 | case 1: |
| 1281 | if (context.has_turn_penalty_function) |
| 1282 | { |
| 1283 | auto luares = context.turn_function(std::ref(turn)); |
| 1284 | if (!luares.valid()) |
| 1285 | handle_lua_error(luares); |
| 1286 | |
| 1287 | // Turn weight falls back to the duration value in deciseconds |
| 1288 | // or uses the extracted unit-less weight value |
| 1289 | if (context.properties.fallback_to_duration) |
| 1290 | turn.weight = turn.duration; |
| 1291 | } |
| 1292 | |
| 1293 | break; |
| 1294 | case 0: |
| 1295 | if (context.has_turn_penalty_function) |
| 1296 | { |
| 1297 | if (turn.number_of_roads > 2) |
| 1298 | { |
| 1299 | // Get turn duration and convert deci-seconds to seconds |
| 1300 | turn.duration = static_cast<double>(context.turn_function(turn.angle)) / 10.; |
| 1301 | BOOST_ASSERT(turn.weight == 0); |
| 1302 | |
| 1303 | // add U-turn penalty |
| 1304 | if (turn.is_u_turn) |
| 1305 | turn.duration += context.properties.GetUturnPenalty(); |
| 1306 | } |
| 1307 | else |
| 1308 | { |
| 1309 | // Use zero turn penalty if it is not an actual turn. This heuristic is necessary |
| 1310 | // since OSRM cannot handle looping roads/parallel roads |
| 1311 | turn.duration = 0.; |
| 1312 | } |
no test coverage detected