diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-07-27 17:45:00 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-07-27 17:45:00 +0200 |
commit | 6cab322100f88be57872dfec8575b3ceda9f0248 (patch) | |
tree | 5ae8cc7e5b1d47237e0a8cb76f5a8524a233112b | |
parent | b69cf7243bb5c91f582cedbdc754b273052f501c (diff) |
another distance calculation fix for ring lines
Fixes #229
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 61c9927..c0ba2a9 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -13,7 +13,7 @@ use DateTime; use DateTime::Format::Strptime; use GIS::Distance; use JSON; -use List::MoreUtils qw(after_incl before_incl first_index); +use List::MoreUtils qw(after_incl before_incl first_index last_index); my %visibility_itoa = ( 100 => 'public', @@ -1270,7 +1270,11 @@ sub get_travel_distance { ) } @{$route_ref}; - my $route_end = first_index { + + # Here, we need to use last_index. In case of ring lines, the first index + # will not have sched_arr/rt_arr set, but we should not select it as route + # end... + my $route_end = last_index { ( ( $_->[1] and $_->[1] == $to_eva or $_->[0] eq $to ) and ( not( defined $_->[2]{sched_arr} or defined $_->[2]{rt_arr} ) @@ -1291,7 +1295,7 @@ sub get_travel_distance { } # Assumption: polyline entries are always [lat, lon] or [lat, lon, stop ID] - %seen = undef; + %seen = (); for my $entry ( @{$polyline_ref} ) { if ( $entry->[2] ) { $seen{ $entry->[2] } //= 1; |