From b0d3664b35f6288c2b0bfb273b1430a87d361510 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 14 Mar 2021 20:57:06 +0100 Subject: map: handle arrival-only and departure-only stops --- lib/DBInfoscreen/Controller/Map.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm index b55afe0..b4c9134 100644 --- a/lib/DBInfoscreen/Controller/Map.pm +++ b/lib/DBInfoscreen/Controller/Map.pm @@ -1,4 +1,5 @@ package DBInfoscreen::Controller::Map; + # Copyright (C) 2011-2020 Daniel Friesel # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -138,8 +139,8 @@ sub estimate_train_positions { my $now = $opt{now}; - my $from_dt = $opt{from}{dep}; - my $to_dt = $opt{to}{arr}; + my $from_dt = $opt{from}{dep} // $opt{from}{arr}; + my $to_dt = $opt{to}{arr} // $opt{to}{dep}; my $from_name = $opt{from}{name}; my $to_name = $opt{to}{name}; my $features = $opt{features}; @@ -242,10 +243,10 @@ sub estimate_train_positions2 { my $next_stop; for my $i ( 1 .. $#route ) { - if ( $route[$i]{arr} - and $route[ $i - 1 ]{dep} - and $now > $route[ $i - 1 ]{dep} - and $now < $route[$i]{arr} ) + if ( ( $route[$i]{arr} // $route[$i]{dep} ) + and ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) + and $now > ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) + and $now < ( $route[$i]{arr} // $route[$i]{dep} ) ) { # (current position, future positons...) in 2 second steps @@ -262,7 +263,9 @@ sub estimate_train_positions2 { }; last; } - if ( $route[ $i - 1 ]{dep} and $now <= $route[ $i - 1 ]{dep} ) { + if ( ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) + and $now <= ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) ) + { @train_positions = ( [ $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon} ] ); $next_stop = { -- cgit v1.2.3