Skip to content

Commit ce415eb

Browse files
authored
Merge pull request #2334 from joto/cleanups
Various cleanups
2 parents 8881168 + fcf1ddd commit ce415eb

12 files changed

+30
-47
lines changed

src/flex-lua-expire-output.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ create_expire_output(lua_State *lua_state, std::string const &default_schema,
6565
return new_expire_output;
6666
}
6767

68-
TRAMPOLINE_WRAPPED_OBJECT(expire_output, __tostring)
68+
TRAMPOLINE_WRAPPED_OBJECT(expire_output, tostring)
6969
TRAMPOLINE_WRAPPED_OBJECT(expire_output, filename)
7070
TRAMPOLINE_WRAPPED_OBJECT(expire_output, maxzoom)
7171
TRAMPOLINE_WRAPPED_OBJECT(expire_output, minzoom)
@@ -112,7 +112,7 @@ void lua_wrapper_expire_output::init(lua_State *lua_state)
112112
lua_pushvalue(lua_state, -1);
113113
lua_setfield(lua_state, -2, "__index");
114114
luaX_add_table_func(lua_state, "__tostring",
115-
lua_trampoline_expire_output___tostring);
115+
lua_trampoline_expire_output_tostring);
116116
luaX_add_table_func(lua_state, "filename",
117117
lua_trampoline_expire_output_filename);
118118
luaX_add_table_func(lua_state, "maxzoom",
@@ -126,7 +126,7 @@ void lua_wrapper_expire_output::init(lua_State *lua_state)
126126
lua_pop(lua_state, 2);
127127
}
128128

