From 51cd6d2cb7ae3341b2c727aab18af82788a2ca39 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 30 Oct 2014 16:41:38 +0300 Subject: [PATCH] =?UTF-8?q?[classificator]=20Added=20=E2=80=9Cjunction=3Dr?= =?UTF-8?q?oundabout=E2=80=9D=20type=20for=20routing=20algorithm.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/classificator.txt | 3 ++ data/mapcss-mapping.csv | 1 + data/types.txt | 1 + generator/feature_builder.hpp | 1 + .../generator_tests/feature_builder_test.cpp | 40 +++++++++++++++-- indexer/feature_visibility.cpp | 45 ++++++++++++++----- map/drawer.cpp | 6 +-- 7 files changed, 77 insertions(+), 20 deletions(-) diff --git a/data/classificator.txt b/data/classificator.txt index bfd34ec274..e741778605 100644 --- a/data/classificator.txt +++ b/data/classificator.txt @@ -336,6 +336,9 @@ world + internet_access + wlan - {} + junction + + roundabout - + {} landuse + allotments - basin - diff --git a/data/mapcss-mapping.csv b/data/mapcss-mapping.csv index 8aaed673ee..9d0ac2768c 100644 --- a/data/mapcss-mapping.csv +++ b/data/mapcss-mapping.csv @@ -987,3 +987,4 @@ amenity|waste_disposal;[amenity=waste_disposal];;name;int_name;986; amenity|bbq;[amenity=bbq];;name;int_name;987; hwtag|private;[hwtag=private];;name;int_name;988; route|ferry|motorcar;[route=ferry];;name;int_name;989; +junction|roundabout;[junction=roundabout];;name;int_name;990; \ No newline at end of file diff --git a/data/types.txt b/data/types.txt index fb12837dab..ce2bf24698 100644 --- a/data/types.txt +++ b/data/types.txt @@ -987,3 +987,4 @@ amenity|waste_disposal amenity|bbq hwtag|private route|ferry|motorcar +junction|roundabout diff --git a/generator/feature_builder.hpp b/generator/feature_builder.hpp index 8b061b8b09..6c1a25fd9e 100644 --- a/generator/feature_builder.hpp +++ b/generator/feature_builder.hpp @@ -86,6 +86,7 @@ public: inline size_t GetPointsCount() const { return GetGeometry().size(); } inline size_t GetPolygonsCount() const { return m_polygons.size(); } + inline size_t GetTypesCount() const { return m_params.m_Types.size(); } //@} /// @name Iterate through polygons points. diff --git a/generator/generator_tests/feature_builder_test.cpp b/generator/generator_tests/feature_builder_test.cpp index 5c8e51a047..b8e787a5aa 100644 --- a/generator/generator_tests/feature_builder_test.cpp +++ b/generator/generator_tests/feature_builder_test.cpp @@ -25,7 +25,6 @@ UNIT_TEST(FBuilder_ManyTypes) classificator::Load(); FeatureBuilder1 fb1; - FeatureParams params; char const * arr1[][1] = { @@ -40,13 +39,10 @@ UNIT_TEST(FBuilder_ManyTypes) { "place", "region" }, { "place", "city" }, { "place", "town" }, - { "railway", "rail" }, - { "hwtag", "oneway" }, }; AddTypes(params, arr2); params.FinishAddingTypes(); - params.AddHouseNumber("75"); params.AddHouseName("Best House"); params.name.AddString(0, "Name"); @@ -66,6 +62,42 @@ UNIT_TEST(FBuilder_ManyTypes) TEST(fb2.CheckValid(), ()); TEST_EQUAL(fb1, fb2, ()); + TEST_EQUAL(fb2.GetTypesCount(), 7, ()); +} + +UNIT_TEST(FBuilder_LineTypes) +{ + FeatureBuilder1 fb1; + FeatureParams params; + + char const * arr2[][2] = { + { "railway", "rail" }, + { "highway", "motorway" }, + { "hwtag", "oneway" }, + { "junction", "roundabout" }, + }; + + AddTypes(params, arr2); + params.FinishAddingTypes(); + fb1.SetParams(params); + + fb1.AddPoint(m2::PointD(0, 0)); + fb1.AddPoint(m2::PointD(1, 1)); + fb1.SetLinear(); + + TEST(fb1.RemoveInvalidTypes(), ()); + TEST(fb1.CheckValid(), ()); + + FeatureBuilder1::buffer_t buffer; + TEST(fb1.PreSerialize(), ()); + fb1.Serialize(buffer); + + FeatureBuilder1 fb2; + fb2.Deserialize(buffer); + + TEST(fb2.CheckValid(), ()); + TEST_EQUAL(fb1, fb2, ()); + TEST_EQUAL(fb2.GetTypesCount(), 4, ()); } UNIT_TEST(FVisibility_RemoveNoDrawableTypes) diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp index 59a941d320..5952e5696a 100644 --- a/indexer/feature_visibility.cpp +++ b/indexer/feature_visibility.cpp @@ -104,7 +104,7 @@ namespace drule::KeysT & m_keys; public: - DrawRuleGetter(int scale, feature::EGeomType ft, drule::KeysT & keys) + DrawRuleGetter(int scale, EGeomType ft, drule::KeysT & keys) : m_scale(scale), m_ft(ft), m_keys(keys) { } @@ -126,7 +126,7 @@ namespace pair GetDrawRule(FeatureBase const & f, int level, drule::KeysT & keys) { - feature::TypesHolder types(f); + TypesHolder types(f); ASSERT ( keys.empty(), () ); Classificator const & c = classif(); @@ -232,11 +232,29 @@ namespace return false; } }; + + /// Add here all exception classificator types: needed for algorithms, + /// but don't have drawing rules. + bool TypeAlwaysExists(uint32_t t, EGeomType g = GEOM_UNDEFINED) + { + static const uint32_t s1 = classif().GetTypeByPath({ "junction", "roundabout" }); + static const uint32_t s2 = classif().GetTypeByPath({ "hwtag" }); + + if (g == GEOM_LINE || g == GEOM_UNDEFINED) + { + if (s1 == t) return true; + + ftype::TruncValue(t, 1); + if (s2 == t) return true; + } + + return false; + } } bool IsDrawableAny(uint32_t type) { - return classif().GetObject(type)->IsDrawableAny(); + return (TypeAlwaysExists(type) || classif().GetObject(type)->IsDrawableAny()); } bool IsDrawableLike(vector const & types, EGeomType ft) @@ -254,9 +272,9 @@ bool IsDrawableForIndex(FeatureBase const & f, int level) { Classificator const & c = classif(); - feature::TypesHolder types(f); + TypesHolder types(f); - if (types.GetGeoType() == feature::GEOM_AREA && !types.Has(c.GetCoastType())) + if (types.GetGeoType() == GEOM_AREA && !types.Has(c.GetCoastType())) if (!scales::IsGoodForLevel(level, f.GetLimitRect())) return false; @@ -270,16 +288,19 @@ bool IsDrawableForIndex(FeatureBase const & f, int level) namespace { - class CheckNonDrawableType + class IsNonDrawableType { Classificator & m_c; EGeomType m_type; public: - CheckNonDrawableType(EGeomType ft) : m_c(classif()), m_type(ft) {} + IsNonDrawableType(EGeomType ft) : m_c(classif()), m_type(ft) {} bool operator() (uint32_t t) { + if (TypeAlwaysExists(t, m_type)) + return false; + IsDrawableLikeChecker doCheck(m_type); if (m_c.ProcessObjects(t, doCheck)) return false; @@ -300,7 +321,7 @@ namespace bool RemoveNoDrawableTypes(vector & types, EGeomType ft) { - types.erase(remove_if(types.begin(), types.end(), CheckNonDrawableType(ft)), types.end()); + types.erase(remove_if(types.begin(), types.end(), IsNonDrawableType(ft)), types.end()); return !types.empty(); } @@ -309,7 +330,7 @@ int GetMinDrawableScale(FeatureBase const & f) int const upBound = scales::GetUpperStyleScale(); for (int level = 0; level <= upBound; ++level) - if (feature::IsDrawableForIndex(f, level)) + if (IsDrawableForIndex(f, level)) return level; return -1; @@ -373,7 +394,7 @@ pair GetDrawableScaleRange(TypesHolder const & types) namespace { - bool IsDrawableForRules(feature::TypesHolder const & types, int level, int rules) + bool IsDrawableForRules(TypesHolder const & types, int level, int rules) { Classificator const & c = classif(); @@ -386,7 +407,7 @@ namespace } } -pair GetDrawableScaleRangeForRules(feature::TypesHolder const & types, int rules) +pair GetDrawableScaleRangeForRules(TypesHolder const & types, int rules) { int const upBound = scales::GetUpperStyleScale(); int lowL = -1; @@ -432,4 +453,4 @@ bool TypeSetChecker::IsEqual(uint32_t type) const return (m_type == type); } -} +} // namespace feature diff --git a/map/drawer.cpp b/map/drawer.cpp index 11aa583607..113bcfe7f5 100644 --- a/map/drawer.cpp +++ b/map/drawer.cpp @@ -475,10 +475,8 @@ void Drawer::Draw(di::FeatureInfo const & fi) // draw road numbers if (isPath && !fi.m_styler.m_refText.empty() && m_level >= 12) - { - for (list::const_iterator i = fi.m_pathes.begin(); i != fi.m_pathes.end(); ++i) - drawPathNumber(*i, fi.m_styler); - } + for (auto n : fi.m_pathes) + drawPathNumber(n, fi.m_styler); } int Drawer::ThreadSlot() const