Skip to content

Commit 7fa2e73

Browse files
authored
Merge pull request #1790 from joto/misc-code-cleanup
Misc code cleanups
2 parents 81a1dae + b5e547b commit 7fa2e73

File tree

8 files changed

+64
-41
lines changed

8 files changed

+64
-41
lines changed

src/geom-from-osm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void create_multilinestring(geometry_t *geom,
139139
auto ways = buffer.select<osmium::Way>();
140140
if (ways.size() == 1 && !force_multi) {
141141
auto &line = geom->set<linestring_t>();
142-
auto &way = *ways.begin();
142+
auto const &way = *ways.begin();
143143
if (!fill_point_list(&line, way.nodes())) {
144144
geom->reset();
145145
}

src/geom-functions.cpp

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ point_t interpolate(point_t p1, point_t p2, double frac) noexcept
3232
frac * (p1.y() - p2.y()) + p2.y()};
3333
}
3434

35+
/****************************************************************************/
36+
3537
std::string_view geometry_type(geometry_t const &geom)
3638
{
3739
using namespace std::literals::string_view_literals;
@@ -52,12 +54,16 @@ std::string_view geometry_type(geometry_t const &geom)
5254
}});
5355
}
5456

57+
/****************************************************************************/
58+
5559
std::size_t num_geometries(geometry_t const &geom)
5660
{
5761
return geom.visit(
58-
overloaded{[&](auto const &input) { return input.num_geometries(); }});
62+
[&](auto const &input) { return input.num_geometries(); });
5963
}
6064

65+
/****************************************************************************/
66+
6167
namespace {
6268

6369
class geometry_n_visitor
@@ -67,8 +73,6 @@ class geometry_n_visitor
6773
: m_output(output), m_n(n)
6874
{}
6975

70-
void operator()(nullgeom_t const & /*input*/) const { m_output->reset(); }
71-
7276
void operator()(geom::collection_t const &input) const
7377
{
7478
*m_output = input[m_n];
@@ -113,11 +117,13 @@ geometry_t geometry_n(geometry_t const &input, std::size_t n)
113117
return output;
114118
}
115119

120+
/****************************************************************************/
121+
116122
namespace {
117123

118124
void set_to_same_type(geometry_t *output, geometry_t const &input)
119125
{
120-
input.visit(overloaded{[&](auto in) { output->set<decltype(in)>(); }});
126+
input.visit([&](auto in) { output->set<decltype(in)>(); });
121127
}
122128

123129
class transform_visitor
@@ -233,6 +239,8 @@ geometry_t transform(geometry_t const &input, reprojection const &reprojection)
233239
return output;
234240
}
235241

242+
/****************************************************************************/
243+
236244
namespace {
237245

238246
/**
@@ -335,6 +343,8 @@ geometry_t segmentize(geometry_t const &input, double max_segment_length)
335343
return output;
336344
}
337345

346+
/****************************************************************************/
347+
338348
double area(geometry_t const &geom)
339349
{
340350
return std::abs(geom.visit(
@@ -350,6 +360,8 @@ double area(geometry_t const &geom)
350360
}}));
351361
}
352362

363+
/****************************************************************************/
364+
353365
double length(geometry_t const &geom)
354366
{
355367
return geom.visit(overloaded{
@@ -366,6 +378,8 @@ double length(geometry_t const &geom)
366378
}});
367379
}
368380

381+
/****************************************************************************/
382+
369383
namespace {
370384

371385
class split_visitor
@@ -415,25 +429,6 @@ std::vector<geometry_t> split_multi(geometry_t &&geom, bool split_multi)
415429
return output;
416430
}
417431

418-
/**
419-
* Add points specified by iterators to the linestring. If linestring is not
420-
* empty, do not add the first point returned by *it.
421-
*/
422-
template <typename ITERATOR>
423-
static void add_nodes_to_linestring(linestring_t *linestring, ITERATOR it,
424-
ITERATOR end)
425-
{
426-
if (!linestring->empty()) {
427-
assert(it != end);
428-
++it;
429-
}
430-
431-
while (it != end) {
432-
linestring->push_back(*it);
433-
++it;
434-
}
435-
}
436-
437432
/****************************************************************************/
438433

