forked from organicmaps/organicmaps
IsBuildingPartChecker optimization.
This commit is contained in:
parent
d1cdbcd973
commit
5d2b838aa1
3 changed files with 38 additions and 44 deletions
|
@ -137,7 +137,10 @@ void RuleDrawer::operator()(FeatureType const & f)
|
|||
bool is3dBuilding = false;
|
||||
if (m_is3dBuidings && f.GetLayer() >= 0)
|
||||
{
|
||||
is3dBuilding = (ftypes::IsBuildingChecker::Instance()(f) || ftypes::IsBuildingPartChecker::Instance()(f)) &&
|
||||
// Looks like nonsense, but there are some osm objects with types
|
||||
// highway-path-bridge and building (sic!) at the same time (pedestrian crossing).
|
||||
is3dBuilding = (ftypes::IsBuildingChecker::Instance()(f) ||
|
||||
ftypes::IsBuildingPartChecker::Instance()(f)) &&
|
||||
!ftypes::IsBridgeChecker::Instance()(f) &&
|
||||
!ftypes::IsTunnelChecker::Instance()(f);
|
||||
}
|
||||
|
|
|
@ -224,8 +224,9 @@ IsLocalityChecker::IsLocalityChecker()
|
|||
m_types.push_back(c.GetTypeByPath(vector<string>(arr[i], arr[i] + 2)));
|
||||
}
|
||||
|
||||
IsBuildingPartChecker::IsBuildingPartChecker() : BaseChecker(3)
|
||||
IsBuildingPartChecker::IsBuildingPartChecker() : BaseChecker(1)
|
||||
{
|
||||
m_types.push_back(classif().GetTypeByPath({"building:part"}));
|
||||
}
|
||||
|
||||
IsBuildingPartChecker const & IsBuildingPartChecker::Instance()
|
||||
|
@ -234,11 +235,6 @@ IsBuildingPartChecker const & IsBuildingPartChecker::Instance()
|
|||
return inst;
|
||||
}
|
||||
|
||||
bool IsBuildingPartChecker::IsMatched(uint32_t type) const
|
||||
{
|
||||
return IsTypeConformed(type, {"building:part"});
|
||||
}
|
||||
|
||||
IsBridgeChecker::IsBridgeChecker() : BaseChecker(3)
|
||||
{
|
||||
}
|
||||
|
@ -333,23 +329,24 @@ uint32_t GetPopulationByRadius(double r)
|
|||
return my::rounds(pow(r / 550.0, 3.6));
|
||||
}
|
||||
|
||||
bool IsTypeConformed(uint32_t type, vector<string> const & path)
|
||||
bool IsTypeConformed(uint32_t type, StringIL const & path)
|
||||
{
|
||||
Classificator const & c = classif();
|
||||
ClassifObject const * p = c.GetRoot();
|
||||
ClassifObject const * p = classif().GetRoot();
|
||||
ASSERT(p, ());
|
||||
|
||||
uint8_t val = 0, i = 0;
|
||||
for (auto const & n : path)
|
||||
for (char const * s : path)
|
||||
{
|
||||
if (!ftype::GetValue(type, i, val))
|
||||
return false;
|
||||
|
||||
p = p->GetObject(val);
|
||||
if (p == 0)
|
||||
return false;
|
||||
string const name = p->GetName();
|
||||
if (n != name && n != "*")
|
||||
|
||||
if (p->GetName() != s && strcmp(s, "*") != 0)
|
||||
return false;
|
||||
|
||||
++i;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "base/base.hpp"
|
||||
|
||||
#include "std/algorithm.hpp"
|
||||
#include "std/initializer_list.hpp"
|
||||
#include "std/string.hpp"
|
||||
#include "std/utility.hpp"
|
||||
#include "std/vector.hpp"
|
||||
|
@ -16,15 +17,16 @@ namespace ftypes
|
|||
class BaseChecker
|
||||
{
|
||||
size_t const m_level;
|
||||
virtual bool IsMatched(uint32_t type) const;
|
||||
|
||||
protected:
|
||||
vector<uint32_t> m_types;
|
||||
|
||||
public:
|
||||
BaseChecker(size_t level = 2) : m_level(level) {}
|
||||
virtual ~BaseChecker() {}
|
||||
virtual bool IsMatched(uint32_t type) const;
|
||||
|
||||
BaseChecker(size_t level = 2) : m_level(level) {}
|
||||
virtual ~BaseChecker() = default;
|
||||
|
||||
public:
|
||||
bool operator() (feature::TypesHolder const & types) const;
|
||||
bool operator() (FeatureType const & ft) const;
|
||||
bool operator() (vector<uint32_t> const & types) const;
|
||||
|
@ -36,49 +38,43 @@ public:
|
|||
|
||||
class IsPeakChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsPeakChecker();
|
||||
|
||||
public:
|
||||
static IsPeakChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsATMChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsATMChecker();
|
||||
|
||||
public:
|
||||
static IsATMChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsSpeedCamChecker : public BaseChecker
|
||||
{
|
||||
IsSpeedCamChecker();
|
||||
|
||||
public:
|
||||
static IsSpeedCamChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsFuelStationChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsFuelStationChecker();
|
||||
|
||||
public:
|
||||
static IsFuelStationChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsRailwayStationChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsRailwayStationChecker();
|
||||
|
||||
public:
|
||||
static IsRailwayStationChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsStreetChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsStreetChecker();
|
||||
|
||||
public:
|
||||
template <typename TFn>
|
||||
void ForEachType(TFn && fn) const
|
||||
{
|
||||
|
@ -90,17 +86,15 @@ public:
|
|||
|
||||
class IsOneWayChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsOneWayChecker();
|
||||
|
||||
public:
|
||||
static IsOneWayChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsRoundAboutChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsRoundAboutChecker();
|
||||
|
||||
public:
|
||||
static IsRoundAboutChecker const & Instance();
|
||||
};
|
||||
|
||||
|
@ -121,25 +115,26 @@ public:
|
|||
|
||||
class IsBuildingPartChecker : public BaseChecker
|
||||
{
|
||||
virtual bool IsMatched(uint32_t type) const;
|
||||
public:
|
||||
IsBuildingPartChecker();
|
||||
public:
|
||||
static IsBuildingPartChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsBridgeChecker : public BaseChecker
|
||||
{
|
||||
virtual bool IsMatched(uint32_t type) const;
|
||||
public:
|
||||
virtual bool IsMatched(uint32_t type) const override;
|
||||
|
||||
IsBridgeChecker();
|
||||
public:
|
||||
static IsBridgeChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsTunnelChecker : public BaseChecker
|
||||
{
|
||||
virtual bool IsMatched(uint32_t type) const;
|
||||
public:
|
||||
virtual bool IsMatched(uint32_t type) const override;
|
||||
|
||||
IsTunnelChecker();
|
||||
public:
|
||||
static IsTunnelChecker const & Instance();
|
||||
};
|
||||
|
||||
|
@ -149,9 +144,8 @@ enum Type { NONE = -1, COUNTRY = 0, STATE, CITY, TOWN, VILLAGE, LOCALITY_COUNT }
|
|||
|
||||
class IsLocalityChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsLocalityChecker();
|
||||
|
||||
public:
|
||||
Type GetType(feature::TypesHolder const & types) const;
|
||||
Type GetType(FeatureType const & f) const;
|
||||
|
||||
|
@ -164,26 +158,27 @@ public:
|
|||
uint32_t GetPopulation(FeatureType const & ft);
|
||||
double GetRadiusByPopulation(uint32_t p);
|
||||
uint32_t GetPopulationByRadius(double r);
|
||||
//@}
|
||||
|
||||
/// Check if type conforms the path. Strings in the path can be
|
||||
/// feature types like "highway", "living_street", "bridge" and so on
|
||||
/// or *. * means any class.
|
||||
/// The root name ("world") is ignored
|
||||
bool IsTypeConformed(uint32_t type, vector<string> const & path);
|
||||
bool IsTypeConformed(uint32_t type, StringIL const & path);
|
||||
|
||||
// Highway class. The order is important.
|
||||
// The enum values follow from the biggest roads (Trunk) to the smallest ones (Service).
|
||||
enum class HighwayClass
|
||||
{
|
||||
Undefined = 0, // There has not been any attempt of calculating HighwayClass.
|
||||
Error, // There was an attempt of calculating HighwayClass but it was not successful.
|
||||
Error, // There was an attempt of calculating HighwayClass but it was not successful.
|
||||
Trunk,
|
||||
Primary,
|
||||
Secondary,
|
||||
Tertiary,
|
||||
LivingStreet,
|
||||
Service,
|
||||
Count // This value is used for internals only.
|
||||
Count // This value is used for internals only.
|
||||
};
|
||||
|
||||
string DebugPrint(HighwayClass const cls);
|
||||
|
@ -191,5 +186,4 @@ string DebugPrint(HighwayClass const cls);
|
|||
HighwayClass GetHighwayClass(feature::TypesHolder const & types);
|
||||
HighwayClass GetHighwayClass(FeatureType const & ft);
|
||||
|
||||
//@}
|
||||
} // namespace ftypes
|
||||
|
|
Loading…
Add table
Reference in a new issue