More review fixes.

This commit is contained in:
Lev Dragunov 2016-03-04 17:03:26 +03:00
parent e58411033e
commit e5e944dffe
2 changed files with 33 additions and 18 deletions

View file

@ -56,8 +56,10 @@ IRouter::ResultCode CrossMwmGraph::SetStartNode(CrossNode const & startNode)
{
vector<BorderCross> const & nextCrosses = ConstructBorderCross(outgoingNodes[i], startMapping);
for (auto const & nextCross : nextCrosses)
{
if (nextCross.toNode.IsValid())
dummyEdges.emplace_back(nextCross, weights[i]);
}
}
}
@ -137,10 +139,9 @@ vector<BorderCross> const & CrossMwmGraph::ConstructBorderCross(OutgoingCrossNod
return it->second;
// Cache miss case.
vector<BorderCross> crosses;
auto & crosses = m_cachedNextNodes[key];
ConstructBorderCrossImpl(startNode, currentMapping, crosses);
auto const inserted = m_cachedNextNodes.insert(make_pair(key, crosses));
return inserted.first->second;
return crosses;
}
bool CrossMwmGraph::ConstructBorderCrossImpl(OutgoingCrossNode const & startNode,
@ -157,7 +158,7 @@ bool CrossMwmGraph::ConstructBorderCrossImpl(OutgoingCrossNode const & startNode
nextMapping->m_crossContext.ForEachIngoingNodeNearPoint(startNode.m_point, [&](IngoingCrossNode const & node)
{
crosses.emplace_back(CrossNode(startNode.m_nodeId, currentMapping->GetMwmId(), node.m_point),
CrossNode(node.m_nodeId, nextMapping->GetMwmId(), node.m_point));
CrossNode(node.m_nodeId, nextMapping->GetMwmId(), node.m_point));
});
return !crosses.empty();
}
@ -185,14 +186,15 @@ void CrossMwmGraph::GetOutgoingEdgesList(BorderCross const & v,
// Find income node.
IngoingCrossNode ingoingNode;
bool found = false;
CHECK(currentContext.ForEachIngoingNodeNearPoint(v.toNode.point, [&ingoingNode, &v, &found](IngoingCrossNode const & node)
{
if (node.m_nodeId == v.toNode.node)
{
found = true;
ingoingNode = node;
}
}), ());
auto findingFn = [&ingoingNode, &v, &found](IngoingCrossNode const & node)
{
if (node.m_nodeId == v.toNode.node)
{
found = true;
ingoingNode = node;
}
};
CHECK(currentContext.ForEachIngoingNodeNearPoint(v.toNode.point, findingFn), ());
CHECK(found, ());
@ -204,8 +206,10 @@ void CrossMwmGraph::GetOutgoingEdgesList(BorderCross const & v,
{
vector<BorderCross> const & targets = ConstructBorderCross(node, currentMapping);
for (auto const & target : targets)
{
if (target.toNode.IsValid())
adj.emplace_back(target, outWeight);
}
}
});
}

View file

@ -121,12 +121,14 @@ UNIT_TEST(TestFindingByPoint)
routing::CrossRoutingContextWriter context;
routing::CrossRoutingContextReader newContext;
ms::LatLon p1(1., 1.), p2(5., 5.), p3(10.,1.);
ms::LatLon p1(1., 1.), p2(5., 5.), p3(10., 1.), p4(20., 1.);
context.AddIngoingNode(1, ms::LatLon::Zero());
context.AddIngoingNode(2, p1);
context.AddIngoingNode(3, p2);
context.AddOutgoingNode(4, "foo", ms::LatLon::Zero());
context.AddIngoingNode(5, p3);
context.AddIngoingNode(6, p3);
context.ReserveAdjacencyMatrix();
vector<char> buffer;
@ -136,12 +138,21 @@ UNIT_TEST(TestFindingByPoint)
MemReader reader(buffer.data(), buffer.size());
newContext.Load(reader);
IngoingCrossNode node;
auto fn = [&node](IngoingCrossNode const & nd) {node = nd;};
vector<IngoingCrossNode> node;
auto fn = [&node](IngoingCrossNode const & nd) {node.push_back(nd);};
TEST(newContext.ForEachIngoingNodeNearPoint(p1, fn), ());
TEST_EQUAL(node.m_nodeId, 2, ());
TEST_EQUAL(node.size(), 1, ());
TEST_EQUAL(node[0].m_nodeId, 2, ());
node.clear();
TEST(newContext.ForEachIngoingNodeNearPoint(p2, fn), ());
TEST_EQUAL(node.m_nodeId, 3, ());
TEST(!newContext.ForEachIngoingNodeNearPoint(p3, fn), ());
TEST_EQUAL(node.size(), 1, ());
TEST_EQUAL(node[0].m_nodeId, 3, ());
node.clear();
TEST(!newContext.ForEachIngoingNodeNearPoint(p4, fn), ());
node.clear();
TEST(newContext.ForEachIngoingNodeNearPoint(p3, fn), ());
TEST_EQUAL(node.size(), 2, ());
TEST_EQUAL(node[0].m_nodeId, 5, ());
TEST_EQUAL(node[1].m_nodeId, 6, ());
}
} // namespace