New function for finding outgoing cross nodes.

This commit is contained in:
Lev Dragunov 2016-03-04 14:05:10 +03:00
parent 75d835e6d7
commit 1626bbda3c
4 changed files with 18 additions and 19 deletions

View file

@ -155,13 +155,10 @@ bool CrossMwmGraph::ConstructBorderCrossImpl(OutgoingCrossNode const & startNode
return false;
crosses.clear();
nextMapping->LoadCrossContext();
nextMapping->m_crossContext.ForEachIngoingNode([&](IngoingCrossNode const & node)
nextMapping->m_crossContext.ForEachIngoingNodeNearPoint(startNode.m_point, [&](IngoingCrossNode const & node)
{
if (node.m_point == startNode.m_point)
{
crosses.emplace_back(CrossNode(startNode.m_nodeId, currentMapping->GetMwmId(), node.m_point),
CrossNode(node.m_nodeId, nextMapping->GetMwmId(), node.m_point));
}
});
return !crosses.empty();
}
@ -188,16 +185,17 @@ void CrossMwmGraph::GetOutgoingEdgesList(BorderCross const & v,
// Find income node.
IngoingCrossNode ingoingNode;
CHECK(currentContext.FindIngoingNodeByPoint(v.toNode.point, ingoingNode), ());
if (ingoingNode.m_nodeId != v.toNode.node)
{
LOG(LDEBUG, ("Several nodes stores in one border point.", v.toNode.point));
currentContext.ForEachIngoingNode([&ingoingNode, &v](IngoingCrossNode const & node)
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;
});
}
}
}), ());
CHECK(found, ());
// Find outs. Generate adjacency list.
currentContext.ForEachOutgoingNode([&, this](OutgoingCrossNode const & node)

View file

@ -96,17 +96,16 @@ void CrossRoutingContextReader::Load(Reader const & r)
}
}
bool CrossRoutingContextReader::FindIngoingNodeByPoint(ms::LatLon const & point,
IngoingCrossNode & node) const
bool CrossRoutingContextReader::ForEachIngoingNodeNearPoint(ms::LatLon const & point, function<void(IngoingCrossNode const & node)> && fn) const
{
bool found = false;
m_ingoingIndex.ForEachInRect(m2::RectD(point.lat - kMwmCrossingNodeEqualityRadiusDegrees,
point.lon - kMwmCrossingNodeEqualityRadiusDegrees,
point.lat + kMwmCrossingNodeEqualityRadiusDegrees,
point.lon + kMwmCrossingNodeEqualityRadiusDegrees),
[&found, &node](IngoingCrossNode const & nd)
[&found, &fn](IngoingCrossNode const & node)
{
node = nd;
fn(node);
found = true;
});
return found;

View file

@ -7,6 +7,7 @@
#include "geometry/rect2d.hpp"
#include "geometry/tree4d.hpp"
#include "std/function.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
@ -87,7 +88,7 @@ public:
const string & GetOutgoingMwmName(OutgoingCrossNode const & mwmIndex) const;
bool FindIngoingNodeByPoint(ms::LatLon const & point, IngoingCrossNode & node) const;
bool ForEachIngoingNodeNearPoint(ms::LatLon const & point, function<void(IngoingCrossNode const & node)> && fn) const;
TWrittenEdgeWeight GetAdjacencyCost(IngoingCrossNode const & ingoing,
OutgoingCrossNode const & outgoing) const;

View file

@ -137,10 +137,11 @@ UNIT_TEST(TestFindingByPoint)
MemReader reader(buffer.data(), buffer.size());
newContext.Load(reader);
IngoingCrossNode node;
TEST(newContext.FindIngoingNodeByPoint(p1, node), ());
auto fn = [&node](IngoingCrossNode const & nd) {node = nd;};
TEST(newContext.ForEachIngoingNodeNearPoint(p1, fn), ());
TEST_EQUAL(node.m_nodeId, 2, ());
TEST(newContext.FindIngoingNodeByPoint(p2, node), ());
TEST(newContext.ForEachIngoingNodeNearPoint(p2, fn), ());
TEST_EQUAL(node.m_nodeId, 3, ());
TEST(!newContext.FindIngoingNodeByPoint(p3, node), ());
TEST(!newContext.ForEachIngoingNodeNearPoint(p3, fn), ());
}
} // namespace