1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-19 05:33:02 +00:00

clang-tidy fixes

This commit is contained in:
Carles Fernandez 2023-03-17 13:51:01 +01:00
parent 1b2087944e
commit 18e5345669
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 9 additions and 14 deletions

View File

@ -22,13 +22,9 @@
#include <cstddef> #include <cstddef>
#include <limits> #include <limits>
#include <stdexcept> #include <stdexcept>
#include <utility>
Geohash::Geohash()
{
base32 = "0123456789bcdefghjkmnpqrstuvwxyz";
}
std::string Geohash::encode(double lat, double lon, int precision) const std::string Geohash::encode(double lat, double lon, int precision) const
{ {
// infer precision? // infer precision?
@ -113,7 +109,7 @@ std::string Geohash::encode(double lat, double lon, int precision) const
std::array<double, 2> Geohash::decode(std::string geohash) const std::array<double, 2> 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 latMin = bounds[0];
const double lonMin = bounds[1]; const double lonMin = bounds[1];
@ -126,8 +122,8 @@ std::array<double, 2> Geohash::decode(std::string geohash) const
// round to close to centre without excessive precision: ⌊2-log10(Δ°)⌋ decimal places // round to close to centre without excessive precision: ⌊2-log10(Δ°)⌋ decimal places
std::array<double, 2> latlon{}; std::array<double, 2> latlon{};
latlon[0] = std::floor(lat * std::pow(10, std::floor(2 - std::log10(latMax - latMin)))); 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 - std::log10(lonMax - lonMin)))); latlon[1] = std::floor(lon * std::pow(10, std::floor(2.0 - std::log10(lonMax - lonMin))));
return latlon; return latlon;
} }
@ -149,9 +145,8 @@ std::array<double, 4> Geohash::bounds(std::string geohash) const
double lonMin = -180.0; double lonMin = -180.0;
double lonMax = 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); int idx = base32.find(chr);
if (idx == -1) if (idx == -1)
{ {
@ -164,7 +159,7 @@ std::array<double, 4> Geohash::bounds(std::string geohash) const
if (evenBit) if (evenBit)
{ {
// longitude // longitude
double lonMid = (lonMin + lonMax) / 2; double lonMid = (lonMin + lonMax) / 2.0;
if (bitN == 1) if (bitN == 1)
{ {
lonMin = lonMid; lonMin = lonMid;
@ -177,7 +172,7 @@ std::array<double, 4> Geohash::bounds(std::string geohash) const
else else
{ {
// latitude // latitude
double latMid = (latMin + latMax) / 2; double latMid = (latMin + latMax) / 2.0;
if (bitN == 1) if (bitN == 1)
{ {
latMin = latMid; latMin = latMid;

View File

@ -34,7 +34,7 @@
class Geohash class Geohash
{ {
public: public:
Geohash(); Geohash() = default;
/** /**
* Encodes latitude/longitude to geohash, either to specified precision or * Encodes latitude/longitude to geohash, either to specified precision or
@ -66,7 +66,7 @@ private:
* Returns SW/NE latitude/longitude bounds of specified geohash. * Returns SW/NE latitude/longitude bounds of specified geohash.
*/ */
std::array<double, 4> bounds(std::string geohash) const; std::array<double, 4> bounds(std::string geohash) const;
std::string base32; std::string base32{"0123456789bcdefghjkmnpqrstuvwxyz"};
}; };
/** \} */ /** \} */