439434
static void reverse(geom::nullgeom_t * /*output*/,
@@ -490,6 +485,25 @@ geometry_t reverse(geometry_t const &input)
490485

491486
/****************************************************************************/
492487

488+
/**
489+
* Add points specified by iterators to the linestring. If linestring is not
490+
* empty, do not add the first point returned by *it.
491+
*/
492+
template <typename ITERATOR>
493+
static void add_nodes_to_linestring(linestring_t *linestring, ITERATOR it,
494+
ITERATOR end)
495+
{
496+
if (!linestring->empty()) {
497+
assert(it != end);
498+
++it;
499+
}
500+
501+
while (it != end) {
502+
linestring->push_back(*it);
503+
++it;
504+
}
505+
}
506+
493507
void line_merge(geometry_t *output, geometry_t const &input)
494508
{
495509
if (input.is_linestring()) {
@@ -672,6 +686,8 @@ geometry_t line_merge(geometry_t const &input)
672686
return output;
673687
}
674688

689+
/****************************************************************************/
690+
675691
/**
676692
* This helper function is used to calculate centroids of geometry collections.
677693
* It first creates a multi geometry that only contains the geometries of

src/geom-output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ std::basic_ostream<CHAR, TRAITS> &
101101
operator<<(std::basic_ostream<CHAR, TRAITS> &out, const geometry_t &geom)
102102
{
103103
out << geometry_type(geom) << '(';
104-
geom.visit(overloaded{[&](auto const &input) { out << input; }});
104+
geom.visit([&](auto const &input) { out << input; });
105105
return out << ')';
106106
}
107107

src/geom.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ std::size_t dimension(collection_t const &geom)
4040

4141
std::size_t dimension(geometry_t const &geom)
4242
{
43-
return geom.visit(
44-
overloaded{[&](auto const &input) { return dimension(input); }});
43+
return geom.visit([&](auto const &input) { return dimension(input); });
4544
}
4645

4746
} // namespace geom

src/geom.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ class geometry_t
246246
public:
247247
constexpr geometry_t() = default;
248248

249-
constexpr explicit geometry_t(point_t &&geom, int srid = 4326)
250-
: m_geom(geom), m_srid(srid) // geom is trivially copyable, no move needed
249+
// point_t is small and trivially copyable, no move needed like for the
250+
// other constructors.
251+
constexpr explicit geometry_t(point_t geom, int srid = 4326)
252+
: m_geom(geom), m_srid(srid)
251253
{}
252254

253255
constexpr explicit geometry_t(linestring_t &&geom, int srid = 4326)
@@ -373,13 +375,13 @@ class geometry_t
373375

374376
}; // class geometry_t
375377

376-
inline std::size_t dimension(nullgeom_t) noexcept { return 0; }
377-
inline std::size_t dimension(point_t) noexcept { return 0; }
378-
inline std::size_t dimension(linestring_t) noexcept { return 1; }
379-
inline std::size_t dimension(polygon_t) noexcept { return 2; }
380-
inline std::size_t dimension(multipoint_t) noexcept { return 0; }
381-
inline std::size_t dimension(multilinestring_t) noexcept { return 1; }
382-
inline std::size_t dimension(multipolygon_t) noexcept { return 2; }
378+
inline std::size_t dimension(nullgeom_t const &) noexcept { return 0; }
379+
inline std::size_t dimension(point_t const &) noexcept { return 0; }
380+
inline std::size_t dimension(linestring_t const &) noexcept { return 1; }
381+
inline std::size_t dimension(polygon_t const &) noexcept { return 2; }
382+
inline std::size_t dimension(multipoint_t const &) noexcept { return 0; }
383+
inline std::size_t dimension(multilinestring_t const &) noexcept { return 1; }
384+
inline std::size_t dimension(multipolygon_t const &) noexcept { return 2; }
383385

384386
std::size_t dimension(collection_t const &geom);
385387

src/node-persistent-cache.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class node_persistent_cache
2424
node_persistent_cache(std::string file_name, bool remove_file);
2525
~node_persistent_cache() noexcept;
2626

27+
node_persistent_cache(node_persistent_cache const &) = delete;
28+
node_persistent_cache &operator=(node_persistent_cache const &) = delete;
29+
30+
node_persistent_cache(node_persistent_cache &&) = delete;
31+
node_persistent_cache &operator=(node_persistent_cache &&) = delete;
32+
2733
void set(osmid_t id, osmium::Location location);
2834
osmium::Location get(osmid_t id) const noexcept;
2935

tests/test-geom-multipoints.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST_CASE("multipoint_t with a single point", "[NoDB]")
3434
REQUIRE(area(geom) == Approx(0.0));
3535
REQUIRE(length(geom) == Approx(0.0));
3636
REQUIRE(reverse(geom) == geom);
37-
REQUIRE(centroid(geom) == geom::geometry_t{std::move(point)});
37+
REQUIRE(centroid(geom) == geom::geometry_t{point});
3838

3939
REQUIRE(mp[0] == expected);
4040
}
@@ -63,9 +63,9 @@ TEST_CASE("multipoint_t with several points", "[NoDB]")
6363
REQUIRE(mp[1] == p1);
6464
REQUIRE(mp[2] == p2);
6565

66-
REQUIRE(geometry_n(geom, 1) == geom::geometry_t{std::move(p0)});
67-
REQUIRE(geometry_n(geom, 2) == geom::geometry_t{std::move(p1)});
68-
REQUIRE(geometry_n(geom, 3) == geom::geometry_t{std::move(p2)});
66+
REQUIRE(geometry_n(geom, 1) == geom::geometry_t{p0});
67+
REQUIRE(geometry_n(geom, 2) == geom::geometry_t{p1});
68+
REQUIRE(geometry_n(geom, 3) == geom::geometry_t{p2});
6969
}
7070

7171
TEST_CASE("create_multipoint from OSM data", "[NoDB]")

tests/test-geom-output.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TEST_CASE("point_t output", "[NoDB]")
3333
ss1 << g;
3434
CHECK(ss1.str() == "1 2");
3535

36-
geom::geometry_t geom{std::move(g)};
36+
geom::geometry_t geom{g};
3737
std::stringstream ss2;
3838
ss2 << geom;
3939
CHECK(ss2.str() == "POINT(1 2)");

0 commit comments

Comments
 (0)