Commit cae91562 authored by Volker Krause's avatar Volker Krause
Browse files

Don't truncate Location::distance results to meters

When doing computations on detailed navigation paths the errors introduced
by this actually accumulate to relevant sizes.
parent 13e4f8c9
......@@ -3,7 +3,7 @@
"sections": [
{
"disruptionEffect": "NoService",
"distance": 163558,
"distance": 163559,
"from": {
"identifier": {
"unit-test": "8011113"
......
......@@ -274,7 +274,7 @@ static Path parseDirections(Path &&fullPath, const QJsonArray &directions)
int nextSecStart = prevSecStart;
for (; nextSecStart < poly.size(); ++nextSecStart) {
if (Location::distance(lat, lon, poly[nextSecStart].y(), poly[nextSecStart].x()) == 0) {
if (Location::distance(lat, lon, poly[nextSecStart].y(), poly[nextSecStart].x()) < 1.0f) {
break;
}
}
......
......@@ -421,7 +421,7 @@ Location Location::merge(const Location &lhs, const Location &rhs)
}
// see https://en.wikipedia.org/wiki/Haversine_formula
int Location::distance(float lat1, float lon1, float lat2, float lon2)
float Location::distance(float lat1, float lon1, float lat2, float lon2)
{
const auto degToRad = M_PI / 180.0;
const auto earthRadius = 6371000.0; // in meters
......@@ -433,10 +433,10 @@ int Location::distance(float lat1, float lon1, float lat2, float lon2)
return 2.0 * earthRadius * atan2(sqrt(a), sqrt(1.0 - a));
}
int Location::distance(const Location &lhs, const Location &rhs)
float Location::distance(const Location &lhs, const Location &rhs)
{
if (!lhs.hasCoordinate() || !rhs.hasCoordinate()) {
return std::numeric_limits<int>::max();
return std::numeric_limits<float>::max();
}
return Location::distance(lhs.latitude(), lhs.longitude(), rhs.latitude(), rhs.longitude());
}
......
......@@ -105,11 +105,11 @@ public:
static Location merge(const Location &lhs, const Location &rhs);
/** Compute the distance between two geo coordinates, in meters. */
static int distance(float lat1, float lon1, float lat2, float lon2);
static float distance(float lat1, float lon1, float lat2, float lon2);
/** Computes the distance in meters between two locations.
* Returns MAX_INT if one of the arguments has no coordinates set.
*/
static int distance(const Location &lhs, const Location &rhs);
static float distance(const Location &lhs, const Location &rhs);
RentalVehicleStation rentalVehicleStation() const;
[[deprecated("use setData instead")]] void setRentalVehicleStation(const RentalVehicleStation &dock);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment