MCPcopy Create free account
hub / github.com/comaps/comaps / FillProjections

Function FillProjections

libs/transit/world_feed/feed_helpers.cpp:89–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89void FillProjections(std::vector<m2::PointD> & polyline, size_t startIndex, size_t endIndex, m2::PointD const & point,
90 double distStopsM, Direction direction, std::vector<ProjectionData> & projections)
91{
92 CHECK_LESS_OR_EQUAL(startIndex, endIndex, ());
93
94 double distTravelledM = 0.0;
95 // Stop can't be further from its projection to line then |maxDistFromStopM|.
96 double constexpr maxDistFromStopM = 1000;
97
98 size_t const from = direction == Direction::Forward ? startIndex : endIndex;
99
100 auto const endCriterion = [&](size_t i) { return direction == Direction::Forward ? i < endIndex : i > startIndex; };
101
102 auto const move = [&](size_t & i)
103 {
104 direction == Direction::Forward ? ++i : --i;
105 CHECK_LESS_OR_EQUAL(i, polyline.size(), ());
106 };
107
108 for (size_t i = from; endCriterion(i); move(i))
109 {
110 auto const current = i;
111 auto const prev = direction == Direction::Forward ? i - 1 : i + 1;
112 auto const next = direction == Direction::Forward ? i + 1 : i - 1;
113
114 if (i != from)
115 distTravelledM += mercator::DistanceOnEarth(polyline[prev], polyline[current]);
116
117 auto proj =
118 GetProjection(polyline, current, direction, ProjectStopOnTrack(point, polyline[current], polyline[next]));
119 proj.m_distFromEnding = distTravelledM + mercator::DistanceOnEarth(polyline[current], proj.m_proj);
120
121 // The distance on the polyline between the projections of stops must not be less than the
122 // shortest possible distance between the stops themselves.
123 if (proj.m_distFromEnding < distStopsM)
124 continue;
125
126 if (proj.m_distFromPoint < maxDistFromStopM)
127 projections.emplace_back(proj);
128 }
129}
130
131std::pair<size_t, bool> PrepareNearestPointOnTrack(m2::PointD const & point,
132 std::optional<m2::PointD> const & prevPoint, size_t prevIndex,

Callers 1

Calls 5

GetProjectionFunction · 0.85
ProjectStopOnTrackFunction · 0.85
DistanceOnEarthFunction · 0.50
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected