Calculate USA limit rect.

This commit is contained in:
vng 2012-01-30 20:55:59 +03:00 committed by Alex Zolotarev
parent 9176ae5056
commit 187413d181
3 changed files with 42 additions and 9 deletions

View file

@ -108,9 +108,9 @@ namespace storage
if (info.m_name.empty())
info.m_name = id;
if (id.find_first_of('_') != string::npos)
if (id.find('_') != string::npos)
{
size_t const i = info.m_name.find_first_of('_');
size_t const i = info.m_name.find('_');
ASSERT ( i != string::npos, () );
// replace '_' with ", "
@ -118,4 +118,19 @@ namespace storage
info.m_name.insert(i+1, " ");
}
}
m2::RectD CountryInfoGetter::CalcUSALimitRect() const
{
m2::RectD r;
for (size_t i = 0; i < m_countries.size(); ++i)
{
if ((m_countries[i].m_name.find("USA_") != string::npos) &&
(m_countries[i].m_name != "USA_Alaska") &&
(m_countries[i].m_name != "USA_Hawaii"))
{
r.Add(m_countries[i].m_rect);
}
}
return r;
}
}

View file

@ -45,5 +45,7 @@ namespace storage
void GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const;
void GetRegionInfo(string const & id, CountryInfo & info) const;
m2::RectD CalcUSALimitRect() const;
};
}

View file

@ -7,21 +7,31 @@
#include "../../platform/platform.hpp"
#include "../../base/logging.hpp"
using namespace storage;
namespace
{
typedef storage::CountryInfoGetter CountryInfoT;
CountryInfoT * GetCountryInfo()
{
Platform & pl = GetPlatform();
return new CountryInfoT(pl.GetReader(PACKED_POLYGONS_FILE),
pl.GetReader(COUNTRIES_FILE));
}
}
UNIT_TEST(CountryInfo_GetByPoint_Smoke)
{
Platform & pl = GetPlatform();
storage::CountryInfoGetter getter(pl.GetReader(PACKED_POLYGONS_FILE),
pl.GetReader(COUNTRIES_FILE));
scoped_ptr<CountryInfoT> getter(GetCountryInfo());
// Minsk
CountryInfo info;
getter.GetRegionInfo(m2::PointD(MercatorBounds::LonToX(27.5618818),
MercatorBounds::LatToY(53.9022651)),
info);
getter->GetRegionInfo(m2::PointD(MercatorBounds::LonToX(27.5618818),
MercatorBounds::LatToY(53.9022651)),
info);
TEST_EQUAL(info.m_name, "Belarus", ());
TEST_EQUAL(info.m_flag, "by", ());
@ -51,3 +61,9 @@ UNIT_TEST(CountryInfo_ValidName_Smoke)
TEST(IsEmptyName(id2info, "Russia_Far Eastern"), ());
TEST(IsEmptyName(id2info, "UK_Northern Ireland"), ());
}
UNIT_TEST(CountryInfo_USARect)
{
scoped_ptr<CountryInfoT> getter(GetCountryInfo());
LOG(LINFO, (getter->CalcUSALimitRect()));
}