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

Compute journey section length correctly when we don't have stop coords

TRIAS can still give us a valid path in that case, which allows for a
pretty accurate distance computation.
parent c9a103b3
Pipeline #80003 passed with stage
in 18 seconds
......@@ -50,8 +50,6 @@ public:
Platform departurePlatformLayout;
Vehicle arrivalVehicleLayout;
Platform arrivalPlatformLayout;
int estimatedDistance() const;
};
class JourneyPrivate : public QSharedData
......@@ -80,27 +78,6 @@ KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Platform, departurePlatformLayout
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Vehicle, arrivalVehicleLayout, setArrivalVehicleLayout)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Platform, arrivalPlatformLayout, setArrivalPlatformLayout)
int JourneySectionPrivate::estimatedDistance() const
{
assert(from.hasCoordinate() && to.hasCoordinate());
int d = 0;
float startLat = from.latitude();
float startLon = from.longitude();
for (const auto &stop : intermediateStops) {
if (!stop.stopPoint().hasCoordinate()) {
continue;
}
d += Location::distance(startLat, startLon, stop.stopPoint().latitude(), stop.stopPoint().longitude());
startLat = stop.stopPoint().latitude();
startLon = stop.stopPoint().longitude();
}
d += Location::distance(startLat, startLon, to.latitude(), to.longitude());
return std::max(d, path.distance());
}
bool JourneySection::hasExpectedDepartureTime() const
{
return d->expectedDepartureTime.isValid();
......@@ -137,10 +114,25 @@ int JourneySection::distance() const
if (d->mode == JourneySection::Waiting) {
return 0;
}
if (!d->from.hasCoordinate() || !d->to.hasCoordinate()) {
return d->distance;
int dist = 0;
if (d->from.hasCoordinate() && d->to.hasCoordinate()) {
float startLat = d->from.latitude();
float startLon = d->from.longitude();
for (const auto &stop : d->intermediateStops) {
if (!stop.stopPoint().hasCoordinate()) {
continue;
}
dist += Location::distance(startLat, startLon, stop.stopPoint().latitude(), stop.stopPoint().longitude());
startLat = stop.stopPoint().latitude();
startLon = stop.stopPoint().longitude();
}
dist += Location::distance(startLat, startLon, d->to.latitude(), d->to.longitude());
}
return std::max(d->estimatedDistance(), d->distance);
dist = std::max(dist, d->path.distance());
return std::max(dist, d->distance);
}
void JourneySection::setDistance(int value)
......
Markdown is supported
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