129-
int lua_wrapper_expire_output::__tostring() const
129+
int lua_wrapper_expire_output::tostring() const
130130
{
131131
std::string const str =
132132
fmt::format("osm2pgsql.ExpireOutput[minzoom={},maxzoom={},filename={},"

src/flex-lua-expire-output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class lua_wrapper_expire_output : public lua_wrapper_base<expire_output_t>
3636
{
3737
}
3838

39-
int __tostring() const;
39+
int tostring() const;
4040
int filename() const;
4141
int maxzoom() const;
4242
int minzoom() const;

src/flex-lua-locator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ locator_t &create_locator(lua_State *lua_state,
3636
return new_locator;
3737
}
3838

39-
TRAMPOLINE_WRAPPED_OBJECT(locator, __tostring)
39+
TRAMPOLINE_WRAPPED_OBJECT(locator, tostring)
4040
TRAMPOLINE_WRAPPED_OBJECT(locator, name)
4141
TRAMPOLINE_WRAPPED_OBJECT(locator, add_bbox)
4242
TRAMPOLINE_WRAPPED_OBJECT(locator, add_from_db)
@@ -83,7 +83,7 @@ void lua_wrapper_locator::init(lua_State *lua_state,
8383
lua_pushvalue(lua_state, -1);
8484
lua_setfield(lua_state, -2, "__index");
8585
luaX_add_table_func(lua_state, "__tostring",
86-
lua_trampoline_locator___tostring);
86+
lua_trampoline_locator_tostring);
8787
luaX_add_table_func(lua_state, "name", lua_trampoline_locator_name);
8888
luaX_add_table_func(lua_state, "add_bbox", lua_trampoline_locator_add_bbox);
8989
luaX_add_table_func(lua_state, "add_from_db",
@@ -96,7 +96,7 @@ void lua_wrapper_locator::init(lua_State *lua_state,
9696
lua_pop(lua_state, 2);
9797
}
9898

99-
int lua_wrapper_locator::__tostring() const
99+
int lua_wrapper_locator::tostring() const
100100
{
101101
std::string const str{fmt::format("osm2pgsql.Locator[name={},size={}]",
102102
self().name(), self().size())};

src/flex-lua-locator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class lua_wrapper_locator : public lua_wrapper_base<locator_t>
3838
{
3939
}
4040

41-
int __tostring() const;
41+
int tostring() const;
4242
int name() const;
4343
int add_bbox();
4444
int add_from_db();

src/flex-lua-table.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ void setup_flex_table_indexes(lua_State *lua_state, flex_table_t *table,
418418
lua_pop(lua_state, 1); // "indexes"
419419
}
420420

421-
TRAMPOLINE_WRAPPED_OBJECT(table, __tostring)
421+
TRAMPOLINE_WRAPPED_OBJECT(table, tostring)
422422
TRAMPOLINE_WRAPPED_OBJECT(table, cluster)
423423
TRAMPOLINE_WRAPPED_OBJECT(table, columns)
424424
TRAMPOLINE_WRAPPED_OBJECT(table, name)
@@ -469,7 +469,7 @@ void lua_wrapper_table::init(lua_State *lua_state)
469469
lua_pushvalue(lua_state, -1);
470470
lua_setfield(lua_state, -2, "__index");
471471
luaX_add_table_func(lua_state, "__tostring",
472-
lua_trampoline_table___tostring);
472+
lua_trampoline_table_tostring);
473473
luaX_add_table_func(lua_state, "insert", lua_trampoline_table_insert);
474474
luaX_add_table_func(lua_state, "name", lua_trampoline_table_name);
475475
luaX_add_table_func(lua_state, "schema", lua_trampoline_table_schema);
@@ -479,7 +479,7 @@ void lua_wrapper_table::init(lua_State *lua_state)
479479
lua_pop(lua_state, 2);
480480
}
481481

482-
int lua_wrapper_table::__tostring() const
482+
int lua_wrapper_table::tostring() const
483483
{
484484
std::string const str{fmt::format("osm2pgsql.Table[{}]", self().name())};
485485
luaX_pushstring(lua_state(), str);

src/flex-lua-table.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class lua_wrapper_table : public lua_wrapper_base<flex_table_t>
3636
{
3737
}
3838

39-
int __tostring() const;
39+
int tostring() const;
4040
int cluster() const;
4141
int columns() const;
4242
int name() const;

src/flex-lua-wrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cassert>
1616
#include <exception>
1717

18+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
1819
#define TRAMPOLINE_WRAPPED_OBJECT(obj_name, func_name) \
1920
int lua_trampoline_##obj_name##_##func_name(lua_State *lua_state) \
2021
{ \

src/gen/gen-discrete-isolation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ FROM {src} WHERE {importance_column} > 0
113113
double const dx = coords[m].first - coords[n].first;
114114
double const dy = coords[m].second - coords[n].second;
115115
double const dist = dx * dx + dy * dy;
116-
if (dist < min) {
117-
min = dist;
118-
}
116+
min = std::min(dist, min);
119117
}
120118
data[n].di = std::sqrt(min);
121119
}

src/geom-box.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,17 @@
99

1010
#include "geom-box.hpp"
1111

12+
#include <algorithm>
1213
#include <variant>
1314

1415
namespace geom {
1516

1617
box_t &box_t::extend(point_t const &point) noexcept
1718
{
18-
if (point.x() < m_min_x) {
19-
m_min_x = point.x();
20-
}
21-
if (point.y() < m_min_y) {
22-
m_min_y = point.y();
23-
}
24-
if (point.x() > m_max_x) {
25-
m_max_x = point.x();
26-
}
27-
if (point.y() > m_max_y) {
28-
m_max_y = point.y();
29-
}
30-
19+
m_min_x = std::min(point.x(), m_min_x);
20+
m_min_y = std::min(point.y(), m_min_y);
21+
m_max_x = std::max(point.x(), m_max_x);
22+
m_max_y = std::max(point.y(), m_max_y);
3123
return *this;
3224
}
3325

@@ -40,18 +32,10 @@ void box_t::extend(point_list_t const &list) noexcept
4032

4133
void box_t::extend(box_t const &box) noexcept
4234
{
43-
if (box.min_x() < m_min_x) {
44-
m_min_x = box.min_x();
45-
}
46-
if (box.min_y() < m_min_y) {
47-
m_min_y = box.min_y();
48-
}
49-
if (box.max_x() > m_max_x) {
50-
m_max_x = box.max_x();
51-
}
52-
if (box.max_y() > m_max_y) {
53-
m_max_y = box.max_y();
54-
}
35+
m_min_x = std::min(box.min_x(), m_min_x);
36+
m_min_y = std::min(box.min_y(), m_min_y);
37+
m_max_x = std::max(box.max_x(), m_max_x);
38+
m_max_y = std::max(box.max_y(), m_max_y);
5539
}
5640

5741
box_t envelope(geom::nullgeom_t const & /*geom*/) { return box_t{}; }

src/geom-pole-of-inaccessibility.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ bool point_to_ring_distance_squared(point_t point, ring_t const &ring,
9090

9191
double const d =
9292
point_to_segment_distance_squared(point, a, b, stretch);
93-
if (d < *min_dist_squared) {
94-
*min_dist_squared = d;
95-
}
93+
*min_dist_squared = std::min(d, *min_dist_squared);
9694
}
9795

9896
return inside;
@@ -158,9 +156,7 @@ point_t pole_of_inaccessibility(const polygon_t &polygon, double precision,
158156

159157
double const min_precision =
160158
std::max(envelope.width(), envelope.height()) / 1000.0;
161-
if (min_precision > precision) {
162-
precision = min_precision;
163-
}
159+
precision = std::max(min_precision, precision);
164160

165161
box_t const stretched_envelope{envelope.min_x(), envelope.min_y() * stretch,
166162
envelope.max_x(),

0 commit comments

Comments
 (0)