[routing] Fixed bug in reconstruction route points.

This commit is contained in:
vng 2014-07-13 20:35:27 +02:00 committed by Alex Zolotarev
parent 4100abc69e
commit 05e5b8305c
3 changed files with 48 additions and 30 deletions

View file

@ -217,13 +217,12 @@ void FeatureRoadGraph::ReconstructPath(RoadPosVectorT const & positions, Route &
vector<m2::PointD> poly;
// Initialize starting point.
RoadPos pos1 = positions[0];
LoadFeature(pos1.GetFeatureId(), ft1);
LoadFeature(positions.back().GetFeatureId(), ft1);
size_t i = 0;
while (i < count-1)
for (size_t i = count-1; i > 0; --i)
{
RoadPos const & pos2 = positions[i+1];
RoadPos const & pos1 = positions[i];
RoadPos const & pos2 = positions[i-1];
FeatureType ft2;
@ -233,16 +232,15 @@ void FeatureRoadGraph::ReconstructPath(RoadPosVectorT const & positions, Route &
if (diffIDs)
{
LoadFeature(pos2.GetFeatureId(), ft2);
lastPt = ft2.GetPoint(pos2.GetPointId() + (pos2.IsForward() ? 0 : 1));
lastPt = ft2.GetPoint(pos2.GetPointId() + (pos2.IsForward() ? 1 : 0));
}
else
lastPt = ft1.GetPoint(pos2.GetPointId() + (pos1.IsForward() ? 0 : 1));
lastPt = ft1.GetPoint(pos2.GetPointId() + (pos1.IsForward() ? 1 : 0));
// Accumulate points from start point id to pt.
int const inc = pos1.IsForward() ? 1 : -1;
int ptID = pos1.GetPointId() + (pos1.IsForward() ? 1 : 0);
int const inc = pos1.IsForward() ? -1 : 1;
int ptID = pos1.GetPointId() + (pos1.IsForward() ? 0 : 1);
m2::PointD pt;
bool notEnd, notEqualPoints;
do
{
pt = ft1.GetPoint(ptID);
@ -252,30 +250,14 @@ void FeatureRoadGraph::ReconstructPath(RoadPosVectorT const & positions, Route &
ptID += inc;
notEqualPoints = !m2::AlmostEqual(pt, lastPt);
notEnd = (ptID >= 0 && ptID < ft1.GetPointsCount());
} while (notEnd && notEqualPoints);
// If we reached the end of feature, start with the begining
// (end - for backward direction) of the next feauture, until reach pos2.
if (!notEnd && notEqualPoints)
{
pos1 = RoadPos(pos2.GetFeatureId(), pos2.IsForward(),
pos2.IsForward() ? 0 : ft2.GetPointsCount() - 2);
}
else
{
pos1 = pos2;
++i;
}
} while (!m2::AlmostEqual(pt, lastPt));
// Assign current processing feature.
if (diffIDs)
ft1.SwapGeometry(ft2);
}
route = Route("", poly, "");
route.SetGeometry(poly.rbegin(), poly.rend());
}
bool FeatureRoadGraph::IsStreet(feature::TypesHolder const & types) const

View file

@ -2,6 +2,8 @@
#include "features_road_graph_test.hpp"
#include "../route.hpp"
#include "../../indexer/classificator_loader.hpp"
#include "../../indexer/feature.hpp"
#include "../../indexer/ftypes_matcher.hpp"
@ -110,12 +112,23 @@ void FeatureRoadGraphTester::GetPossibleTurns(RoadPos const & pos, IRoadGraph::T
FeatureID2Name(vec);
}
template <size_t N>
void FeatureRoadGraphTester::ReconstructPath(routing::RoadPos (&arr)[N], vector<m2::PointD> & vec)
{
vector<RoadPos> positions(arr, arr + N);
Name2FeatureID(positions);
Route route("dummy");
m_graph->ReconstructPath(positions, route);
vec.assign(route.GetPoly().Begin(), route.GetPoly().End());
}
}
using namespace routing_test;
UNIT_TEST(FRG_Test_MWM1)
UNIT_TEST(FRG_TurnsTest_MWM1)
{
FeatureRoadGraphTester tester("route_test1.mwm");
@ -154,7 +167,7 @@ UNIT_TEST(FRG_Test_MWM1)
}
}
UNIT_TEST(FRG_Test_MWM2)
UNIT_TEST(FRG_TurnsTest_MWM2)
{
FeatureRoadGraphTester tester("route_test2.mwm");
@ -227,3 +240,23 @@ UNIT_TEST(FRG_Test_MWM2)
TEST(TestResult(vec, RoadPos(8, true, 5), -1), ());
}
}
UNIT_TEST(FRG_ReconstructTest_MWM2)
{
// Uncomment to see debug log.
//my::g_LogLevel = LDEBUG;
FeatureRoadGraphTester tester("route_test2.mwm");
{
RoadPos arr[] = {
RoadPos(8, true, 4),
RoadPos(2, true, 0),
RoadPos(3, true, 2)
};
vector<m2::PointD> vec;
tester.ReconstructPath(arr, vec);
TEST_EQUAL(vec.size(), 3, ());
}
}

View file

@ -40,6 +40,9 @@ public:
void Name2FeatureID(vector<routing::RoadPos> & vec);
void GetPossibleTurns(routing::RoadPos const & pos, routing::IRoadGraph::TurnsVectorT & vec);
template <size_t N>
void ReconstructPath(routing::RoadPos (&arr)[N], vector<m2::PointD> & vec);
};
}