@@ -30,7 +30,7 @@ namespace osr {
30
30
31
31
constexpr auto const kMaxMatchingDistanceSquaredRatio = 9.0 ;
32
32
33
- #define trace (...)
33
+ #define trace (...)
34
34
35
35
struct connecting_way {
36
36
constexpr bool valid () const { return way_ != way_idx_t::invalid (); }
@@ -528,68 +528,73 @@ std::optional<path> route_bidirectional(ways const& w,
528
528
b.distance_lon_degrees_ ) /
529
529
kMaxMatchingDistanceSquaredRatio ;
530
530
531
- for (auto const [i, start] : utl::enumerate (from_match)) {
532
- if (b.max_reached_1_ && component_seen (w, from_match, i)) {
533
- continue ;
534
- }
535
- auto const start_way = start.way_ ;
536
- for (auto const * nc : {&start.left_ , &start.right_ }) {
537
- if (nc->valid () && nc->cost_ < max) {
538
- Profile::resolve_start_node (
539
- *w.r_ , start.way_ , nc->node_ , from.lvl_ , dir, [&](auto const node) {
540
- auto label = typename Profile::label{node, nc->cost_ };
541
- label.track (label, *w.r_ , start_way, node.get_node (), false );
542
- b.add_start (w, label, sharing);
543
- });
544
- }
545
- }
546
- if (b.pq1_ .empty ()) {
547
- continue ;
548
- }
549
- for (auto const [j, end] : utl::enumerate (to_match)) {
550
- if (w.r_ ->way_component_ [start.way_ ] != w.r_ ->way_component_ [end.way_ ]) {
551
- continue ;
552
- }
553
- if (b.max_reached_2_ && component_seen (w, to_match, j)) {
531
+ for (auto const accept_bad_max_matching_dist : {false , true }) {
532
+ for (auto const [i, start] : utl::enumerate (from_match)) {
533
+ if (b.max_reached_1_ && component_seen (w, from_match, i)) {
554
534
continue ;
555
535
}
556
- if (std::pow (end.dist_to_way_ , 2 ) > limit_squared_max_matching_distance) {
557
- break ;
558
- }
559
- auto const end_way = end.way_ ;
560
- for (auto const * nc : {&end.left_ , &end.right_ }) {
536
+ auto const start_way = start.way_ ;
537
+ for (auto const * nc : {&start.left_ , &start.right_ }) {
561
538
if (nc->valid () && nc->cost_ < max) {
562
539
Profile::resolve_start_node (
563
- *w.r_ , end_way , nc->node_ , to .lvl_ , opposite ( dir) ,
540
+ *w.r_ , start. way_ , nc->node_ , from .lvl_ , dir,
564
541
[&](auto const node) {
565
542
auto label = typename Profile::label{node, nc->cost_ };
566
- label.track (label, *w.r_ , end_way , node.get_node (), false );
567
- b.add_end (w, label, sharing);
543
+ label.track (label, *w.r_ , start_way , node.get_node (), false );
544
+ b.add_start (w, label, sharing);
568
545
});
569
546
}
570
547
}
571
- if (b.pq2_ .empty ()) {
548
+ if (b.pq1_ .empty ()) {
572
549
continue ;
573
550
}
574
- auto const should_continue =
575
- b.run (w, *w.r_ , max, blocked, sharing, elevations, dir);
576
-
577
- if (b.meet_point_1_ .get_node () == node_idx_t::invalid ()) {
578
- if (should_continue) {
551
+ for (auto const [j, end] : utl::enumerate (to_match)) {
552
+ if (w.r_ ->way_component_ [start.way_ ] !=
553
+ w.r_ ->way_component_ [end.way_ ]) {
579
554
continue ;
580
555
}
581
- return std::nullopt ;
582
- }
556
+ if (b.max_reached_2_ && component_seen (w, to_match, j)) {
557
+ continue ;
558
+ }
559
+ if (std::pow (end.dist_to_way_ , 2 ) >
560
+ limit_squared_max_matching_distance) {
561
+ break ;
562
+ }
563
+ auto const end_way = end.way_ ;
564
+ for (auto const * nc : {&end.left_ , &end.right_ }) {
565
+ if (nc->valid () && nc->cost_ < max) {
566
+ Profile::resolve_start_node (
567
+ *w.r_ , end_way, nc->node_ , to.lvl_ , opposite (dir),
568
+ [&](auto const node) {
569
+ auto label = typename Profile::label{node, nc->cost_ };
570
+ label.track (label, *w.r_ , end_way, node.get_node (), false );
571
+ b.add_end (w, label, sharing);
572
+ });
573
+ }
574
+ }
575
+ if (b.pq2_ .empty ()) {
576
+ continue ;
577
+ }
578
+ auto const should_continue =
579
+ b.run (w, *w.r_ , max, blocked, sharing, elevations, dir);
583
580
584
- auto const cost = b.get_cost_to_mp (b.meet_point_1_ , b.meet_point_2_ );
581
+ if (b.meet_point_1_ .get_node () == node_idx_t::invalid ()) {
582
+ if (should_continue) {
583
+ continue ;
584
+ }
585
+ return std::nullopt ;
586
+ }
587
+
588
+ auto const cost = b.get_cost_to_mp (b.meet_point_1_ , b.meet_point_2_ );
585
589
586
- return reconstruct_bi (w, l, blocked, sharing, elevations, b, from, to,
587
- start, end, cost, dir);
590
+ return reconstruct_bi (w, l, blocked, sharing, elevations, b, from, to,
591
+ start, end, cost, dir);
592
+ }
593
+ b.pq1_ .clear ();
594
+ b.pq2_ .clear ();
595
+ b.cost2_ .clear ();
596
+ b.max_reached_2_ = false ;
588
597
}
589
- b.pq1_ .clear ();
590
- b.pq2_ .clear ();
591
- b.cost2_ .clear ();
592
- b.max_reached_2_ = false ;
593
598
}
594
599
return std::nullopt ;
595
600
}
0 commit comments