Skip to content

Commit

Permalink
[drape] calculate spline length during the iteration
Browse files Browse the repository at this point in the history
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 <kirylkaveryn@gmail.com>
  • Loading branch information
kirylkaveryn authored and vng committed Oct 11, 2024
1 parent e5710e6 commit a009944
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
9 changes: 6 additions & 3 deletions drape_frontend/gps_track_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void GpsTrackRenderer::RenderTrack(ref_ptr<dp::GraphicsContext> context, ref_ptr
double const currentScaleGtoP = 1.0 / screen.GetScale();
double const radiusMercator = m_radius / currentScaleGtoP;
double const diameterMercator = 2.0 * radiusMercator;
double const step = diameterMercator + kDistanceScalar * diameterMercator;

// Update points' positions and colors.
ASSERT(!m_renderData.empty(), ());
Expand Down Expand Up @@ -231,15 +232,16 @@ void GpsTrackRenderer::RenderTrack(ref_ptr<dp::GraphicsContext> context, ref_ptr
{
m2::Spline::iterator it;
it.Attach(m_pointsSpline);
auto const fullLength = it.GetFullLength();
double lengthFromStart = 0.0;
while (!it.BeginAgain())
{
m2::PointD const pt = it.m_pos;
m2::RectD pointRect(pt.x - radiusMercator, pt.y - radiusMercator,
pt.x + radiusMercator, pt.y + radiusMercator);
if (screen.ClipRect().IsIntersect(pointRect))
{
dp::Color const color = CalculatePointColor(it.GetIndex(), pt,
it.GetLength(), it.GetFullLength());
dp::Color const color = CalculatePointColor(it.GetIndex(), pt, lengthFromStart, fullLength);
m2::PointD const convertedPt = MapShape::ConvertToLocal(pt, m_pivot, kShapeCoordScalar);
m_handlesCache[cacheIndex].first->SetPoint(m_handlesCache[cacheIndex].second,
convertedPt, m_radius, color);
Expand All @@ -254,7 +256,8 @@ void GpsTrackRenderer::RenderTrack(ref_ptr<dp::GraphicsContext> context, ref_ptr
return;
}
}
it.Advance(diameterMercator + kDistanceScalar * diameterMercator);
lengthFromStart += step;
it.Advance(step);
}

#ifdef GPS_TRACK_SHOW_RAW_POINTS
Expand Down
5 changes: 0 additions & 5 deletions geometry/spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ void Spline::iterator::Advance(double step)
AdvanceForward(step);
}

double Spline::iterator::GetLength() const
{
return std::accumulate(m_spl->m_length.begin(), m_spl->m_length.begin() + m_index, m_dist);
}

double Spline::iterator::GetFullLength() const
{
return m_spl->GetLength();
Expand Down
1 change: 0 additions & 1 deletion geometry/spline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Spline
void Attach(Spline const & spl);
void Advance(double step);
bool BeginAgain() const;
double GetLength() const;
double GetFullLength() const;

size_t GetIndex() const;
Expand Down

0 comments on commit a009944

Please sign in to comment.