Fix formatting

This commit is contained in:
Dennis Luxen 2022-12-10 20:01:16 +01:00
parent 1215062e4c
commit 612ca82a06
2 changed files with 31 additions and 33 deletions

View File

@ -7,31 +7,30 @@
#include <tuple> #include <tuple>
#include <utility> #include <utility>
namespace mapbox { namespace mapbox
{
namespace geometry { namespace geometry
template <typename T> {
struct point template <typename T> struct point
{ {
using coordinate_type = T; using coordinate_type = T;
constexpr point() constexpr point() : x(), y() {}
: x(), y() constexpr point(T x_, T y_) : x(x_), y(y_) {}
{}
constexpr point(T x_, T y_)
: x(x_), y(y_)
{}
T x; T x;
T y; T y;
}; };
} } // namespace geometry
namespace cheap_ruler { namespace cheap_ruler
{
using point = geometry::point<double>; using point = geometry::point<double>;
class CheapRuler { class CheapRuler
{
// Values that define WGS84 ellipsoid model of the Earth // Values that define WGS84 ellipsoid model of the Earth
static constexpr double RE = 6378.137; // equatorial radius static constexpr double RE = 6378.137; // equatorial radius
@ -41,7 +40,8 @@ class CheapRuler {
static constexpr double RAD = M_PI / 180.0; static constexpr double RAD = M_PI / 180.0;
public: public:
explicit CheapRuler(double latitude) { explicit CheapRuler(double latitude)
{
// Curvature formulas from https://en.wikipedia.org/wiki/Earth_radius#Meridional // Curvature formulas from https://en.wikipedia.org/wiki/Earth_radius#Meridional
double mul = RAD * RE * 1000; double mul = RAD * RE * 1000;
double coslat = std::cos(latitude * RAD); double coslat = std::cos(latitude * RAD);
@ -53,7 +53,8 @@ public:
ky = mul * w * w2 * (1 - E2); // based on meridonal radius of curvature ky = mul * w * w2 * (1 - E2); // based on meridonal radius of curvature
} }
double squareDistance(point a, point b) const { double squareDistance(point a, point b) const
{
auto dx = longDiff(a.x, b.x) * kx; auto dx = longDiff(a.x, b.x) * kx;
auto dy = (a.y - b.y) * ky; auto dy = (a.y - b.y) * ky;
return dx * dx + dy * dy; return dx * dx + dy * dy;
@ -62,14 +63,13 @@ public:
// //
// Given two points of the form [x = longitude, y = latitude], returns the distance. // Given two points of the form [x = longitude, y = latitude], returns the distance.
// //
double distance(point a, point b) const { double distance(point a, point b) const { return std::sqrt(squareDistance(a, b)); }
return std::sqrt(squareDistance(a, b));
}
// //
// Returns the bearing between two points in angles. // Returns the bearing between two points in angles.
// //
double bearing(point a, point b) const { double bearing(point a, point b) const
{
auto dx = longDiff(b.x, a.x) * kx; auto dx = longDiff(b.x, a.x) * kx;
auto dy = (b.y - a.y) * ky; auto dy = (b.y - a.y) * ky;
@ -79,9 +79,7 @@ public:
private: private:
double ky; double ky;
double kx; double kx;
static double longDiff(double a, double b) { static double longDiff(double a, double b) { return std::remainder(a - b, 360); }
return std::remainder(a - b, 360);
}
}; };
} // namespace cheap_ruler } // namespace cheap_ruler

View File

@ -30,8 +30,8 @@ class CheapRulerContainer
{ {
for (int n = 0; n < number_of_rulers; n++) for (int n = 0; n < number_of_rulers; n++)
{ {
cheap_ruler_cache[n] = mapbox::cheap_ruler::CheapRuler( cheap_ruler_cache[n] =
step * (n + 0.5) / COORDINATE_PRECISION); mapbox::cheap_ruler::CheapRuler(step * (n + 0.5) / COORDINATE_PRECISION);
} }
}; };