From 8380c959b0589577823a2e1ff968f250e8f9cf7e Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Thu, 6 Jul 2023 16:21:16 -0300 Subject: [PATCH] [generator] Do not set useless hwtag=yescar. Signed-off-by: Viktor Govako --- generator/generator_tests/osm_type_test.cpp | 39 ++++++++++++++-- generator/osm2type.cpp | 49 +++++++++++++++++---- indexer/ftypes_matcher.cpp | 1 + 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/generator/generator_tests/osm_type_test.cpp b/generator/generator_tests/osm_type_test.cpp index e7754efa23..2f62f86f5d 100644 --- a/generator/generator_tests/osm_type_test.cpp +++ b/generator/generator_tests/osm_type_test.cpp @@ -646,14 +646,15 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_Hwtag) auto const params = GetFeatureBuilderParams(tags); - TEST_EQUAL(params.m_types.size(), 7, (params)); + TEST_EQUAL(params.m_types.size(), 6, (params)); TEST(params.IsTypeExist(GetType({"highway", "primary"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "oneway"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "private"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "nofoot"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "yesbicycle"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "bidir_bicycle"})), ()); - TEST(params.IsTypeExist(GetType({"hwtag", "yescar"})), ()); + // We don't put yescar tag for features that already Yes by default. + //TEST(params.IsTypeExist(GetType({"hwtag", "yescar"})), ()); } { @@ -728,11 +729,11 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_Hwtag) auto const params = GetFeatureBuilderParams(tags); - TEST_EQUAL(params.m_types.size(), 4, (params)); + TEST_EQUAL(params.m_types.size(), 3, (params)); TEST(params.IsTypeExist(GetType({"highway", "trunk"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "nofoot"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "nobicycle"})), ()); - TEST(params.IsTypeExist(GetType({"hwtag", "yescar"})), ()); + //TEST(params.IsTypeExist(GetType({"hwtag", "yescar"})), ()); } { @@ -766,6 +767,36 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_Hwtag) TEST(params.IsTypeExist(GetType({"hwtag", "nosidewalk"})), ()); TEST(params.IsTypeExist(GetType({"hwtag", "yesbicycle"})), ()); } + + { + Tags const tags = { + {"bench", "yes"}, + {"bicycle", "yes"}, + {"bin", "yes"}, + {"foot", "designated"}, + {"highway", "footway"}, + {"lit", "yes"}, + {"public_transport", "platform"}, + {"railway", "platform"}, + {"shelter", "yes"}, + {"smoothness", "good"}, + {"surface", "paving_stones"}, + {"tactile_paving", "yes"}, + {"traffic_sign", "DE:239,DE:1022-10"}, + {"tram", "yes"}, + }; + + auto const params = GetFeatureBuilderParams(tags); + + TEST_EQUAL(params.m_types.size(), 8, (params)); + TEST(params.IsTypeExist(GetType({"highway", "footway"})), (params)); + TEST(params.IsTypeExist(GetType({"hwtag", "yesbicycle"})), ()); + TEST(!params.IsTypeExist(GetType({"hwtag", "yesfoot"})), ()); + + /// @todo One platform is enough. + TEST(params.IsTypeExist(GetType({"railway", "platform"})), (params)); + TEST(params.IsTypeExist(GetType({"public_transport", "platform"})), (params)); + } } UNIT_CLASS_TEST(TestWithClassificator, OsmType_Surface) diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp index d34e9ec9a5..87854f2766 100644 --- a/generator/osm2type.cpp +++ b/generator/osm2type.cpp @@ -10,6 +10,7 @@ #include "indexer/classificator.hpp" #include "indexer/feature_impl.hpp" +#include "indexer/ftypes_matcher.hpp" #include "platform/platform.hpp" @@ -885,6 +886,29 @@ void PreprocessElement(OsmElement * p, CalculateOriginFnT const & calcOrg) p->UpdateTag("capital", [&](string & value) { value = "2"; }); } +bool IsCarDesignatedHighway(uint32_t type) +{ + switch (ftypes::IsWayChecker::Instance().GetSearchRank(type)) + { + case ftypes::IsWayChecker::Motorway: + case ftypes::IsWayChecker::Regular: + case ftypes::IsWayChecker::Minors: + return true; + default: + return false; + } +} + +bool IsBicycleDesignatedHighway(uint32_t type) +{ + return ftypes::IsWayChecker::Instance().GetSearchRank(type) == ftypes::IsWayChecker::Cycleway; +} + +bool IsPedestrianDesignatedHighway(uint32_t type) +{ + return ftypes::IsWayChecker::Instance().GetSearchRank(type) == ftypes::IsWayChecker::Pedestrian; +} + void PostprocessElement(OsmElement * p, FeatureBuilderParams & params) { static CachedTypes const types; @@ -1014,16 +1038,25 @@ void PostprocessElement(OsmElement * p, FeatureBuilderParams & params) params.AddType(types.Get(CachedTypes::OneWay)); auto const ApplyFlag = [&flags, &AddParam](Flags::Type f, CachedTypes::Type yes, - CachedTypes::Type no0, CachedTypes::Type no1) + CachedTypes::Type no0, CachedTypes::Type no1, + bool isDesignated) { - if (flags[f] != 0) - AddParam(flags[f] == 1 ? yes : no0); - else if (flags[int(f) + 1] != 0) - AddParam(flags[int(f) + 1] == 1 ? yes : no1); + if (flags[f] == 1 && !isDesignated) + AddParam(yes); + else if (flags[f] == -1) + AddParam(no0); + else if (flags[int(f) + 1] == 1 && !isDesignated) + AddParam(yes); + else if (flags[int(f) + 1] == -1) + AddParam(no1); }; - ApplyFlag(Flags::Foot, CachedTypes::YesFoot, CachedTypes::NoFoot, CachedTypes::NoSidewalk); - ApplyFlag(Flags::Bicycle, CachedTypes::YesBicycle, CachedTypes::NoBicycle, CachedTypes::NoCycleway); - ApplyFlag(Flags::MotorCar, CachedTypes::YesCar, CachedTypes::NoCar, CachedTypes::NoCar); + + ApplyFlag(Flags::Foot, CachedTypes::YesFoot, CachedTypes::NoFoot, CachedTypes::NoSidewalk, + IsPedestrianDesignatedHighway(vType)); + ApplyFlag(Flags::Bicycle, CachedTypes::YesBicycle, CachedTypes::NoBicycle, CachedTypes::NoCycleway, + IsBicycleDesignatedHighway(vType)); + ApplyFlag(Flags::MotorCar, CachedTypes::YesCar, CachedTypes::NoCar, CachedTypes::NoCar, + IsCarDesignatedHighway(vType)); highwayDone = true; } diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp index 3e5b34ee13..a2de493366 100644 --- a/indexer/ftypes_matcher.cpp +++ b/indexer/ftypes_matcher.cpp @@ -347,6 +347,7 @@ IsWayChecker::IsWayChecker() {"secondary", Regular}, {"secondary_link",Regular}, {"service", Minors}, + {"steps", Pedestrian}, {"tertiary", Regular}, {"tertiary_link", Regular}, {"track", Outdoor},