Review fixes.

This commit is contained in:
vng 2015-12-22 15:32:26 +03:00 committed by Sergey Yershov
parent 2fe8fee598
commit b15b113b2c
4 changed files with 36 additions and 28 deletions

View file

@ -132,7 +132,7 @@ m2::PointD GetCenter(FeatureType const & f)
double GetMinDistance(FeatureType const & ft, m2::PointD const & pt, int scale)
{
double res = numeric_limits<double>::max();
auto distanceFn = [&] (m2::PointD const & p)
auto updateDistanceFn = [&] (m2::PointD const & p)
{
double const d = MercatorBounds::DistanceOnEarth(p, pt);
if (d < res)
@ -144,20 +144,20 @@ double GetMinDistance(FeatureType const & ft, m2::PointD const & pt, int scale)
switch (type)
{
case GEOM_POINT:
distanceFn(ft.GetCenter());
updateDistanceFn(ft.GetCenter());
break;
case GEOM_LINE:
ft.ForEachPoint(distanceFn, scale);
ft.ForEachPoint(updateDistanceFn, scale);
break;
default:
ASSERT_EQUAL(type, GEOM_AREA, ());
ft.ForEachTriangle([&] (m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3)
{
distanceFn(p1);
distanceFn(p2);
distanceFn(p3);
updateDistanceFn(p1);
updateDistanceFn(p2);
updateDistanceFn(p3);
}, scale);
break;
}

View file

@ -6,33 +6,35 @@
#include "indexer/index.hpp"
using namespace search;
using namespace platform;
namespace
{
void TestAddress(search::ReverseGeocoder & coder,
ms::LatLon const & ll, string const & stName, string const & hName)
void TestAddress(ReverseGeocoder & coder, ms::LatLon const & ll,
string const & stName, string const & hNumber)
{
search::ReverseGeocoder::Street street;
search::ReverseGeocoder::Building building;
coder.GetNearbyAddress(MercatorBounds::FromLatLon(ll), building, street);
ReverseGeocoder::Address addr;
coder.GetNearbyAddress(MercatorBounds::FromLatLon(ll), addr);
string key;
search::GetStreetNameAsKey(street.m_name, key);
GetStreetNameAsKey(addr.m_street.m_name, key);
TEST_EQUAL(stName, key, ());
TEST_EQUAL(hName, building.m_name, ());
TEST_EQUAL(hNumber, addr.m_building.m_name, ());
}
} // namespace
UNIT_TEST(ReverseGeocoder_Smoke)
{
platform::LocalCountryFile file = platform::LocalCountryFile::MakeForTesting("minsk-pass");
LocalCountryFile file = LocalCountryFile::MakeForTesting("minsk-pass");
Index index;
TEST_EQUAL(index.RegisterMap(file).second, MwmSet::RegResult::Success, ());
search::ReverseGeocoder coder(index);
ReverseGeocoder coder(index);
TestAddress(coder, {53.89815, 27.54265}, "мясникова", "32");
TestAddress(coder, {53.89953, 27.54189}, "немига", "42");

View file

@ -70,7 +70,7 @@ void ReverseGeocoder::GetNearbyBuildings(m2::PointD const & center, vector<Build
if (!ftypes::IsBuildingChecker::Instance()(ft))
return;
// Skip empty house nubers.
// Skip empty house numbers.
string const number = ft.GetHouseNumber();
if (number.empty())
return;
@ -120,24 +120,25 @@ size_t ReverseGeocoder::GetMatchedStreetIndex(string const & keyName,
return result;
}
void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center,
Building & building, Street & street)
void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center, Address & addr)
{
vector<Building> buildings;
GetNearbyBuildings(center, buildings);
vector<Street> streets;
unique_ptr<search::v2::HouseToStreetTable> table;
MwmSet::MwmId mwmId;
MwmSet::MwmHandle mwmHandle;
for (auto const & b : buildings)
{
if (!table || mwmId != b.m_id.m_mwmId)
if (!table || mwmHandle.GetId() != b.m_id.m_mwmId)
{
auto handle = m_index.GetMwmHandleById(b.m_id.m_mwmId);
auto value = handle.GetValue<MwmValue>();
mwmHandle = m_index.GetMwmHandleById(b.m_id.m_mwmId);
auto value = mwmHandle.GetValue<MwmValue>();
if (value)
table = search::v2::HouseToStreetTable::Load(*value);
else
continue;
}
GetNearbyStreets(b.m_center, streets);
@ -145,8 +146,8 @@ void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center,
uint32_t const ind = table->Get(b.m_id.m_index);
if (ind < streets.size())
{
building = b;
street = streets[ind];
addr.m_building = b;
addr.m_street = streets[ind];
return;
}
}

View file

@ -43,8 +43,8 @@ public:
m2::PointD m_center;
Building() = default;
Building(FeatureID const & id, double dist, string const & hn, m2::PointD const & center)
: Object(id, dist, hn), m_center(center)
Building(FeatureID const & id, double dist, string const & number, m2::PointD const & center)
: Object(id, dist, number), m_center(center)
{
}
};
@ -53,8 +53,13 @@ public:
static size_t GetMatchedStreetIndex(string const & keyName, vector<Street> const & streets);
void GetNearbyAddress(m2::PointD const & center,
Building & building, Street & street);
struct Address
{
Building m_building;
Street m_street;
};
void GetNearbyAddress(m2::PointD const & center, Address & addr);
private:
void GetNearbyStreets(m2::PointD const & center, vector<Street> & streets);