diff --git a/drape_frontend/route_shape.cpp b/drape_frontend/route_shape.cpp index 67026fb671..1e7d502d23 100644 --- a/drape_frontend/route_shape.cpp +++ b/drape_frontend/route_shape.cpp @@ -62,11 +62,10 @@ void GetArrowTextureRegion(ref_ptr textures, textures->GetSymbolRegion("route-arrow", region); } -std::vector CalculatePoints(m2::PolylineD const & polyline, - double start, double end) +void CalculatePoints(m2::PolylineD const & polyline, double start, double end, + std::vector & result) { - std::vector result; - result.reserve(polyline.GetSize() / 4); + result.clear(); auto addIfNotExist = [&result](m2::PointD const & pnt) { @@ -74,12 +73,15 @@ std::vector CalculatePoints(m2::PolylineD const & polyline, result.push_back(pnt); }; - std::vector const & path = polyline.GetPoints(); + auto const & path = polyline.GetPoints(); double len = 0; bool started = false; - for (size_t i = 0; i + 1 < path.size(); i++) + for (size_t i = 1; i < path.size(); ++i) { - double const dist = (path[i + 1] - path[i]).Length(); + auto const & p1 = path[i - 1]; + auto const & p2 = path[i]; + auto const vec = p2 - p1; + double const dist = vec.Length(); if (dist == 0) continue; @@ -87,7 +89,7 @@ std::vector CalculatePoints(m2::PolylineD const & polyline, if (!started && start >= len && start <= l) { double const k = (start - len) / dist; - addIfNotExist(path[i] + (path[i + 1] - path[i]) * k); + addIfNotExist(p1 + vec * k); started = true; } if (!started) @@ -99,16 +101,15 @@ std::vector CalculatePoints(m2::PolylineD const & polyline, if (end >= len && end <= l) { double const k = (end - len) / dist; - addIfNotExist(path[i] + (path[i + 1] - path[i]) * k); + addIfNotExist(p1 + vec * k); break; } else { - addIfNotExist(path[i + 1]); + addIfNotExist(p2); } len = l; } - return result; } float SideByNormal(glsl::vec2 const & normal, bool isLeft) @@ -516,13 +517,14 @@ void RouteShape::CacheRouteArrows(ref_ptr context, // Generate arrow geometry. auto depth = static_cast(baseDepthIndex * rs::kDepthPerSubroute) + rs::kArrowsDepth; float const depthStep = (rs::kArrowsDepth - rs::kRouteDepth) / (1 + borders.size()); + + std::vector points; + points.reserve(polyline.GetSize() / 4); for (ArrowBorders const & b : borders) { depth -= depthStep; - std::vector points = rs::CalculatePoints(polyline, b.m_startDistance, b.m_endDistance); - ASSERT_LESS_OR_EQUAL(points.size(), polyline.GetSize(), ()); - PrepareArrowGeometry(points, routeArrowsData.m_pivot, region.GetTexRect(), depthStep, - depth, geometryData); + rs::CalculatePoints(polyline, b.m_startDistance, b.m_endDistance, points); + PrepareArrowGeometry(points, routeArrowsData.m_pivot, region.GetTexRect(), depthStep, depth, geometryData); } geometryData.m_boundingBox.Scale(kBoundingBoxScale);