diff --git a/routing/routing_helpers.cpp b/routing/routing_helpers.cpp index 309b01d523..0efc28a2db 100644 --- a/routing/routing_helpers.cpp +++ b/routing/routing_helpers.cpp @@ -4,6 +4,9 @@ #include "traffic/traffic_info.hpp" +#include "geometry/parametrized_segment.hpp" +#include "geometry/point2d.hpp" + #include "base/stl_helpers.hpp" #include @@ -160,4 +163,23 @@ Segment ConvertEdgeToSegment(NumMwmIds const & numMwmIds, Edge const & edge) return Segment(numMwmId, edge.GetFeatureId().m_index, edge.GetSegId(), edge.IsForward()); } + +bool PolylineInRect(IRoadGraph::JunctionVec const & junctions, m2::RectD const & rect) +{ + if (junctions.empty()) + return false; + + if (junctions.size() == 1) + return rect.IsPointInside(junctions.front().GetPoint()); + + auto const & center = rect.Center(); + for (size_t i = 1; i < junctions.size(); ++i) + { + m2::ParametrizedSegment segProj(junctions[i - 1].GetPoint(), junctions[i].GetPoint()); + m2::PointD const & proj = segProj.ClosestPointTo(center); + if (rect.IsPointInside(proj)) + return true; + } + return false; +} } // namespace routing diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index 9d15384582..0e5e09d5a3 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -2,6 +2,7 @@ #include "routing/directions_engine.hpp" #include "routing/index_road_graph.hpp" +#include "routing/road_graph.hpp" #include "routing/route.hpp" #include "routing/traffic_stash.hpp" @@ -11,6 +12,8 @@ #include "routing_common/car_model.hpp" #include "routing_common/pedestrian_model.hpp" +#include "geometry/rect2d.hpp" + #include "base/cancellable.hpp" #include @@ -50,6 +53,9 @@ void ReconstructRoute(IDirectionsEngine & engine, IndexRoadGraph const & graph, /// \returns Segment() if mwm of |edge| is not alive. Segment ConvertEdgeToSegment(NumMwmIds const & numMwmIds, Edge const & edge); +// @returns true if any part of polyline |junctions| lay in |rect| and false otherwise. +bool PolylineInRect(IRoadGraph::JunctionVec const & junctions, m2::RectD const & rect); + /// \brief Checks is edge connected with world graph. Function does BFS while it finds some number /// of edges, /// if graph ends before this number is reached then junction is assumed as not connected to the