Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed some flaky tests dues to floating point errors #966

Merged
merged 1 commit into from
Oct 20, 2024
Merged
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
13 changes: 9 additions & 4 deletions src/modules/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,16 @@ std::tuple<std::string, std::string> nearbyGPSCoordinate(Precision precision, co
const auto radiusMetric = isMetric ? radius : radius * 1.60934;
const auto distanceInKm = number::decimal<double>(radiusMetric);

constexpr auto kmPerDegree = 40000 / 360; // The distance in km per degree for earth.
const auto distanceInDegree = distanceInKm / kmPerDegree;
constexpr auto kmPerDegreeLatitude = 110.574; // The distance in km per degree for earth's latitude.
const auto kmPerDegreeLongitude =
111.320 *
std::cos(std::get<0>(origin) / 180 * M_PI); // The distance in km per degree for a specific longitude in earth.

auto coordinateLatitude = std::get<0>(origin) + distanceInDegree * std::sin(angleRadians);
auto coordinateLongitude = std::get<1>(origin) + distanceInDegree * std::cos(angleRadians);
const auto distanceInDegreeLatitude = distanceInKm / kmPerDegreeLatitude;
const auto distanceInDegreeLongitude = distanceInKm / kmPerDegreeLongitude;

auto coordinateLatitude = std::get<0>(origin) + distanceInDegreeLatitude * std::sin(angleRadians);
auto coordinateLongitude = std::get<1>(origin) + distanceInDegreeLongitude * std::cos(angleRadians);

// Box the latitude [-90, 90]
coordinateLatitude = std::fmod(coordinateLatitude, 180.0);
Expand Down
Loading