forked from organicmaps/organicmaps
PR fixes.
This commit is contained in:
parent
135a8b2b15
commit
0b6573d468
5 changed files with 130 additions and 115 deletions
|
@ -399,11 +399,15 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation(
|
|||
bool isStartNode = (segmentIndex == 0);
|
||||
bool isEndNode = (segmentIndex == numSegments - 1);
|
||||
if (isStartNode || isEndNode)
|
||||
{
|
||||
loadedSegments.emplace_back(*mapping, *m_pIndex, pathSegments[segmentIndex],
|
||||
routingResult.sourceEdge, routingResult.targetEdge, isStartNode,
|
||||
isEndNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
loadedSegments.emplace_back(*mapping, *m_pIndex, pathSegments[segmentIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
// Annotate turns.
|
||||
|
|
|
@ -20,70 +20,70 @@ UNIT_TEST(GetDistanceTextIdMetersTest)
|
|||
{
|
||||
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
|
||||
// TurnDirection turnDir, ::Settings::Units lengthUnits)
|
||||
Notification const notifiation1(500, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation1), "in_500_meters", ());
|
||||
Notification const notifiation2(500, 0, true, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation2), "then", ());
|
||||
Notification const notifiation3(200, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation3), "in_200_meters", ());
|
||||
Notification const notifiation4(2000, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation4), "in_2_kilometers", ());
|
||||
Notification const notification1(500, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notification1), "in_500_meters", ());
|
||||
Notification const notification2(500, 0, true, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notification2), "then", ());
|
||||
Notification const notification3(200, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notification3), "in_200_meters", ());
|
||||
Notification const notification4(2000, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDistanceTextId(notification4), "in_2_kilometers", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GetDistanceTextIdFeetTest)
|
||||
{
|
||||
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
|
||||
// TurnDirection turnDir, ::Settings::Units lengthUnits)
|
||||
Notification const notifiation1(500, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation1), "in_500_feet", ());
|
||||
Notification const notifiation2(500, 0, true, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation2), "then", ());
|
||||
Notification const notifiation3(800, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation3), "in_800_feet", ());
|
||||
Notification const notifiation4(5000, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notifiation4), "in_5000_feet", ());
|
||||
Notification const notification1(500, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notification1), "in_500_feet", ());
|
||||
Notification const notification2(500, 0, true, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notification2), "then", ());
|
||||
Notification const notification3(800, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notification3), "in_800_feet", ());
|
||||
Notification const notification4(5000, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDistanceTextId(notification4), "in_5000_feet", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GetRoundaboutTextIdTest)
|
||||
{
|
||||
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
|
||||
// TurnDirection turnDir, ::Settings::Units lengthUnits)
|
||||
Notification const notifiation1(500, 0, false, TurnDirection::LeaveRoundAbout, ::Settings::Foot);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notifiation1), "leave_the_roundabout", ());
|
||||
Notification const notifiation2(0, 3, true, TurnDirection::LeaveRoundAbout, ::Settings::Foot);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notifiation2), "take_the_3_exit", ());
|
||||
Notification const notifiation3(0, 7, true, TurnDirection::LeaveRoundAbout, ::Settings::Metric);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notifiation3), "take_the_7_exit", ());
|
||||
Notification const notifiation4(0, 15, true, TurnDirection::LeaveRoundAbout, ::Settings::Metric);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notifiation4), "leave_the_roundabout", ());
|
||||
Notification const notification1(500, 0, false, TurnDirection::LeaveRoundAbout, ::Settings::Foot);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notification1), "leave_the_roundabout", ());
|
||||
Notification const notification2(0, 3, true, TurnDirection::LeaveRoundAbout, ::Settings::Foot);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notification2), "take_the_3_exit", ());
|
||||
Notification const notification3(0, 7, true, TurnDirection::LeaveRoundAbout, ::Settings::Metric);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notification3), "take_the_7_exit", ());
|
||||
Notification const notification4(0, 15, true, TurnDirection::LeaveRoundAbout, ::Settings::Metric);
|
||||
TEST_EQUAL(GetRoundaboutTextId(notification4), "leave_the_roundabout", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GetYouArriveTextIdTest)
|
||||
{
|
||||
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
|
||||
// TurnDirection turnDir, ::Settings::Units lengthUnits)
|
||||
Notification const notifiation1(500, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Foot);
|
||||
TEST_EQUAL(GetYouArriveTextId(notifiation1), "destination", ());
|
||||
Notification const notifiation2(0, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetYouArriveTextId(notifiation2), "you_have_reached_the_destination", ());
|
||||
Notification const notifiation3(0, 0, true, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetYouArriveTextId(notifiation3), "destination", ());
|
||||
Notification const notification1(500, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Foot);
|
||||
TEST_EQUAL(GetYouArriveTextId(notification1), "destination", ());
|
||||
Notification const notification2(0, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetYouArriveTextId(notification2), "you_have_reached_the_destination", ());
|
||||
Notification const notification3(0, 0, true, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetYouArriveTextId(notification3), "destination", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GetDirectionTextIdTest)
|
||||
{
|
||||
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
|
||||
// TurnDirection turnDir, ::Settings::Units lengthUnits)
|
||||
Notification const notifiation1(500, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDirectionTextId(notifiation1), "make_a_right_turn", ());
|
||||
Notification const notifiation2(1000, 0, false, TurnDirection::GoStraight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notifiation2), "go_straight", ());
|
||||
Notification const notifiation3(700, 0, false, TurnDirection::UTurnLeft, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notifiation3), "make_a_u_turn", ());
|
||||
Notification const notifiation4(200, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notifiation4), "destination", ());
|
||||
Notification const notifiation5(0, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notifiation5), "you_have_reached_the_destination", ());
|
||||
Notification const notification1(500, 0, false, TurnDirection::TurnRight, ::Settings::Foot);
|
||||
TEST_EQUAL(GetDirectionTextId(notification1), "make_a_right_turn", ());
|
||||
Notification const notification2(1000, 0, false, TurnDirection::GoStraight, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notification2), "go_straight", ());
|
||||
Notification const notification3(700, 0, false, TurnDirection::UTurnLeft, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notification3), "make_a_u_turn", ());
|
||||
Notification const notification4(200, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notification4), "destination", ());
|
||||
Notification const notification5(0, 0, false, TurnDirection::ReachedYourDestination, ::Settings::Metric);
|
||||
TEST_EQUAL(GetDirectionTextId(notification5), "you_have_reached_the_destination", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GetTtsTextTest)
|
||||
|
@ -113,23 +113,23 @@ UNIT_TEST(GetTtsTextTest)
|
|||
GetTtsText getTtsText;
|
||||
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
|
||||
// TurnDirection turnDir, Settings::Units lengthUnits)
|
||||
Notification const notifiation1(500, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
Notification const notifiation2(300, 0, false, TurnDirection::TurnLeft, ::Settings::Metric);
|
||||
Notification const notifiation3(0, 0, false, TurnDirection::ReachedYourDestination,
|
||||
Notification const notification1(500, 0, false, TurnDirection::TurnRight, ::Settings::Metric);
|
||||
Notification const notification2(300, 0, false, TurnDirection::TurnLeft, ::Settings::Metric);
|
||||
Notification const notification3(0, 0, false, TurnDirection::ReachedYourDestination,
|
||||
::Settings::Metric);
|
||||
Notification const notifiation4(0, 0, true, TurnDirection::TurnLeft, ::Settings::Metric);
|
||||
Notification const notification4(0, 0, true, TurnDirection::TurnLeft, ::Settings::Metric);
|
||||
|
||||
getTtsText.ForTestingSetLocaleWithJson(engShortJson, "en");
|
||||
TEST_EQUAL(getTtsText(notifiation1), "In 500 meters. Make a right turn.", ());
|
||||
TEST_EQUAL(getTtsText(notifiation2), "In 300 meters. Make a left turn.", ());
|
||||
TEST_EQUAL(getTtsText(notifiation3), "You have reached the destination.", ());
|
||||
TEST_EQUAL(getTtsText(notifiation4), "Then. Make a left turn.", ());
|
||||
TEST_EQUAL(getTtsText(notification1), "In 500 meters. Make a right turn.", ());
|
||||
TEST_EQUAL(getTtsText(notification2), "In 300 meters. Make a left turn.", ());
|
||||
TEST_EQUAL(getTtsText(notification3), "You have reached the destination.", ());
|
||||
TEST_EQUAL(getTtsText(notification4), "Then. Make a left turn.", ());
|
||||
|
||||
getTtsText.ForTestingSetLocaleWithJson(rusShortJson, "ru");
|
||||
TEST_EQUAL(getTtsText(notifiation1), "Через 500 метров. Поворот направо.", ());
|
||||
TEST_EQUAL(getTtsText(notifiation2), "Через 300 метров. Поворот налево.", ());
|
||||
TEST_EQUAL(getTtsText(notifiation3), "Вы достигли конца маршрута.", ());
|
||||
TEST_EQUAL(getTtsText(notifiation4), "Затем. Поворот налево.", ());
|
||||
TEST_EQUAL(getTtsText(notification1), "Через 500 метров. Поворот направо.", ());
|
||||
TEST_EQUAL(getTtsText(notification2), "Через 300 метров. Поворот налево.", ());
|
||||
TEST_EQUAL(getTtsText(notification3), "Вы достигли конца маршрута.", ());
|
||||
TEST_EQUAL(getTtsText(notification4), "Затем. Поворот налево.", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GetAllSoundedDistMetersTest)
|
||||
|
|
|
@ -322,9 +322,10 @@ TurnDirection FindDirectionByAngle(vector<pair<double, TurnDirection>> const & l
|
|||
*/
|
||||
m2::PointD GetPointForTurn(vector<m2::PointD> const & path, m2::PointD const & junctionPoint,
|
||||
size_t const maxPointsCount, double const minDistMeters,
|
||||
size_t (*GetPointIndex)(const size_t start, const size_t end,
|
||||
const size_t shift))
|
||||
function<size_t(const size_t start, const size_t end, const size_t shift)> GetPointIndex)
|
||||
{
|
||||
ASSERT(!path.empty(), ());
|
||||
|
||||
double curDistanceMeters = 0.;
|
||||
m2::PointD point = junctionPoint;
|
||||
m2::PointD nextPoint;
|
||||
|
@ -332,6 +333,7 @@ m2::PointD GetPointForTurn(vector<m2::PointD> const & path, m2::PointD const & j
|
|||
size_t const numSegPoints = path.size() - 1;
|
||||
ASSERT_GREATER(numSegPoints, 0, ());
|
||||
size_t const usedFtPntNum = min(maxPointsCount, numSegPoints);
|
||||
ASSERT_GREATER_OR_EQUAL(usedFtPntNum, 1, ());
|
||||
|
||||
for (size_t i = 1; i <= usedFtPntNum; ++i)
|
||||
{
|
||||
|
@ -459,13 +461,16 @@ LoadedPathSegment::LoadedPathSegment(RoutingMapping & mapping, Index const & ind
|
|||
false /* isStartNode */, false /*isEndNode*/);
|
||||
}
|
||||
|
||||
void LoadedPathSegment::LoadPathGeometry(buffer_vector<TSeg, 8> const & buffer, size_t startK,
|
||||
size_t endK, Index const & index, RoutingMapping & mapping,
|
||||
void LoadedPathSegment::LoadPathGeometry(buffer_vector<TSeg, 8> const & buffer, size_t startIndex,
|
||||
size_t endIndex, Index const & index, RoutingMapping & mapping,
|
||||
FeatureGraphNode const & startGraphNode,
|
||||
FeatureGraphNode const & endGraphNode, bool isStartNode,
|
||||
bool isEndNode)
|
||||
{
|
||||
for (size_t k = startK; k < endK; ++k)
|
||||
ASSERT_LESS(startIndex, endIndex, ());
|
||||
ASSERT_LESS_OR_EQUAL(endIndex, buffer.size(), ());
|
||||
ASSERT(!buffer.empty(), ());
|
||||
for (size_t k = startIndex; k < endIndex; ++k)
|
||||
{
|
||||
auto const & segment = buffer[k];
|
||||
if (!segment.IsValid())
|
||||
|
@ -482,10 +487,10 @@ void LoadedPathSegment::LoadPathGeometry(buffer_vector<TSeg, 8> const & buffer,
|
|||
// Get points in proper direction.
|
||||
auto startIdx = segment.m_pointStart;
|
||||
auto endIdx = segment.m_pointEnd;
|
||||
if (isStartNode && k == startK && startGraphNode.segment.IsValid())
|
||||
if (isStartNode && k == startIndex && startGraphNode.segment.IsValid())
|
||||
startIdx = (segment.m_pointEnd > segment.m_pointStart) ? startGraphNode.segment.m_pointStart
|
||||
: startGraphNode.segment.m_pointEnd;
|
||||
if (isEndNode && k == endK - 1 && endGraphNode.segment.IsValid())
|
||||
if (isEndNode && k == endIndex - 1 && endGraphNode.segment.IsValid())
|
||||
endIdx = (segment.m_pointEnd > segment.m_pointStart) ? endGraphNode.segment.m_pointEnd
|
||||
: endGraphNode.segment.m_pointStart;
|
||||
if (startIdx < endIdx)
|
||||
|
@ -496,7 +501,7 @@ void LoadedPathSegment::LoadPathGeometry(buffer_vector<TSeg, 8> const & buffer,
|
|||
else
|
||||
{
|
||||
// I use big signed type because endIdx can be 0.
|
||||
for (int64_t idx = startIdx; idx >= endIdx; --idx)
|
||||
for (int64_t idx = startIdx; idx >= static_cast<int64_t>(endIdx); --idx)
|
||||
m_path.push_back(ft.GetPoint(idx));
|
||||
}
|
||||
|
||||
|
@ -538,12 +543,13 @@ LoadedPathSegment::LoadedPathSegment(RoutingMapping & mapping, Index const & ind
|
|||
, m_weight(0)
|
||||
, m_nodeId(osrmPathSegment.node)
|
||||
{
|
||||
ASSERT(isStartNode || isEndNode, ("This function process only side cases."));
|
||||
if (!startGraphNode.segment.IsValid() || !endGraphNode.segment.IsValid())
|
||||
return;
|
||||
buffer_vector<TSeg, 8> buffer;
|
||||
mapping.m_segMapping.ForEachFtSeg(osrmPathSegment.node, MakeBackInsertFunctor(buffer));
|
||||
|
||||
auto FindIntersectingSeg = [&buffer](TSeg const & seg) -> size_t
|
||||
auto findIntersectingSeg = [&buffer](TSeg const & seg) -> size_t
|
||||
{
|
||||
ASSERT(seg.IsValid(), ());
|
||||
auto const it = find_if(buffer.begin(), buffer.end(), [&seg](OsrmMappingTypes::FtSeg const & s)
|
||||
|
@ -556,19 +562,6 @@ LoadedPathSegment::LoadedPathSegment(RoutingMapping & mapping, Index const & ind
|
|||
};
|
||||
|
||||
// Calculate estimated time for a start and a end node cases.
|
||||
if (isStartNode)
|
||||
{
|
||||
m_weight = (osrmPathSegment.node == startGraphNode.node.forward_node_id)
|
||||
? startGraphNode.node.GetForwardWeightPlusOffset()
|
||||
: startGraphNode.node.GetReverseWeightPlusOffset();
|
||||
}
|
||||
if (isEndNode)
|
||||
{
|
||||
m_weight = (osrmPathSegment.node == endGraphNode.node.forward_node_id)
|
||||
? endGraphNode.node.GetForwardWeightPlusOffset()
|
||||
: endGraphNode.node.GetReverseWeightPlusOffset();
|
||||
}
|
||||
|
||||
if (isStartNode && isEndNode)
|
||||
{
|
||||
double const forwardWeight = (osrmPathSegment.node == startGraphNode.node.forward_node_id)
|
||||
|
@ -584,10 +577,23 @@ LoadedPathSegment::LoadedPathSegment(RoutingMapping & mapping, Index const & ind
|
|||
// more info.
|
||||
m_weight = wholeWeight + forwardWeight + backwardWeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
PhantomNode const * node = nullptr;
|
||||
if (isStartNode)
|
||||
node = &startGraphNode.node;
|
||||
else if (isEndNode)
|
||||
node = &endGraphNode.node;
|
||||
if (node)
|
||||
{
|
||||
m_weight = (osrmPathSegment.node == node->forward_weight)
|
||||
? node->GetForwardWeightPlusOffset() : node->GetReverseWeightPlusOffset();
|
||||
}
|
||||
}
|
||||
|
||||
size_t startK = isStartNode ? FindIntersectingSeg(startGraphNode.segment) : 0;
|
||||
size_t endK = isEndNode ? FindIntersectingSeg(endGraphNode.segment) + 1 : buffer.size();
|
||||
LoadPathGeometry(buffer, startK, endK, index, mapping, startGraphNode, endGraphNode, isStartNode,
|
||||
size_t startIndex = isStartNode ? findIntersectingSeg(startGraphNode.segment) : 0;
|
||||
size_t endIndex = isEndNode ? findIntersectingSeg(endGraphNode.segment) + 1 : buffer.size();
|
||||
LoadPathGeometry(buffer, startIndex, endIndex, index, mapping, startGraphNode, endGraphNode, isStartNode,
|
||||
isEndNode);
|
||||
}
|
||||
|
||||
|
@ -891,49 +897,51 @@ void GetTurnDirection(Index const & index, RoutingMapping & mapping, TurnInfo &
|
|||
size_t CheckUTurnOnRoute(vector<LoadedPathSegment> const & segments, size_t currentSegment, TurnItem & turn)
|
||||
{
|
||||
size_t constexpr kUTurnLookAhead = 3;
|
||||
double const kUTurnHeadingSensitivity = math::pi / 10.0;
|
||||
double constexpr kUTurnHeadingSensitivity = math::pi / 10.0;
|
||||
|
||||
// In this function we process the turn between the previous and the current
|
||||
// segments. So we need a shift to get the previous segment.
|
||||
ASSERT_GREATER(segments.size(), 1, ());
|
||||
ASSERT_GREATER(currentSegment, 0, ());
|
||||
ASSERT_GREATER(segments.size(), currentSegment, ());
|
||||
auto const & masterSegment = segments[currentSegment - 1];
|
||||
ASSERT_GREATER(masterSegment.m_path.size(), 1, ());
|
||||
// Roundabout is not the UTurn.
|
||||
if (masterSegment.m_onRoundabout)
|
||||
return 0;
|
||||
for (size_t i = 0; i< min(kUTurnLookAhead, segments.size()); ++i)
|
||||
for (size_t i = 0; i < min(kUTurnLookAhead, segments.size() - currentSegment); ++i)
|
||||
{
|
||||
auto const & checkedSegment = segments[currentSegment + i];
|
||||
if (checkedSegment.m_name == masterSegment.m_name &&
|
||||
checkedSegment.m_highwayClass == masterSegment.m_highwayClass &&
|
||||
checkedSegment.m_isLink == masterSegment.m_isLink && !checkedSegment.m_onRoundabout)
|
||||
{
|
||||
m2::PointD p1 = masterSegment.m_path.back() - masterSegment.m_path[masterSegment.m_path.size() - 2];
|
||||
m2::PointD p2 = checkedSegment.m_path[1] -checkedSegment.m_path.front();
|
||||
auto const & path = masterSegment.m_path;
|
||||
m2::PointD p1 = path[path.size() - 1] - path[path.size() - 2];
|
||||
m2::PointD p2 = checkedSegment.m_path[1] - checkedSegment.m_path[0];
|
||||
auto angle = ang::TwoVectorsAngle(m2::PointD::Zero(), p1, p2);
|
||||
if (my::AlmostEqualAbs(angle, math::pi, kUTurnHeadingSensitivity))
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
turn.m_turn = TurnDirection::UTurnLeft;
|
||||
return 0;
|
||||
}
|
||||
// Determine turn direction.
|
||||
m2::PointD const junctionPoint = masterSegment.m_path.back();
|
||||
m2::PointD const ingoingPoint = GetPointForTurn(masterSegment.m_path, junctionPoint,
|
||||
kMaxPointsCount, kMinDistMeters,
|
||||
GetIngoingPointIndex);
|
||||
m2::PointD const outgoingPoint = GetPointForTurn(segments[currentSegment].m_path, junctionPoint,
|
||||
kMaxPointsCount, kMinDistMeters,
|
||||
GetOutgoingPointIndex);
|
||||
if (PiMinusTwoVectorsAngle(junctionPoint, ingoingPoint, outgoingPoint) < 0)
|
||||
turn.m_turn = TurnDirection::UTurnLeft;
|
||||
else
|
||||
turn.m_turn = TurnDirection::UTurnRight;
|
||||
return ++i;
|
||||
}
|
||||
else
|
||||
|
||||
if (!my::AlmostEqualAbs(angle, math::pi, kUTurnHeadingSensitivity))
|
||||
return 0;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
turn.m_turn = TurnDirection::UTurnLeft;
|
||||
return 0;
|
||||
}
|
||||
// Determine turn direction.
|
||||
m2::PointD const junctionPoint = masterSegment.m_path.back();
|
||||
m2::PointD const ingoingPoint = GetPointForTurn(masterSegment.m_path, junctionPoint,
|
||||
kMaxPointsCount, kMinDistMeters,
|
||||
GetIngoingPointIndex);
|
||||
m2::PointD const outgoingPoint = GetPointForTurn(segments[currentSegment].m_path, junctionPoint,
|
||||
kMaxPointsCount, kMinDistMeters,
|
||||
GetOutgoingPointIndex);
|
||||
if (PiMinusTwoVectorsAngle(junctionPoint, ingoingPoint, outgoingPoint) < 0)
|
||||
turn.m_turn = TurnDirection::UTurnLeft;
|
||||
else
|
||||
turn.m_turn = TurnDirection::UTurnRight;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace turns
|
|||
using TGetIndexFunction = function<size_t(pair<size_t, size_t>)>;
|
||||
|
||||
/*!
|
||||
* \brief The LoadedPathSegment struct is a representation for a single osrm node path.
|
||||
* It unpacks all necessary information about path and stores it inside this structure.
|
||||
* \brief The LoadedPathSegment struct is a representation of a single osrm node path.
|
||||
* It unpacks and stores information about path and road type flags.
|
||||
* Postprocessing must read information from the structure and does not initiate disk readings.
|
||||
*/
|
||||
struct LoadedPathSegment
|
||||
|
@ -47,22 +47,24 @@ struct LoadedPathSegment
|
|||
// General constructor.
|
||||
LoadedPathSegment(RoutingMapping & mapping, Index const & index,
|
||||
RawPathData const & osrmPathSegment);
|
||||
// Spesial constructor for side nodes. Splits OSRM node by information from the FeatureGraphNode.
|
||||
// Special constructor for side nodes. Splits OSRM node by information from the FeatureGraphNode.
|
||||
LoadedPathSegment(RoutingMapping & mapping, Index const & index,
|
||||
RawPathData const & osrmPathSegment, FeatureGraphNode const & startGraphNode,
|
||||
FeatureGraphNode const & endGraphNode, bool isStartNode, bool isEndNode);
|
||||
LoadedPathSegment() = delete;
|
||||
|
||||
private:
|
||||
void LoadPathGeometry(buffer_vector<OsrmMappingTypes::FtSeg, 8> const & buffer, size_t startK,
|
||||
size_t endK, Index const & index, RoutingMapping & mapping,
|
||||
// Load information about road, that described as the sequence of FtSegs and start/end indexes in
|
||||
// in it. For the side case, it has information about start/end graph nodes.
|
||||
void LoadPathGeometry(buffer_vector<OsrmMappingTypes::FtSeg, 8> const & buffer, size_t startIndex,
|
||||
size_t endIndex, Index const & index, RoutingMapping & mapping,
|
||||
FeatureGraphNode const & startGraphNode,
|
||||
FeatureGraphNode const & endGraphNode, bool isStartNode, bool isEndNode);
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief The TurnInfo struct is a representation of a junction.
|
||||
* It has ingoing and outgoing edges and method to check if this edges are valid.
|
||||
* It has ingoing and outgoing edges and method to check if these edges are valid.
|
||||
*/
|
||||
struct TurnInfo
|
||||
{
|
||||
|
@ -144,8 +146,9 @@ void GetTurnDirection(Index const & index, RoutingMapping & mapping, turns::Turn
|
|||
TurnItem & turn);
|
||||
|
||||
/*!
|
||||
* \brief Finds UTurn started from current segment and returns how many segments it lasts.
|
||||
* Returns 0 otherwise.
|
||||
* \brief Finds an UTurn that starts from current segment and returns how many segments it lasts.
|
||||
* Returns 0 if there is no UTurn.
|
||||
* Warning! currentSegment must be greater than 0.
|
||||
*/
|
||||
size_t CheckUTurnOnRoute(vector<LoadedPathSegment> const & segments, size_t currentSegment, TurnItem & turn);
|
||||
} // namespace routing
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
|
||||
namespace math
|
||||
{
|
||||
static const double pi = 3.14159265358979323846;
|
||||
static const double pi2 = pi / 2.;
|
||||
static const double pi4 = pi / 4.;
|
||||
static const double twicePi = 2. * pi;
|
||||
double constexpr pi = 3.14159265358979323846;
|
||||
double constexpr pi2 = pi / 2.;
|
||||
double constexpr pi4 = pi / 4.;
|
||||
double constexpr twicePi = 2. * pi;
|
||||
|
||||
template <class T> T sqr(T t) { return (t*t); }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue