Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,6 @@ include_directories(SYSTEM ${RAPIDJSON_INCLUDE_DIR})
set(MICROTAR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src")
include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})

set(MBXGEOM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/geometry.hpp-0.9.2/include")
include_directories(SYSTEM ${MBXGEOM_INCLUDE_DIR})
set(CHEAPRULER_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cheap-ruler-cpp-2778eb8/include")
include_directories(SYSTEM ${CHEAPRULER_INCLUDE_DIR})

add_library(MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src/microtar.c")
set_property(TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON)
target_no_warning(MICROTAR unused-variable)
Expand Down
86 changes: 86 additions & 0 deletions include/util/cheap_ruler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

#include <cassert>
#include <cmath>
#include <cstdint>
#include <limits>
#include <tuple>
#include <utility>

namespace mapbox
{

namespace geometry
{
template <typename T> struct point
{
using coordinate_type = T;

constexpr point() : x(), y() {}
constexpr point(T x_, T y_) : x(x_), y(y_) {}

T x;
T y;
};
} // namespace geometry

namespace cheap_ruler
{

using point = geometry::point<double>;

class CheapRuler
{

// Values that define WGS84 ellipsoid model of the Earth
static constexpr double RE = 6378.137; // equatorial radius
static constexpr double FE = 1.0 / 298.257223563; // flattening

static constexpr double E2 = FE * (2 - FE);
static constexpr double RAD = M_PI / 180.0;

public:
explicit CheapRuler(double latitude)
{
// Curvature formulas from https://en.wikipedia.org/wiki/Earth_radius#Meridional
double mul = RAD * RE * 1000;
double coslat = std::cos(latitude * RAD);
double w2 = 1 / (1 - E2 * (1 - coslat * coslat));
double w = std::sqrt(w2);

// multipliers for converting longitude and latitude degrees into distance
kx = mul * w * coslat; // based on normal radius of curvature
ky = mul * w * w2 * (1 - E2); // based on meridonal radius of curvature
}

double squareDistance(point a, point b) const
{
auto dx = longDiff(a.x, b.x) * kx;
auto dy = (a.y - b.y) * ky;
return dx * dx + dy * dy;
}

//
// Given two points of the form [x = longitude, y = latitude], returns the distance.
//
double distance(point a, point b) const { return std::sqrt(squareDistance(a, b)); }

//
// Returns the bearing between two points in angles.
//
double bearing(point a, point b) const
{
auto dx = longDiff(b.x, a.x) * kx;
auto dy = (b.y - a.y) * ky;

return std::atan2(dx, dy) / RAD;
}

private:
double ky;
double kx;
static double longDiff(double a, double b) { return std::remainder(a - b, 360); }
};

} // namespace cheap_ruler
} // namespace mapbox
7 changes: 3 additions & 4 deletions src/util/coordinate_calculation.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "util/coordinate_calculation.hpp"
#include "util/cheap_ruler.hpp"
#include "util/coordinate.hpp"
#include "util/trigonometry_table.hpp"
#include "util/web_mercator.hpp"

#include <boost/assert.hpp>

#include <mapbox/cheap_ruler.hpp>

#include <algorithm>
#include <iterator>
#include <limits>
Expand All @@ -31,8 +30,8 @@ class CheapRulerContainer
{
for (int n = 0; n < number_of_rulers; n++)
{
cheap_ruler_cache[n] = mapbox::cheap_ruler::CheapRuler(
step * (n + 0.5) / COORDINATE_PRECISION, mapbox::cheap_ruler::CheapRuler::Meters);
cheap_ruler_cache[n] =
mapbox::cheap_ruler::CheapRuler(step * (n + 0.5) / COORDINATE_PRECISION);
}
};

Expand Down
18 changes: 0 additions & 18 deletions third_party/cheap-ruler-cpp-2778eb8/.clang-format

This file was deleted.

2 changes: 0 additions & 2 deletions third_party/cheap-ruler-cpp-2778eb8/.gitignore

This file was deleted.

25 changes: 0 additions & 25 deletions third_party/cheap-ruler-cpp-2778eb8/.travis.yml

This file was deleted.

27 changes: 0 additions & 27 deletions third_party/cheap-ruler-cpp-2778eb8/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions third_party/cheap-ruler-cpp-2778eb8/LICENSE

This file was deleted.

Loading