From 18e5345669a33ca60adce26ca784c66e3377173a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 17 Mar 2023 13:51:01 +0100 Subject: [PATCH] clang-tidy fixes --- src/algorithms/PVT/libs/geohash.cc | 19 +++++++------------ src/algorithms/PVT/libs/geohash.h | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/algorithms/PVT/libs/geohash.cc b/src/algorithms/PVT/libs/geohash.cc index 3682a7e0e..0021a752d 100644 --- a/src/algorithms/PVT/libs/geohash.cc +++ b/src/algorithms/PVT/libs/geohash.cc @@ -22,13 +22,9 @@ #include #include #include +#include -Geohash::Geohash() -{ - base32 = "0123456789bcdefghjkmnpqrstuvwxyz"; -} - std::string Geohash::encode(double lat, double lon, int precision) const { // infer precision? @@ -113,7 +109,7 @@ std::string Geohash::encode(double lat, double lon, int precision) const std::array Geohash::decode(std::string geohash) const { - const auto bounds = Geohash::bounds(geohash); + const auto bounds = Geohash::bounds(std::move(geohash)); const double latMin = bounds[0]; const double lonMin = bounds[1]; @@ -126,8 +122,8 @@ std::array Geohash::decode(std::string geohash) const // round to close to centre without excessive precision: ⌊2-log10(Δ°)⌋ decimal places std::array latlon{}; - latlon[0] = std::floor(lat * std::pow(10, std::floor(2 - std::log10(latMax - latMin)))); - latlon[1] = std::floor(lon * std::pow(10, std::floor(2 - std::log10(lonMax - lonMin)))); + latlon[0] = std::floor(lat * std::pow(10, std::floor(2.0 - std::log10(latMax - latMin)))); + latlon[1] = std::floor(lon * std::pow(10, std::floor(2.0 - std::log10(lonMax - lonMin)))); return latlon; } @@ -149,9 +145,8 @@ std::array Geohash::bounds(std::string geohash) const double lonMin = -180.0; double lonMax = 180.0; - for (size_t i = 0; i < geohash.length(); i++) + for (char chr : geohash) { - char chr = geohash[i]; int idx = base32.find(chr); if (idx == -1) { @@ -164,7 +159,7 @@ std::array Geohash::bounds(std::string geohash) const if (evenBit) { // longitude - double lonMid = (lonMin + lonMax) / 2; + double lonMid = (lonMin + lonMax) / 2.0; if (bitN == 1) { lonMin = lonMid; @@ -177,7 +172,7 @@ std::array Geohash::bounds(std::string geohash) const else { // latitude - double latMid = (latMin + latMax) / 2; + double latMid = (latMin + latMax) / 2.0; if (bitN == 1) { latMin = latMid; diff --git a/src/algorithms/PVT/libs/geohash.h b/src/algorithms/PVT/libs/geohash.h index 019dbaea5..a97015f44 100644 --- a/src/algorithms/PVT/libs/geohash.h +++ b/src/algorithms/PVT/libs/geohash.h @@ -34,7 +34,7 @@ class Geohash { public: - Geohash(); + Geohash() = default; /** * Encodes latitude/longitude to geohash, either to specified precision or @@ -66,7 +66,7 @@ private: * Returns SW/NE latitude/longitude bounds of specified geohash. */ std::array bounds(std::string geohash) const; - std::string base32; + std::string base32{"0123456789bcdefghjkmnpqrstuvwxyz"}; }; /** \} */