Skip to content

Commit a009944

Browse files
kirylkaverynvng
authored andcommitted
[drape] calculate spline length during the iteration
during the `CalculatePointColor` the `GetLength` is called on the every iteration and it should returns the value as fast as possible. The previous solution with `accumulate` slows down the track rendering performance a lot. Signed-off-by: Kiryl Kaveryn <[email protected]>
1 parent e5710e6 commit a009944

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

drape_frontend/gps_track_renderer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void GpsTrackRenderer::RenderTrack(ref_ptr<dp::GraphicsContext> context, ref_ptr
204204
double const currentScaleGtoP = 1.0 / screen.GetScale();
205205
double const radiusMercator = m_radius / currentScaleGtoP;
206206
double const diameterMercator = 2.0 * radiusMercator;
207+
double const step = diameterMercator + kDistanceScalar * diameterMercator;
207208

208209
// Update points' positions and colors.
209210
ASSERT(!m_renderData.empty(), ());
@@ -231,15 +232,16 @@ void GpsTrackRenderer::RenderTrack(ref_ptr<dp::GraphicsContext> context, ref_ptr
231232
{
232233
m2::Spline::iterator it;
233234
it.Attach(m_pointsSpline);
235+
auto const fullLength = it.GetFullLength();
236+
double lengthFromStart = 0.0;
234237
while (!it.BeginAgain())
235238
{
236239
m2::PointD const pt = it.m_pos;
237240
m2::RectD pointRect(pt.x - radiusMercator, pt.y - radiusMercator,
238241
pt.x + radiusMercator, pt.y + radiusMercator);
239242
if (screen.ClipRect().IsIntersect(pointRect))
240243
{
241-
dp::Color const color = CalculatePointColor(it.GetIndex(), pt,
242-
it.GetLength(), it.GetFullLength());
244+
dp::Color const color = CalculatePointColor(it.GetIndex(), pt, lengthFromStart, fullLength);
243245
m2::PointD const convertedPt = MapShape::ConvertToLocal(pt, m_pivot, kShapeCoordScalar);
244246
m_handlesCache[cacheIndex].first->SetPoint(m_handlesCache[cacheIndex].second,
245247
convertedPt, m_radius, color);
@@ -254,7 +256,8 @@ void GpsTrackRenderer::RenderTrack(ref_ptr<dp::GraphicsContext> context, ref_ptr
254256
return;
255257
}
256258
}
257-
it.Advance(diameterMercator + kDistanceScalar * diameterMercator);
259+
lengthFromStart += step;
260+
it.Advance(step);
258261
}
259262

260263
#ifdef GPS_TRACK_SHOW_RAW_POINTS

geometry/spline.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ void Spline::iterator::Advance(double step)
174174
AdvanceForward(step);
175175
}
176176

177-
double Spline::iterator::GetLength() const
178-
{
179-
return std::accumulate(m_spl->m_length.begin(), m_spl->m_length.begin() + m_index, m_dist);
180-
}
181-
182177
double Spline::iterator::GetFullLength() const
183178
{
184179
return m_spl->GetLength();

geometry/spline.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Spline
2222
void Attach(Spline const & spl);
2323
void Advance(double step);
2424
bool BeginAgain() const;
25-
double GetLength() const;
2625
double GetFullLength() const;
2726

2827
size_t GetIndex() const;

0 commit comments

Comments
 (0)