normalise angles only if an improvement
This commit is contained in:
parent
e965cf12f8
commit
23fd27422b
@ -63,8 +63,8 @@ Feature: Simple Turns
|
||||
|
||||
When I route I should get
|
||||
| waypoints | turns | route | intersections |
|
||||
| f,a | depart,arrive | road,road | true:0,true:15 false:90 false:180;true:180 |
|
||||
| e,a | depart,turn right,arrive | turn,road,road | true:270;true:15 false:90 false:180;true:180 |
|
||||
| f,a | depart,arrive | road,road | true:0,true:0 false:90 false:180;true:180 |
|
||||
| e,a | depart,turn right,arrive | turn,road,road | true:270;true:0 false:90 false:180;true:180 |
|
||||
|
||||
Scenario: Turning into splitting road
|
||||
Given the node map
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define OSRM_GEOJSON_DEBUG_LOGGER_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
@ -105,6 +106,8 @@ class GeojsonLogger
|
||||
std::lock_guard<std::mutex> guard(lock);
|
||||
ofs.open(logfile, std::ios::binary);
|
||||
|
||||
ofs << std::setprecision(12);
|
||||
|
||||
// set up a feature collection
|
||||
ofs << "{\n\t\"type\": \"FeatureCollection\",\n\t\"features\": [\n\t";
|
||||
// remember whether we need to output a colon
|
||||
|
@ -370,6 +370,17 @@ IntersectionNormalizer::AdjustBearingsForMergeAtDestination(const NodeID node_at
|
||||
: offset;
|
||||
};
|
||||
|
||||
// only if straighmost angles get smaller, we consider it an improvement
|
||||
auto const improves_straightmost = [&](auto const index, auto const offset) {
|
||||
const auto itr = next_intersection_along_road.FindClosestBearing(
|
||||
util::bearing::reverse(next_intersection_along_road[index].bearing));
|
||||
const auto angle = util::bearing::angleBetween(
|
||||
util::bearing::reverse(itr->bearing), next_intersection_along_road[index].bearing);
|
||||
|
||||
return util::angularDeviation(angle, STRAIGHT_ANGLE) >
|
||||
util::angularDeviation(angle + offset, STRAIGHT_ANGLE);
|
||||
};
|
||||
|
||||
// check if the u-turn edge at the next intersection could be merged to the left/right. If
|
||||
// this is the case and the road is not far away (see previous distance check), if
|
||||
// influences the perceived angle.
|
||||
@ -378,13 +389,17 @@ IntersectionNormalizer::AdjustBearingsForMergeAtDestination(const NodeID node_at
|
||||
const auto offset =
|
||||
get_offset(next_intersection_along_road[0], next_intersection_along_road[1]);
|
||||
|
||||
const auto corrected_offset = get_corrected_offset(
|
||||
offset,
|
||||
road,
|
||||
intersection[(intersection.size() + index - 1) % intersection.size()]);
|
||||
// at the target intersection, we merge to the right, so we need to shift the current
|
||||
// angle to the left
|
||||
road.bearing = adjustAngle(road.bearing, corrected_offset);
|
||||
if (improves_straightmost(0, -offset) && improves_straightmost(1, offset))
|
||||
{
|
||||
const auto corrected_offset = get_corrected_offset(
|
||||
offset,
|
||||
road,
|
||||
intersection[(intersection.size() + index - 1) % intersection.size()]);
|
||||
// at the target intersection, we merge to the right, so we need to shift the
|
||||
// current
|
||||
// angle to the left
|
||||
road.bearing = adjustAngle(road.bearing, corrected_offset);
|
||||
}
|
||||
}
|
||||
else if (CanMerge(node_at_next_intersection,
|
||||
next_intersection_along_road,
|
||||
@ -395,13 +410,18 @@ IntersectionNormalizer::AdjustBearingsForMergeAtDestination(const NodeID node_at
|
||||
get_offset(next_intersection_along_road[0],
|
||||
next_intersection_along_road[next_intersection_along_road.size() - 1]);
|
||||
|
||||
const auto corrected_offset =
|
||||
get_corrected_offset(offset, road, intersection[(index + 1) % intersection.size()]);
|
||||
// at the target intersection, we merge to the left, so we need to shift the current
|
||||
// angle to the right
|
||||
road.bearing = adjustAngle(road.bearing, -corrected_offset);
|
||||
if (improves_straightmost(0, offset) &&
|
||||
improves_straightmost(next_intersection_along_road.size() - 1, -offset))
|
||||
{
|
||||
const auto corrected_offset = get_corrected_offset(
|
||||
offset, road, intersection[(index + 1) % intersection.size()]);
|
||||
// at the target intersection, we merge to the left, so we need to shift the current
|
||||
// angle to the right
|
||||
road.bearing = adjustAngle(road.bearing, -corrected_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return intersection;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user