diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c5b10040..30125c23f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,7 @@ Code must be written in the always be used for code blocks, even one-liners. Names should use underscores, not camel case, with class/struct names ending in -`_t`. Template parameters must use all upper case. +`_t`. Constants and template parameters must use all upper case. Header files should be included in the following order, each group in their own block: diff --git a/src/db-copy.cpp b/src/db-copy.cpp index b02975f04..f0fd0e33a 100644 --- a/src/db-copy.cpp +++ b/src/db-copy.cpp @@ -100,7 +100,7 @@ void db_copy_thread_t::send_command(db_cmd_t &&buffer) std::unique_lock lock{m_shared.queue_mutex}; m_shared.queue_full_cond.wait(lock, [&] { - return m_shared.worker_queue.size() < db_cmd_copy_t::Max_buffers; + return m_shared.worker_queue.size() < db_cmd_copy_t::MAX_BUFFERS; }); m_shared.worker_queue.push_back(std::move(buffer)); diff --git a/src/db-copy.hpp b/src/db-copy.hpp index f843aad8a..c1c1c3a57 100644 --- a/src/db-copy.hpp +++ b/src/db-copy.hpp @@ -79,7 +79,7 @@ class db_deleter_by_id_t * There is a trade-off here between sending as few DELETE SQL as * possible and keeping the size of the deletable vector managable. */ - static constexpr std::size_t Max_entries = 1000000; + static constexpr std::size_t MAX_ENTRIES = 1000000; public: bool has_data() const noexcept { return !m_deletables.empty(); } @@ -89,7 +89,7 @@ class db_deleter_by_id_t void delete_rows(std::string const &table, std::string const &column, pg_conn_t const &db_connection); - bool is_full() const noexcept { return m_deletables.size() > Max_entries; } + bool is_full() const noexcept { return m_deletables.size() > MAX_ENTRIES; } private: /// Vector with object to delete before copying @@ -105,7 +105,7 @@ class db_deleter_by_type_and_id_t * There is a trade-off here between sending as few DELETE SQL as * possible and keeping the size of the deletable vector managable. */ - static constexpr std::size_t Max_entries = 1000000; + static constexpr std::size_t MAX_ENTRIES = 1000000; struct item_t { @@ -129,7 +129,7 @@ class db_deleter_by_type_and_id_t void delete_rows(std::string const &table, std::string const &column, pg_conn_t const &db_connection); - bool is_full() const noexcept { return m_deletables.size() > Max_entries; } + bool is_full() const noexcept { return m_deletables.size() > MAX_ENTRIES; } private: /// Vector with object to delete before copying @@ -145,7 +145,7 @@ struct db_cmd_copy_t * to speed up processing. Currently a one-size fits all value. * Needs more testing and individual values per queue. */ - static constexpr std::size_t Max_buf_size = 10 * 1024 * 1024; + static constexpr std::size_t MAX_BUF_SIZE = 10UL * 1024UL * 1024UL; /** * Maximum length of the queue with COPY data. @@ -155,7 +155,7 @@ struct db_cmd_copy_t * be full and it is better to keep the queue smaller to reduce memory * usage. Current value is just assumed to be a reasonable trade off. */ - static constexpr std::size_t Max_buffers = 10; + static constexpr std::size_t MAX_BUFFERS = 10; /// Name of the target table for the copy operation std::shared_ptr target; @@ -167,7 +167,7 @@ struct db_cmd_copy_t explicit db_cmd_copy_t(std::shared_ptr t) : target(std::move(t)) { - buffer.reserve(Max_buf_size); + buffer.reserve(MAX_BUF_SIZE); } explicit operator bool() const noexcept { return target != nullptr; } @@ -182,7 +182,7 @@ class db_cmd_copy_delete_t : public db_cmd_copy_t /// Return true if the buffer is filled up. bool is_full() const noexcept { - return (buffer.size() > Max_buf_size - 100) || m_deleter.is_full(); + return (buffer.size() > MAX_BUF_SIZE - 100) || m_deleter.is_full(); } bool has_deletables() const noexcept { return m_deleter.has_data(); } diff --git a/src/expire-tiles.cpp b/src/expire-tiles.cpp index 413699025..21eda2df7 100644 --- a/src/expire-tiles.cpp +++ b/src/expire-tiles.cpp @@ -63,8 +63,8 @@ geom::point_t expire_tiles::coords_to_tile(geom::point_t const &point) { auto const c = m_projection->target_to_tile(point); - return {m_map_width * (0.5 + c.x() / tile_t::earth_circumference), - m_map_width * (0.5 - c.y() / tile_t::earth_circumference)}; + return {m_map_width * (0.5 + c.x() / tile_t::EARTH_CIRCUMFERENCE), + m_map_width * (0.5 - c.y() / tile_t::EARTH_CIRCUMFERENCE)}; } void expire_tiles::from_point_list(geom::point_list_t const &list, @@ -224,14 +224,14 @@ int expire_tiles::from_bbox(geom::box_t const &box, double const width = box.width(); double const height = box.height(); - if (width > tile_t::half_earth_circumference + 1) { + if (width > tile_t::HALF_EARTH_CIRCUMFERENCE + 1) { /* Over half the planet's width within the bounding box - assume the box crosses the international date line and split it into two boxes */ - int ret = from_bbox({-tile_t::half_earth_circumference, box.min_y(), + int ret = from_bbox({-tile_t::HALF_EARTH_CIRCUMFERENCE, box.min_y(), box.min_x(), box.max_y()}, expire_config); ret += from_bbox({box.max_x(), box.min_y(), - tile_t::half_earth_circumference, box.max_y()}, + tile_t::HALF_EARTH_CIRCUMFERENCE, box.max_y()}, expire_config); return ret; } diff --git a/src/gen/osm2pgsql-gen.cpp b/src/gen/osm2pgsql-gen.cpp index 04c4526ba..8376edc5f 100644 --- a/src/gen/osm2pgsql-gen.cpp +++ b/src/gen/osm2pgsql-gen.cpp @@ -76,7 +76,7 @@ namespace { -constexpr std::size_t const max_force_single_thread = 4; +constexpr std::size_t const MAX_FORCE_SINGLE_THREAD = 4; struct tile_extent { @@ -496,7 +496,7 @@ class genproc_t } } log_debug("Need to process {} tiles.", tile_list.size()); - if (m_jobs == 1 || tile_list.size() < max_force_single_thread) { + if (m_jobs == 1 || tile_list.size() < MAX_FORCE_SINGLE_THREAD) { log_debug("Running in single-threaded mode."); tile_processor_t tp{generalizer, tile_list.size()}; while (!tile_list.empty()) { diff --git a/src/gen/tracer.cpp b/src/gen/tracer.cpp index 7d4dcd448..7f9eb9296 100644 --- a/src/gen/tracer.cpp +++ b/src/gen/tracer.cpp @@ -42,7 +42,7 @@ tracer_t::trace(canvas_t const &canvas, tile_t const &tile, double min_area) prepare(canvas); potrace_bitmap_t const bitmap{int(canvas.size()), int(canvas.size()), - int(canvas.size() / bits_per_word), + int(canvas.size() / BITS_PER_WORD), m_bits.data()}; std::unique_ptr state{ @@ -64,9 +64,9 @@ void tracer_t::reset() void tracer_t::prepare(canvas_t const &canvas) noexcept { std::size_t const size = canvas.size(); - assert(size % bits_per_word == 0); + assert(size % BITS_PER_WORD == 0); - m_bits.reserve((size * size) / bits_per_word); + m_bits.reserve((size * size) / BITS_PER_WORD); for (unsigned char const *d = canvas.begin(); d != canvas.end(); d += 8) { auto w = bit_squeeze(0, d); diff --git a/src/gen/tracer.hpp b/src/gen/tracer.hpp index 284a3443d..d22d49646 100644 --- a/src/gen/tracer.hpp +++ b/src/gen/tracer.hpp @@ -39,7 +39,7 @@ class tracer_t std::size_t num_points() const noexcept { return m_num_points; } private: - static constexpr auto const bits_per_word = sizeof(potrace_word) * 8; + static constexpr auto const BITS_PER_WORD = sizeof(potrace_word) * 8; geom::point_t make_point(potrace_dpoint_t const &p) const noexcept; diff --git a/src/geom.hpp b/src/geom.hpp index b87cae0d3..250f88081 100644 --- a/src/geom.hpp +++ b/src/geom.hpp @@ -198,7 +198,7 @@ class multigeometry_t using iterator = typename std::vector::iterator; using value_type = GEOM; - static constexpr bool const for_point = std::is_same_v; + static constexpr bool const FOR_POINT = std::is_same_v; [[nodiscard]] std::size_t num_geometries() const noexcept { @@ -206,7 +206,7 @@ class multigeometry_t } GEOM & - add_geometry(typename std::conditional_t geom) + add_geometry(typename std::conditional_t geom) { m_geometry.push_back(std::forward(geom)); return m_geometry.back(); diff --git a/src/lua-utils.cpp b/src/lua-utils.cpp index 928bc9222..376d460a9 100644 --- a/src/lua-utils.cpp +++ b/src/lua-utils.cpp @@ -36,7 +36,7 @@ void *luaX_get_context(lua_State *lua_state) noexcept namespace { // Unique key for lua registry -constexpr char const *const osm2pgsql_output_flex = "osm2pgsql_output_flex"; +constexpr char const *const OSM2PGSQL_OUTPUT_FLEX = "osm2pgsql_output_flex"; } // anonymous namespace @@ -44,7 +44,7 @@ void luaX_set_context(lua_State *lua_state, void *ptr) noexcept { assert(lua_state); assert(ptr); - lua_pushlightuserdata(lua_state, (void *)osm2pgsql_output_flex); + lua_pushlightuserdata(lua_state, (void *)OSM2PGSQL_OUTPUT_FLEX); lua_pushlightuserdata(lua_state, ptr); lua_settable(lua_state, LUA_REGISTRYINDEX); } @@ -52,7 +52,7 @@ void luaX_set_context(lua_State *lua_state, void *ptr) noexcept void *luaX_get_context(lua_State *lua_state) noexcept { assert(lua_state); - lua_pushlightuserdata(lua_state, (void *)osm2pgsql_output_flex); + lua_pushlightuserdata(lua_state, (void *)OSM2PGSQL_OUTPUT_FLEX); lua_gettable(lua_state, LUA_REGISTRYINDEX); auto *const ptr = lua_touserdata(lua_state, -1); assert(ptr); diff --git a/src/node-locations.cpp b/src/node-locations.cpp index 8b86c880e..9f1a2eac8 100644 --- a/src/node-locations.cpp +++ b/src/node-locations.cpp @@ -64,7 +64,7 @@ osmium::Location node_locations_t::get(osmid_t id) const osmium::DeltaDecode dx; osmium::DeltaDecode dy; - for (std::size_t n = 0; n < block_size && begin != end; ++n) { + for (std::size_t n = 0; n < BLOCK_SIZE && begin != end; ++n) { auto const bid = did.update( static_cast(protozero::decode_varint(&begin, end))); auto const x = static_cast(dx.update( @@ -83,13 +83,13 @@ osmium::Location node_locations_t::get(osmid_t id) const void node_locations_t::log_stats() { - constexpr auto const mbyte = 1024 * 1024; + constexpr auto const MBYTE = 1024 * 1024; log_debug("Node locations cache:"); log_debug(" num locations stored: {}", m_count); - log_debug(" bytes overall: {}MB", used_memory() / mbyte); - log_debug(" data capacity: {}MB", m_data.capacity() / mbyte); - log_debug(" data size: {}MB", m_data.size() / mbyte); - log_debug(" index used memory: {}MB", m_index.used_memory() / mbyte); + log_debug(" bytes overall: {}MB", used_memory() / MBYTE); + log_debug(" data capacity: {}MB", m_data.capacity() / MBYTE); + log_debug(" data size: {}MB", m_data.size() / MBYTE); + log_debug(" index used memory: {}MB", m_index.used_memory() / MBYTE); } void node_locations_t::clear() diff --git a/src/node-locations.hpp b/src/node-locations.hpp index 98fa3b8f6..cf50b68a0 100644 --- a/src/node-locations.hpp +++ b/src/node-locations.hpp @@ -81,9 +81,15 @@ class node_locations_t void clear(); private: + /** + * The block size used for internal blocks. The larger the block size + * the less memory is consumed but the more expensive the access is. + */ + static constexpr const std::size_t BLOCK_SIZE = 32; + bool first_entry_in_block() const noexcept { - return m_count % block_size == 0; + return m_count % BLOCK_SIZE == 0; } /// The maximum number of bytes an entry will need in storage. @@ -97,12 +103,6 @@ class node_locations_t (m_data.size() + max_bytes_per_entry() >= m_data.capacity()); } - /** - * The block size used for internal blocks. The larger the block size - * the less memory is consumed but the more expensive the access is. - */ - static constexpr const std::size_t block_size = 32; - ordered_index_t m_index; std::string m_data; diff --git a/src/ordered-index.cpp b/src/ordered-index.cpp index 701d18883..7803f4a99 100644 --- a/src/ordered-index.cpp +++ b/src/ordered-index.cpp @@ -26,7 +26,7 @@ void ordered_index_t::add(osmid_t id, std::size_t offset) } m_ranges.emplace_back(id, offset, m_block_size); m_capacity += m_block_size; - if (m_block_size < max_block_size) { + if (m_block_size < MAX_BLOCK_SIZE) { m_block_size <<= 1U; } } diff --git a/src/ordered-index.hpp b/src/ordered-index.hpp index 47850c138..70790f014 100644 --- a/src/ordered-index.hpp +++ b/src/ordered-index.hpp @@ -185,7 +185,7 @@ class ordered_index_t std::pair get_internal(osmid_t id) const noexcept; - static constexpr std::size_t const max_block_size = 16UL * 1024UL * 1024UL; + static constexpr std::size_t const MAX_BLOCK_SIZE = 16UL * 1024UL * 1024UL; std::vector m_ranges; std::size_t m_block_size; diff --git a/src/output-flex.cpp b/src/output-flex.cpp index 31bb167fa..1e87b5d03 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -132,9 +132,9 @@ void push_osm_object_to_lua_stack(lua_State *lua_state, * timestamp, changeset, uid, user). For ways there are 2 more (is_closed, * nodes), for relations 1 more (members). */ - constexpr int const max_table_size = 10; + constexpr int const MAX_TABLE_SIZE = 10; - lua_createtable(lua_state, 0, max_table_size); + lua_createtable(lua_state, 0, MAX_TABLE_SIZE); luaX_add_table_int(lua_state, "id", object.id()); @@ -240,12 +240,12 @@ typename CONTAINER::value_type &get_from_idx_param(lua_State *lua_state, std::size_t get_nodes(middle_query_t const &middle, osmium::Way *way) { - constexpr std::size_t const max_missing_nodes = 100; + constexpr std::size_t const MAX_MISSING_NODES = 100; static std::size_t count_missing_nodes = 0; auto const count = middle.nodes_get_list(&way->nodes()); - if (count_missing_nodes <= max_missing_nodes && + if (count_missing_nodes <= MAX_MISSING_NODES && count != way->nodes().size()) { util::string_joiner_t id_list{','}; for (auto const &nr : way->nodes()) { @@ -257,10 +257,10 @@ std::size_t get_nodes(middle_query_t const &middle, osmium::Way *way) log_debug("Missing nodes in way {}: {}", way->id(), id_list()); - if (count_missing_nodes > max_missing_nodes) { + if (count_missing_nodes > MAX_MISSING_NODES) { log_debug("Reported more than {} missing nodes, no further missing " "nodes will be reported!", - max_missing_nodes); + MAX_MISSING_NODES); } } diff --git a/src/pgsql.hpp b/src/pgsql.hpp index 01a0f617f..8b1a93322 100644 --- a/src/pgsql.hpp +++ b/src/pgsql.hpp @@ -318,10 +318,11 @@ class pg_conn_t // It needs to be large enough to hold all parameters without resizing // so that pointers into the strings in that vector remain valid // after new parameters have been added. - constexpr auto const total_buffers_needed = + constexpr auto const TOTAL_BUFFERS_NEEDED = (0 + ... + buffers_needed>()); + std::vector exec_params; - exec_params.reserve(total_buffers_needed); + exec_params.reserve(TOTAL_BUFFERS_NEEDED); std::array lengths = {0}; std::array bins = {0}; diff --git a/src/properties.cpp b/src/properties.cpp index b959c0726..b7872cc8c 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -19,7 +19,7 @@ namespace { -constexpr char const *const properties_table = "osm2pgsql_properties"; +constexpr char const *const PROPERTIES_TABLE = "osm2pgsql_properties"; } // anonymous namespace @@ -27,10 +27,10 @@ properties_t::properties_t(connection_params_t connection_params, std::string schema) : m_connection_params(std::move(connection_params)), m_schema(std::move(schema)), - m_has_properties_table(has_table(m_schema, properties_table)) + m_has_properties_table(has_table(m_schema, PROPERTIES_TABLE)) { assert(!m_schema.empty()); - log_debug("Found properties table '{}': {}.", properties_table, + log_debug("Found properties table '{}': {}.", PROPERTIES_TABLE, m_has_properties_table); } @@ -159,5 +159,5 @@ bool properties_t::load() std::string properties_t::table_name() const { - return qualified_name(m_schema, properties_table); + return qualified_name(m_schema, PROPERTIES_TABLE); } diff --git a/src/tagtransform-c.cpp b/src/tagtransform-c.cpp index 9c1e34153..27addf710 100644 --- a/src/tagtransform-c.cpp +++ b/src/tagtransform-c.cpp @@ -26,7 +26,7 @@ struct layers_type bool roads; }; -constexpr std::array const layers = { +constexpr std::array const LAYERS = { {{"proposed", 1, false}, {"construction", 2, false}, {"steps", 10, false}, {"cycleway", 10, false}, {"bridleway", 10, false}, {"footway", 10, false}, @@ -60,7 +60,7 @@ void add_z_order(taglist_t *tags, bool *roads) *roads = false; if (highway) { - for (auto const &layer : layers) { + for (auto const &layer : LAYERS) { if (*highway == layer.highway) { z_order += layer.offset; *roads = layer.roads; diff --git a/src/tagtransform-lua.cpp b/src/tagtransform-lua.cpp index efbab0651..b22c6d28f 100644 --- a/src/tagtransform-lua.cpp +++ b/src/tagtransform-lua.cpp @@ -24,10 +24,10 @@ lua_tagtransform_t::lua_tagtransform_t(std::string const *tag_transform_script, lua_tostring(lua_state(), -1)); } - check_lua_function_exists(node_func); - check_lua_function_exists(way_func); - check_lua_function_exists(rel_func); - check_lua_function_exists(rel_mem_func); + check_lua_function_exists(NODE_FUNC); + check_lua_function_exists(WAY_FUNC); + check_lua_function_exists(REL_FUNC); + check_lua_function_exists(REL_MEM_FUNC); } std::unique_ptr lua_tagtransform_t::clone() const @@ -86,13 +86,13 @@ bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, bool *polygon, { switch (o.type()) { case osmium::item_type::node: - lua_getglobal(lua_state(), node_func); + lua_getglobal(lua_state(), NODE_FUNC); break; case osmium::item_type::way: - lua_getglobal(lua_state(), way_func); + lua_getglobal(lua_state(), WAY_FUNC); break; case osmium::item_type::relation: - lua_getglobal(lua_state(), rel_func); + lua_getglobal(lua_state(), REL_FUNC); break; default: throw std::runtime_error{"Unknown OSM type."}; @@ -153,7 +153,7 @@ bool lua_tagtransform_t::filter_rel_member_tags( bool *roads, taglist_t *out_tags) { size_t const num_members = member_roles.size(); - lua_getglobal(lua_state(), rel_mem_func); + lua_getglobal(lua_state(), REL_MEM_FUNC); lua_newtable(lua_state()); /* relations key value table */ diff --git a/src/tagtransform-lua.hpp b/src/tagtransform-lua.hpp index c0d8e0e28..861417384 100644 --- a/src/tagtransform-lua.hpp +++ b/src/tagtransform-lua.hpp @@ -36,10 +36,10 @@ class lua_tagtransform_t : public tagtransform_t bool *roads, taglist_t *out_tags) override; private: - constexpr static char const *const node_func = "filter_tags_node"; - constexpr static char const *const way_func = "filter_tags_way"; - constexpr static char const *const rel_func = "filter_basic_tags_rel"; - constexpr static char const *const rel_mem_func = + constexpr static char const *const NODE_FUNC = "filter_tags_node"; + constexpr static char const *const WAY_FUNC = "filter_tags_way"; + constexpr static char const *const REL_FUNC = "filter_basic_tags_rel"; + constexpr static char const *const REL_MEM_FUNC = "filter_tags_relation_member"; void check_lua_function_exists(char const *func_name); diff --git a/src/thread-pool.cpp b/src/thread-pool.cpp index 7eadd5a04..aa8a430e9 100644 --- a/src/thread-pool.cpp +++ b/src/thread-pool.cpp @@ -27,7 +27,7 @@ std::chrono::microseconds task_result_t::wait() } thread_pool_t::thread_pool_t(unsigned int num_threads) -: m_work_queue(max_queue_size, "work"), m_joiner(&m_threads) +: m_work_queue(MAX_QUEUE_SIZE, "work"), m_joiner(&m_threads) { assert(num_threads > 0); try { diff --git a/src/thread-pool.hpp b/src/thread-pool.hpp index f65e07e6b..11d1afac9 100644 --- a/src/thread-pool.hpp +++ b/src/thread-pool.hpp @@ -151,7 +151,7 @@ class thread_pool_t }; // class thread_joiner - static constexpr std::size_t const max_queue_size = 32; + static constexpr std::size_t const MAX_QUEUE_SIZE = 32; osmium::thread::Queue m_work_queue; std::vector m_threads; diff --git a/src/tile.hpp b/src/tile.hpp index bcda0a1c3..c95a376e9 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -73,9 +73,9 @@ using quadkey_list_t = std::vector; class tile_t { public: - static constexpr double const earth_circumference = 40075016.68; - static constexpr double const half_earth_circumference = - earth_circumference / 2; + static constexpr double const EARTH_CIRCUMFERENCE = 40075016.68; + static constexpr double const HALF_EARTH_CIRCUMFERENCE = + EARTH_CIRCUMFERENCE / 2; /// Construct an invalid tile. tile_t() noexcept = default; @@ -90,7 +90,7 @@ class tile_t tile_t(uint32_t zoom, uint32_t x, uint32_t y) noexcept : m_x(x), m_y(y), m_zoom(zoom) { - assert(m_zoom < max_zoom); + assert(m_zoom < MAX_ZOOM); assert(x < (1UL << m_zoom)); assert(y < (1UL << m_zoom)); } @@ -113,64 +113,64 @@ class tile_t return m_y; } - bool valid() const noexcept { return m_zoom != invalid_zoom; } + bool valid() const noexcept { return m_zoom != INVALID_ZOOM; } /// The width/height of the tile in web mercator (EPSG:3857) coordinates. double extent() const noexcept { - return earth_circumference / static_cast(1UL << m_zoom); + return EARTH_CIRCUMFERENCE / static_cast(1UL << m_zoom); } /// Minimum X coordinate of this tile in web mercator (EPSG:3857) units. double xmin() const noexcept { - return -half_earth_circumference + m_x * extent(); + return -HALF_EARTH_CIRCUMFERENCE + m_x * extent(); } /// Maximum X coordinate of this tile in web mercator (EPSG:3857) units. double xmax() const noexcept { - return -half_earth_circumference + (m_x + 1) * extent(); + return -HALF_EARTH_CIRCUMFERENCE + (m_x + 1) * extent(); } /// Minimum Y coordinate of this tile in web mercator (EPSG:3857) units. double ymin() const noexcept { - return half_earth_circumference - (m_y + 1) * extent(); + return HALF_EARTH_CIRCUMFERENCE - (m_y + 1) * extent(); } /// Maximum Y coordinate of this tile in web mercator (EPSG:3857) units. double ymax() const noexcept { - return half_earth_circumference - m_y * extent(); + return HALF_EARTH_CIRCUMFERENCE - m_y * extent(); } /// Same as box(margin).min_x(). double xmin(double margin) const noexcept { - return std::clamp(xmin() - margin * extent(), -half_earth_circumference, - half_earth_circumference); + return std::clamp(xmin() - margin * extent(), -HALF_EARTH_CIRCUMFERENCE, + HALF_EARTH_CIRCUMFERENCE); } /// Same as box(margin).max_x(). double xmax(double margin) const noexcept { - return std::clamp(xmax() + margin * extent(), -half_earth_circumference, - half_earth_circumference); + return std::clamp(xmax() + margin * extent(), -HALF_EARTH_CIRCUMFERENCE, + HALF_EARTH_CIRCUMFERENCE); } /// Same as box(margin).min_y(). double ymin(double margin) const noexcept { - return std::clamp(ymin() - margin * extent(), -half_earth_circumference, - half_earth_circumference); + return std::clamp(ymin() - margin * extent(), -HALF_EARTH_CIRCUMFERENCE, + HALF_EARTH_CIRCUMFERENCE); } /// Same as box(margin).max_y(). double ymax(double margin) const noexcept { - return std::clamp(ymax() + margin * extent(), -half_earth_circumference, - half_earth_circumference); + return std::clamp(ymax() + margin * extent(), -HALF_EARTH_CIRCUMFERENCE, + HALF_EARTH_CIRCUMFERENCE); } /** @@ -187,8 +187,8 @@ class tile_t * the bounding box twice as wide and twice as heigh. * * The bounding box is clamped to the extent of the earth, so there will - * be no coordinates smaller than -half_earth_circumference or larger than - * half_earth_circumference. + * be no coordinates smaller than -HALF_EARTH_CIRCUMFERENCE or larger than + * HALF_EARTH_CIRCUMFERENCE. */ geom::box_t box(double margin) const noexcept { @@ -258,13 +258,14 @@ class tile_t static tile_t from_quadkey(quadkey_t quadkey, uint32_t zoom) noexcept; private: - static constexpr uint32_t const invalid_zoom = + static constexpr uint32_t const INVALID_ZOOM = std::numeric_limits::max(); - static constexpr uint32_t const max_zoom = 32; + + static constexpr uint32_t const MAX_ZOOM = 32; uint32_t m_x = 0; uint32_t m_y = 0; - uint32_t m_zoom = invalid_zoom; + uint32_t m_zoom = INVALID_ZOOM; }; // class tile_t /** diff --git a/src/util.hpp b/src/util.hpp index 2938f224c..3ea12f6af 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -27,21 +27,21 @@ namespace util { class double_to_buffer { - static constexpr std::size_t buffer_size = 32; + static constexpr std::size_t BUFFER_SIZE = 32; public: explicit double_to_buffer(double value) { auto const result = - fmt::format_to_n(m_buffer.begin(), buffer_size - 1, "{:g}", value); - assert(result.size < buffer_size); + fmt::format_to_n(m_buffer.begin(), BUFFER_SIZE - 1, "{:g}", value); + assert(result.size < BUFFER_SIZE); *result.out = '\0'; } char const *c_str() const noexcept { return m_buffer.data(); } private: - std::array m_buffer{}; + std::array m_buffer{}; }; /** diff --git a/src/wkb.cpp b/src/wkb.cpp index 519988dc3..facae2ad4 100644 --- a/src/wkb.cpp +++ b/src/wkb.cpp @@ -217,10 +217,10 @@ class make_ewkb_visitor write_point(&data, geom); } else { // 9 byte header plus one set of coordinates - constexpr const std::size_t size = 9 + 2 * 8; - data.reserve(size); + constexpr const std::size_t SIZE = 9 + 2 * 8; + data.reserve(SIZE); write_point(&data, geom, m_srid); - assert(data.size() == size); + assert(data.size() == SIZE); } return data; @@ -578,7 +578,7 @@ geom::geometry_t ewkb_to_geom(std::string_view wkb) namespace { -constexpr std::array const hex_table = { +constexpr std::array const HEX_TABLE = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -594,7 +594,7 @@ constexpr std::array const hex_table = { unsigned char decode_hex_char(char c) noexcept { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) - return hex_table[static_cast(static_cast(c))]; + return HEX_TABLE[static_cast(static_cast(c))]; } std::string decode_hex(std::string_view hex_string) diff --git a/tests/test-tile.cpp b/tests/test-tile.cpp index fe81d8158..e75d29e37 100644 --- a/tests/test-tile.cpp +++ b/tests/test-tile.cpp @@ -55,31 +55,31 @@ TEST_CASE("tile_t coordinates zoom=0", "[NoDB]") { tile_t const tile{0, 0, 0}; - REQUIRE(tile.xmin() == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.ymin() == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.xmax() == Approx(tile_t::half_earth_circumference)); - REQUIRE(tile.ymax() == Approx(tile_t::half_earth_circumference)); - REQUIRE(tile.box().min_x() == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.box().min_y() == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.box().max_x() == Approx(tile_t::half_earth_circumference)); - REQUIRE(tile.box().max_y() == Approx(tile_t::half_earth_circumference)); + REQUIRE(tile.xmin() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.ymin() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.xmax() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.ymax() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box().min_x() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box().min_y() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box().max_x() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box().max_y() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); // Bounding box with margin will not get larger, because it is always // clamped to the full extent of the map. - REQUIRE(tile.xmin(0.1) == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.ymin(0.1) == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.xmax(0.1) == Approx(tile_t::half_earth_circumference)); - REQUIRE(tile.ymax(0.1) == Approx(tile_t::half_earth_circumference)); - REQUIRE(tile.box(0.1).min_x() == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.box(0.1).min_y() == Approx(-tile_t::half_earth_circumference)); - REQUIRE(tile.box(0.1).max_x() == Approx(tile_t::half_earth_circumference)); - REQUIRE(tile.box(0.1).max_y() == Approx(tile_t::half_earth_circumference)); + REQUIRE(tile.xmin(0.1) == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.ymin(0.1) == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.xmax(0.1) == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.ymax(0.1) == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box(0.1).min_x() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box(0.1).min_y() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box(0.1).max_x() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); + REQUIRE(tile.box(0.1).max_y() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE)); REQUIRE(tile.center().x() == Approx(0.0)); REQUIRE(tile.center().y() == Approx(0.0)); REQUIRE(tile.center() == geom::point_t{0.0, 0.0}); - REQUIRE(tile.extent() == Approx(tile_t::earth_circumference)); + REQUIRE(tile.extent() == Approx(tile_t::EARTH_CIRCUMFERENCE)); geom::point_t const p{12345.6, 7891.0}; auto const tp = tile.to_tile_coords(p, 256); @@ -94,7 +94,7 @@ TEST_CASE("tile_t coordinates zoom=2", "[NoDB]") { tile_t const tile{2, 1, 2}; - double min = -tile_t::half_earth_circumference / 2; + double min = -tile_t::HALF_EARTH_CIRCUMFERENCE / 2; double max = 0.0; REQUIRE(tile.xmin() == Approx(min)); REQUIRE(tile.ymin() == Approx(min)); @@ -106,8 +106,8 @@ TEST_CASE("tile_t coordinates zoom=2", "[NoDB]") CHECK(tile.box().max_y() == tile.ymax()); // Bounding box of tile with 50% margin on all sides. - min -= tile_t::half_earth_circumference / 4; - max += tile_t::half_earth_circumference / 4; + min -= tile_t::HALF_EARTH_CIRCUMFERENCE / 4; + max += tile_t::HALF_EARTH_CIRCUMFERENCE / 4; CHECK(tile.xmin(0.5) == Approx(min)); CHECK(tile.ymin(0.5) == Approx(min)); CHECK(tile.xmax(0.5) == Approx(max)); @@ -117,13 +117,13 @@ TEST_CASE("tile_t coordinates zoom=2", "[NoDB]") CHECK(tile.box(0.5).max_x() == tile.xmax(0.5)); CHECK(tile.box(0.5).max_y() == tile.ymax(0.5)); - REQUIRE(tile.center().x() == Approx(-tile_t::half_earth_circumference / 4)); - REQUIRE(tile.center().y() == Approx(-tile_t::half_earth_circumference / 4)); + REQUIRE(tile.center().x() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE / 4)); + REQUIRE(tile.center().y() == Approx(-tile_t::HALF_EARTH_CIRCUMFERENCE / 4)); - REQUIRE(tile.extent() == Approx(tile_t::half_earth_circumference / 2)); + REQUIRE(tile.extent() == Approx(tile_t::HALF_EARTH_CIRCUMFERENCE / 2)); - geom::point_t const p{-tile_t::half_earth_circumference / 4, - -tile_t::half_earth_circumference / 8}; + geom::point_t const p{-tile_t::HALF_EARTH_CIRCUMFERENCE / 4, + -tile_t::HALF_EARTH_CIRCUMFERENCE / 8}; auto const tp = tile.to_tile_coords(p, 4096); REQUIRE(tp.x() == Approx(2048)); REQUIRE(tp.y() == Approx(2048 + 1024));