Skip to content

Commit

Permalink
prefer level bits if both, level bits and layer bits are there
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Nov 3, 2024
1 parent 91263e5 commit 06ddcbb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
37 changes: 23 additions & 14 deletions include/osr/extract/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ enum class override : std::uint8_t { kNone, kWhitelist, kBlacklist };

struct tags {
explicit tags(osmium::OSMObject const& o) {
auto const add_levels = [](auto&& t, level_bits_t& level_bits) {
auto s = utl::cstr{t.value()};
while (s) {
auto l = 0.0F;
utl::parse_arg(s, l);
auto const lvl = level_t{std::clamp(l, kMinLevel, kMaxLevel)};
level_bits |= (1U << to_idx(lvl));
if (s) {
++s;
}
}
};

for (auto const& t : o.tags()) {
switch (cista::hash(std::string_view{t.key()})) {
using namespace std::string_view_literals;
Expand Down Expand Up @@ -53,23 +66,15 @@ struct tags {
is_platform_ = true;
}
break;
case cista::hash("level"):
has_level_ = true;
add_levels(t, level_bits_);
break;
case cista::hash("layer"):
// not correct but layer seems to be used like level in some places :/
[[fallthrough]];
case cista::hash("level"): {
has_level_ = true;
auto s = utl::cstr{t.value()};
while (s) {
auto l = 0.0F;
utl::parse_arg(s, l);
auto const lvl = level_t{std::clamp(l, kMinLevel, kMaxLevel)};
level_bits_ |= (1U << to_idx(lvl));
if (s) {
++s;
}
}
has_layer_ = true;
add_levels(t, layer_bits_);
break;
}
case cista::hash("name"): name_ = t.value(); break;
case cista::hash("ref"): ref_ = t.value(); break;
case cista::hash("entrance"): is_entrance_ = true; break;
Expand Down Expand Up @@ -197,6 +202,10 @@ struct tags {
// https://wiki.openstreetmap.org/wiki/Key:level
bool has_level_{false};
level_bits_t level_bits_{0U};

// https://wiki.openstreetmap.org/wiki/Key:layer
bool has_layer_{false};
level_bits_t layer_bits_{0U};
};

template <typename T>
Expand Down
9 changes: 7 additions & 2 deletions src/extract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ struct rel_way {

using rel_ways_t = hash_map<osm_way_idx_t, rel_way>;

std::tuple<level_t, level_t, bool> get_levels(tags const& t) {
return t.has_level_ ? get_levels(t.has_level_, t.level_bits_)
: get_levels(t.has_layer_, t.layer_bits_);
}

way_properties get_way_properties(tags const& t) {
auto const [from, to, _] = get_levels(t.has_level_, t.level_bits_);
auto const [from, to, _] = get_levels(t);
auto p = way_properties{};
std::memset(&p, 0, sizeof(way_properties));
p.is_foot_accessible_ = is_accessible<foot_profile>(t, osm_obj_type::kWay);
Expand All @@ -113,7 +118,7 @@ way_properties get_way_properties(tags const& t) {
}

std::pair<node_properties, level_bits_t> get_node_properties(tags const& t) {
auto const [from, to, is_multi] = get_levels(t.has_level_, t.level_bits_);
auto const [from, to, is_multi] = get_levels(t);
auto p = node_properties{};
std::memset(&p, 0, sizeof(node_properties));
p.from_level_ = to_idx(from);
Expand Down

0 comments on commit 06ddcbb

Please sign in to comment.