forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
fdaa9d6cf6
commit
31bea55870
6 changed files with 35 additions and 55 deletions
|
@ -14,6 +14,7 @@
|
|||
#include "coding/byte_stream.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
#include "base/string_utils.hpp"
|
||||
|
||||
#include "std/cstring.hpp"
|
||||
#include "std/algorithm.hpp"
|
||||
|
@ -76,6 +77,11 @@ void FeatureBuilder1::SetRank(uint8_t rank)
|
|||
m_params.rank = rank;
|
||||
}
|
||||
|
||||
void FeatureBuilder1::SetTestId(uint64_t id)
|
||||
{
|
||||
m_params.GetMetadata().Set(Metadata::FMD_TEST_ID, strings::to_string(id));
|
||||
}
|
||||
|
||||
void FeatureBuilder1::AddHouseNumber(string const & houseNumber)
|
||||
{
|
||||
m_params.AddHouseNumber(houseNumber);
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
|
||||
void SetRank(uint8_t rank);
|
||||
|
||||
void SetTestId(uint64_t id);
|
||||
|
||||
void AddHouseNumber(string const & houseNumber);
|
||||
|
||||
void AddStreet(string const & streetName);
|
||||
|
|
|
@ -71,6 +71,7 @@ string DebugPrint(feature::Metadata::EType type)
|
|||
case Metadata::FMD_MIN_HEIGHT: return "min_height";
|
||||
case Metadata::FMD_DENOMINATION: return "denomination";
|
||||
case Metadata::FMD_BUILDING_LEVELS: return "building:levels";
|
||||
case Metadata::FMD_TEST_ID: return "test_id";
|
||||
case Metadata::FMD_COUNT: CHECK(false, ("FMD_COUNT can not be used as a type."));
|
||||
};
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ public:
|
|||
FMD_MIN_HEIGHT = 20,
|
||||
FMD_DENOMINATION = 21,
|
||||
FMD_BUILDING_LEVELS = 22,
|
||||
FMD_TEST_ID = 23,
|
||||
FMD_COUNT
|
||||
};
|
||||
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
#include "indexer/classificator.hpp"
|
||||
#include "indexer/feature.hpp"
|
||||
#include "indexer/feature_algo.hpp"
|
||||
#include "indexer/feature_meta.hpp"
|
||||
#include "indexer/ftypes_matcher.hpp"
|
||||
|
||||
#include "coding/multilang_utf8_string.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include "std/atomic.hpp"
|
||||
#include "std/sstream.hpp"
|
||||
|
||||
namespace search
|
||||
|
@ -19,41 +21,38 @@ namespace tests_support
|
|||
{
|
||||
namespace
|
||||
{
|
||||
double const kTestPrecision = 1e-4;
|
||||
uint64_t GenUniqueId()
|
||||
{
|
||||
static atomic<uint64_t> id;
|
||||
return id.fetch_add(1);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// TestFeature -------------------------------------------------------------------------------------
|
||||
TestFeature::TestFeature(string const & name, string const & lang)
|
||||
: m_center(0, 0), m_hasCenter(false), m_name(name), m_lang(lang)
|
||||
: m_id(GenUniqueId()), m_center(0, 0), m_hasCenter(false), m_name(name), m_lang(lang)
|
||||
{
|
||||
}
|
||||
|
||||
TestFeature::TestFeature(m2::PointD const & center, string const & name, string const & lang)
|
||||
: m_center(center), m_hasCenter(true), m_name(name), m_lang(lang)
|
||||
: m_id(GenUniqueId()), m_center(center), m_hasCenter(true), m_name(name), m_lang(lang)
|
||||
{
|
||||
}
|
||||
|
||||
void TestFeature::Serialize(FeatureBuilder1 & fb) const
|
||||
{
|
||||
if (m_hasCenter)
|
||||
fb.SetCenter(m_center);
|
||||
CHECK(fb.AddName(m_lang, m_name), ("Can't set feature name:", m_name, "(", m_lang, ")"));
|
||||
}
|
||||
|
||||
bool TestFeature::Matches(FeatureType const & feature) const
|
||||
{
|
||||
uint8_t const langIndex = StringUtf8Multilang::GetLangIndex(m_lang);
|
||||
string name;
|
||||
bool const nameMatches = feature.GetName(langIndex, name) && m_name == name;
|
||||
if (!nameMatches)
|
||||
return false;
|
||||
istringstream is(feature.GetMetadata().Get(feature::Metadata::FMD_TEST_ID));
|
||||
uint64_t id;
|
||||
is >> id;
|
||||
return id == m_id;
|
||||
}
|
||||
|
||||
void TestFeature::Serialize(FeatureBuilder1 & fb) const
|
||||
{
|
||||
fb.SetTestId(m_id);
|
||||
if (m_hasCenter)
|
||||
{
|
||||
auto const center = feature::GetCenter(feature);
|
||||
if (!m_center.EqualDxDy(center, kTestPrecision))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
fb.SetCenter(m_center);
|
||||
CHECK(fb.AddName(m_lang, m_name), ("Can't set feature name:", m_name, "(", m_lang, ")"));
|
||||
}
|
||||
|
||||
// TestCountry -------------------------------------------------------------------------------------
|
||||
|
@ -165,11 +164,6 @@ void TestPOI::Serialize(FeatureBuilder1 & fb) const
|
|||
fb.AddStreet(m_streetName);
|
||||
}
|
||||
|
||||
bool TestPOI::Matches(FeatureType const & feature) const
|
||||
{
|
||||
return TestFeature::Matches(feature) && m_houseNumber == feature.GetHouseNumber();
|
||||
}
|
||||
|
||||
string TestPOI::ToString() const
|
||||
{
|
||||
ostringstream os;
|
||||
|
@ -226,29 +220,6 @@ void TestBuilding::Serialize(FeatureBuilder1 & fb) const
|
|||
fb.SetType(classificator.GetTypeByPath({"building"}));
|
||||
}
|
||||
|
||||
bool TestBuilding::Matches(FeatureType const & feature) const
|
||||
{
|
||||
auto const & checker = ftypes::IsBuildingChecker::Instance();
|
||||
if (!checker(feature))
|
||||
return false;
|
||||
if (!TestFeature::Matches(feature))
|
||||
return false;
|
||||
if (m_houseNumber != feature.GetHouseNumber())
|
||||
return false;
|
||||
|
||||
// TODO(@y): consider to check m_boundary.
|
||||
if (!m_hasCenter && !m_boundary.empty())
|
||||
{
|
||||
m2::PointD center(0, 0);
|
||||
for (auto const & p : m_boundary)
|
||||
center += p;
|
||||
center = center / m_boundary.size();
|
||||
if (!center.EqualDxDy(feature::GetCenter(feature), kTestPrecision))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string TestBuilding::ToString() const
|
||||
{
|
||||
ostringstream os;
|
||||
|
|
|
@ -17,16 +17,17 @@ class TestFeature
|
|||
public:
|
||||
virtual ~TestFeature() = default;
|
||||
|
||||
virtual void Serialize(FeatureBuilder1 & fb) const;
|
||||
virtual bool Matches(FeatureType const & feature) const;
|
||||
virtual string ToString() const = 0;
|
||||
|
||||
bool Matches(FeatureType const & feature) const;
|
||||
inline string const & GetName() const { return m_name; }
|
||||
|
||||
virtual void Serialize(FeatureBuilder1 & fb) const;
|
||||
virtual string ToString() const = 0;
|
||||
|
||||
protected:
|
||||
TestFeature(string const & name, string const & lang);
|
||||
TestFeature(m2::PointD const & center, string const & name, string const & lang);
|
||||
|
||||
uint64_t const m_id;
|
||||
m2::PointD const m_center;
|
||||
bool const m_hasCenter;
|
||||
string const m_name;
|
||||
|
@ -89,7 +90,6 @@ public:
|
|||
|
||||
// TestFeature overrides:
|
||||
void Serialize(FeatureBuilder1 & fb) const override;
|
||||
bool Matches(FeatureType const & feature) const override;
|
||||
string ToString() const override;
|
||||
|
||||
inline void SetHouseNumber(string const & houseNumber) { m_houseNumber = houseNumber; }
|
||||
|
@ -112,7 +112,6 @@ public:
|
|||
|
||||
// TestFeature overrides:
|
||||
void Serialize(FeatureBuilder1 & fb) const override;
|
||||
bool Matches(FeatureType const & feature) const override;
|
||||
string ToString() const override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue