Upgrade libosmium to v2.15.6

This commit is contained in:
Desone Burns II
2020-11-17 14:59:06 -07:00
parent 98fd17589d
commit dfc1bfc27e
319 changed files with 6268 additions and 3946 deletions
+2 -2
View File
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -72,10 +72,6 @@ namespace osmium {
*/
class AssemblerLegacy : public detail::BasicAssemblerWithTags {
void add_tags_to_area(osmium::builder::AreaBuilder& builder, const osmium::Way& way) const {
builder.add_item(way.tags());
}
void add_common_tags(osmium::builder::TagListBuilder& tl_builder, std::set<const osmium::Way*>& ways) const {
std::map<std::string, std::size_t> counter;
for (const osmium::Way* way : ways) {
@@ -166,7 +162,7 @@ namespace osmium {
const bool area_okay = create_rings();
if (area_okay || config().create_empty_areas) {
add_tags_to_area(builder, way);
builder.add_item(way.tags());
}
if (area_okay) {
add_rings_to_area(builder);
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -103,9 +103,19 @@ namespace osmium {
*/
class BasicAssembler {
static constexpr const std::size_t max_split_locations = 100ULL;
// Maximum recursion depth, stops complex multipolygons from
// breaking everything.
enum : unsigned {
max_depth = 20U
};
struct slocation {
static constexpr const uint32_t invalid_item = 1u << 30u;
enum {
invalid_item = 1U << 30U
};
uint32_t item : 31;
uint32_t reverse : 1;
@@ -269,7 +279,7 @@ namespace osmium {
using rings_stack = std::vector<rings_stack_element>;
void remove_duplicates(rings_stack& outer_rings) {
static void remove_duplicates(rings_stack& outer_rings) {
while (true) {
const auto it = std::adjacent_find(outer_rings.begin(), outer_rings.end());
if (it == outer_rings.end()) {
@@ -350,7 +360,8 @@ namespace osmium {
std::cerr << " Segment is below (nesting=" << nesting << ")\n";
}
if (segment->ring()->is_outer()) {
const double y = ay + (by - ay) * (lx - ax) / double(bx - ax);
const double y = static_cast<double>(ay) +
static_cast<double>((by - ay) * (lx - ax)) / static_cast<double>(bx - ax);
if (debug()) {
std::cerr << " Segment belongs to outer ring (y=" << y << " ring=" << *segment->ring() << ")\n";
}
@@ -500,7 +511,12 @@ namespace osmium {
void create_locations_list() {
m_locations.reserve(m_segment_list.size() * 2);
for (uint32_t n = 0; n < m_segment_list.size(); ++n) {
// static_cast is okay here: The 32bit limit is way past
// anything that makes sense here and even if there are
// 2^32 segments here, it would simply not go through
// all of them not building the multipolygon correctly.
assert(m_segment_list.size() < std::numeric_limits<uint32_t>::max());
for (uint32_t n = 0; n < static_cast<uint32_t>(m_segment_list.size()); ++n) {
m_locations.emplace_back(n, false);
m_locations.emplace_back(n, true);
}
@@ -703,7 +719,13 @@ namespace osmium {
};
void find_candidates(std::vector<candidate>& candidates, std::unordered_set<osmium::Location>& loc_done, const std::vector<location_to_ring_map>& xrings, candidate& cand) {
struct exceeded_max_depth {};
void find_candidates(std::vector<candidate>& candidates, std::unordered_set<osmium::Location>& loc_done, const std::vector<location_to_ring_map>& xrings, const candidate& cand, unsigned depth = 0) {
if (depth > max_depth) {
throw exceeded_max_depth{};
}
if (debug()) {
std::cerr << " find_candidates sum=" << cand.sum << " start=" << cand.start_location << " stop=" << cand.stop_location << "\n";
for (const auto& ring : cand.rings) {
@@ -741,13 +763,30 @@ namespace osmium {
if (debug()) {
std::cerr << " found candidate\n";
}
candidates.push_back(c);
if (candidates.empty()) {
candidates.push_back(c);
} else if (candidates.size() == 1) {
// add new candidate to vector, keep sorted
if (std::abs(c.sum) < std::abs(candidates.front().sum)) {
candidates.insert(candidates.begin(), c);
} else {
candidates.push_back(c);
}
} else {
// add new candidate if it has either smallest or largest area
if (std::abs(c.sum) < std::abs(candidates.front().sum)) {
candidates.front() = c;
} else if (std::abs(c.sum) > std::abs(candidates.back().sum)) {
candidates.back() = c;
}
}
} else if (loc_done.count(c.stop_location) == 0) {
if (debug()) {
std::cerr << " recurse...\n";
std::cerr << " recurse... (depth=" << depth << " candidates.size=" << candidates.size() << ")\n";
}
loc_done.insert(c.stop_location);
find_candidates(candidates, loc_done, xrings, c);
find_candidates(candidates, loc_done, xrings, c, depth + 1);
loc_done.erase(c.stop_location);
if (debug()) {
std::cerr << " ...back\n";
@@ -790,7 +829,7 @@ namespace osmium {
ring.reset();
}
candidate cand{*ring_min, false};
const candidate cand{*ring_min, false};
// Locations we have visited while finding candidates, used
// to detect loops.
@@ -799,7 +838,14 @@ namespace osmium {
loc_done.insert(cand.stop_location);
std::vector<candidate> candidates;
find_candidates(candidates, loc_done, xrings, cand);
try {
find_candidates(candidates, loc_done, xrings, cand);
} catch (const exceeded_max_depth&) {
if (m_config.debug_level > 0) {
std::cerr << " Exceeded max depth (" << static_cast<unsigned>(max_depth) << ")\n";
}
return false;
}
if (candidates.empty()) {
if (debug()) {
@@ -828,26 +874,20 @@ namespace osmium {
}
// Find the candidate with the smallest/largest area
const auto chosen_cand = ring_min_is_outer ?
std::min_element(candidates.cbegin(), candidates.cend(), [](const candidate& lhs, const candidate& rhs) {
return std::abs(lhs.sum) < std::abs(rhs.sum);
}) :
std::max_element(candidates.cbegin(), candidates.cend(), [](const candidate& lhs, const candidate& rhs) {
return std::abs(lhs.sum) < std::abs(rhs.sum);
});
const auto chosen_cand = ring_min_is_outer ? candidates.front() : candidates.back();
if (debug()) {
std::cerr << " Decided on: sum=" << chosen_cand->sum << "\n";
for (const auto& ring : chosen_cand->rings) {
std::cerr << " Decided on: sum=" << chosen_cand.sum << "\n";
for (const auto& ring : chosen_cand.rings) {
std::cerr << " " << ring.first.ring() << (ring.second ? " reverse" : "") << "\n";
}
}
// Join all (open) rings in the candidate to get one closed ring.
assert(chosen_cand->rings.size() > 1);
const auto& first_ring = chosen_cand->rings.front().first;
assert(chosen_cand.rings.size() > 1);
const auto& first_ring = chosen_cand.rings.front().first;
const ProtoRing& remaining_ring = first_ring.ring();
for (auto it = std::next(chosen_cand->rings.begin()); it != chosen_cand->rings.end(); ++it) {
for (auto it = std::next(chosen_cand.rings.begin()); it != chosen_cand.rings.end(); ++it) {
merge_two_rings(open_ring_its, first_ring, it->first);
}
@@ -1077,9 +1117,20 @@ namespace osmium {
timer_simple_case.start();
create_rings_simple_case();
timer_simple_case.stop();
} else if (m_split_locations.size() > max_split_locations) {
if (m_config.debug_level > 0) {
std::cerr << " Ignoring polygon with "
<< m_split_locations.size()
<< " split locations (>"
<< max_split_locations
<< ")\n";
}
return false;
} else {
if (debug()) {
std::cerr << " Found split locations -> using complex algorithm\n";
if (m_config.debug_level > 0) {
std::cerr << " Found "
<< m_split_locations.size()
<< " split locations -> using complex algorithm\n";
}
++m_stats.area_touching_rings_case;
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -38,6 +38,7 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/osm/node_ref.hpp>
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <iosfwd>
@@ -101,14 +102,10 @@ namespace osmium {
NodeRefSegment() noexcept = default;
NodeRefSegment(const osmium::NodeRef& nr1, const osmium::NodeRef& nr2, role_type role, const osmium::Way* way) noexcept :
m_first(nr1),
m_second(nr2),
m_first(nr1.location() < nr2.location() ? nr1 : nr2),
m_second(nr1.location() < nr2.location() ? nr2 : nr1),
m_way(way),
m_role(role) {
if (nr2.location() < nr1.location()) {
using std::swap;
swap(m_first, m_second);
}
}
/**
@@ -195,7 +192,7 @@ namespace osmium {
}
const char* role_name() const noexcept {
static const char* names[] = { "unknown", "outer", "inner", "empty" };
static const std::array<const char*, 4> names = {{ "unknown", "outer", "inner", "empty" }};
return names[int(m_role)];
}
@@ -205,7 +202,7 @@ namespace osmium {
/**
* The "determinant" of this segment. Used for calculating
* the winding order or a ring.
* the winding order of a ring.
*/
int64_t det() const noexcept {
const vec a{start()};
@@ -348,13 +345,14 @@ namespace osmium {
osmium::Location location;
};
seg_loc sl[4];
sl[0] = {0, s1.first().location() };
sl[1] = {0, s1.second().location()};
sl[2] = {1, s2.first().location() };
sl[3] = {1, s2.second().location()};
std::array<seg_loc, 4> sl = {{
{0, s1.first().location() },
{0, s1.second().location()},
{1, s2.first().location() },
{1, s2.second().location()},
}};
std::sort(sl, sl+4, [](const seg_loc& lhs, const seg_loc& rhs) {
std::sort(sl.begin(), sl.end(), [](const seg_loc& lhs, const seg_loc& rhs) {
return lhs.location < rhs.location;
});
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -196,12 +196,14 @@ namespace osmium {
}
void join_forward(ProtoRing& other) {
m_segments.reserve(m_segments.size() + other.m_segments.size());
for (NodeRefSegment* segment : other.m_segments) {
add_segment_back(segment);
}
}
void join_backward(ProtoRing& other) {
m_segments.reserve(m_segments.size() + other.m_segments.size());
for (auto it = other.m_segments.rbegin(); it != other.m_segments.rend(); ++it) {
(*it)->reverse();
add_segment_back(*it);
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -147,14 +147,14 @@ namespace osmium {
m_debug(debug) {
}
~SegmentList() noexcept = default;
SegmentList(const SegmentList&) = delete;
SegmentList(SegmentList&&) = delete;
SegmentList& operator=(const SegmentList&) = delete;
SegmentList& operator=(SegmentList&&) = delete;
~SegmentList() noexcept = default;
/// The number of segments in the list.
std::size_t size() const noexcept {
return m_segments.size();
@@ -181,7 +181,7 @@ namespace osmium {
return m_segments[n];
}
NodeRefSegment& operator[](std::size_t n) noexcept {
NodeRefSegment& operator[](const std::size_t n) noexcept {
assert(n < m_segments.size());
return m_segments[n];
}
@@ -206,7 +206,7 @@ namespace osmium {
* Enable or disable debug output to stderr. This is used
* for debugging libosmium itself.
*/
void enable_debug_output(bool debug = true) noexcept {
void enable_debug_output(const bool debug = true) noexcept {
m_debug = debug;
}
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -68,8 +68,6 @@ namespace osmium {
detail::BasicAssembler(config) {
}
~GeomAssembler() noexcept = default;
/**
* Assemble an area from the given way.
*
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -70,6 +70,8 @@ namespace osmium {
*
* @tparam TAssembler Multipolygon Assembler class.
* @pre The Ids of all objects must be unique in the input data.
*
* @deprecated Use MultipolygonManager instead.
*/
template <typename TAssembler>
class MultipolygonCollector : public osmium::relations::Collector<MultipolygonCollector<TAssembler>, false, true, false> {
@@ -83,8 +85,13 @@ namespace osmium {
area_stats m_stats;
static constexpr size_t initial_output_buffer_size = 1024 * 1024;
static constexpr size_t max_buffer_size_for_flush = 100 * 1024;
enum {
initial_output_buffer_size = 1024UL * 1024UL
};
enum {
max_buffer_size_for_flush = 100UL * 1024UL
};
void flush_output_buffer() {
if (this->callback()) {
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -63,8 +63,8 @@ namespace osmium {
/**
* This class collects all data needed for creating areas from
* relations tagged with type=multipolygon or type=boundary.
* Most of its functionality is derived from the parent class
* osmium::relations::Collector.
* Most of its functionality is derived from the parent template class
* osmium::relations::RelationsManager.
*
* The actual assembling of the areas is done by the assembler
* class given as template argument.
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -93,6 +93,10 @@ namespace osmium {
m_object_id = object_id;
}
osmium::object_id_type object_id() const noexcept {
return m_object_id;
}
void set_nodes(size_t nodes) noexcept {
m_nodes = nodes;
}
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
+2 -2
View File
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003