diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index fbc49db1f4..7c1bb15f8d 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -185,12 +185,13 @@ m2::PointF GetOffset(CaptionDefProto const * capRule) } // namespace -BaseApplyFeature::BaseApplyFeature(ref_ptr drawer, FeatureID const & id, +BaseApplyFeature::BaseApplyFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & caption) - : m_drawer(drawer) + : m_insertShape(insertShape) , m_id(id) , m_captions(caption) { + ASSERT(m_insertShape != nullptr, ()); } void BaseApplyFeature::ExtractCaptionParams(CaptionDefProto const * primaryProto, @@ -220,9 +221,9 @@ void BaseApplyFeature::ExtractCaptionParams(CaptionDefProto const * primaryProto // ============================================= // -ApplyPointFeature::ApplyPointFeature(ref_ptr drawer, FeatureID const & id, +ApplyPointFeature::ApplyPointFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions) - : TBase(drawer, id, captions) + : TBase(insertShape, id, captions) , m_hasPoint(false) , m_symbolDepth(dp::minDepth) , m_circleDepth(dp::minDepth) @@ -251,7 +252,7 @@ void ApplyPointFeature::ProcessRule(Stylist::TRuleWrapper const & rule) TextViewParams params; ExtractCaptionParams(capRule, pRule->GetCaption(1), depth, params); if(!params.m_primaryText.empty() || !params.m_secondaryText.empty()) - m_drawer->InsertShape(make_unique_dp(m_centerPoint, params)); + m_insertShape(make_unique_dp(m_centerPoint, params)); } SymbolRuleProto const * symRule = pRule->GetSymbol(); @@ -281,22 +282,22 @@ void ApplyPointFeature::Finish() params.m_depth = m_circleDepth; params.m_color = ToDrapeColor(m_circleRule->color()); params.m_radius = m_circleRule->radius(); - m_drawer->InsertShape(make_unique_dp(m_centerPoint, params)); + m_insertShape(make_unique_dp(m_centerPoint, params)); } else if (m_symbolRule) { PoiSymbolViewParams params(m_id); params.m_depth = m_symbolDepth; params.m_symbolName = m_symbolRule->name(); - m_drawer->InsertShape(make_unique_dp(m_centerPoint, params)); + m_insertShape(make_unique_dp(m_centerPoint, params)); } } // ============================================= // -ApplyAreaFeature::ApplyAreaFeature(ref_ptr drawer, FeatureID const & id, +ApplyAreaFeature::ApplyAreaFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions) - : TBase(drawer, id, captions) + : TBase(insertShape, id, captions) { } @@ -326,7 +327,7 @@ void ApplyAreaFeature::ProcessRule(Stylist::TRuleWrapper const & rule) AreaViewParams params; params.m_depth = depth; params.m_color = ToDrapeColor(areaRule->color()); - m_drawer->InsertShape(make_unique_dp(move(m_triangles), params)); + m_insertShape(make_unique_dp(move(m_triangles), params)); } else TBase::ProcessRule(rule); @@ -334,12 +335,13 @@ void ApplyAreaFeature::ProcessRule(Stylist::TRuleWrapper const & rule) // ============================================= // -ApplyLineFeature::ApplyLineFeature(ref_ptr drawer, FeatureID const & id, +ApplyLineFeature::ApplyLineFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions, - double currentScaleGtoP, size_t pointsCount) - : TBase(drawer, id, captions) + double currentScaleGtoP, bool simplify, size_t pointsCount) + : TBase(insertShape, id, captions) , m_currentScaleGtoP(currentScaleGtoP) , m_sqrScale(math::sqr(m_currentScaleGtoP)) + , m_simplify(simplify) , m_initialPointsCount(pointsCount) #ifdef CALC_FILTERED_POINTS , m_readedCount(0) @@ -408,7 +410,7 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) params.m_textFont = fontDecl; params.m_baseGtoPScale = m_currentScaleGtoP; - m_drawer->InsertShape(make_unique_dp(m_spline, params)); + m_insertShape(make_unique_dp(m_spline, params)); } if (pLineRule != NULL) @@ -424,7 +426,7 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) params.m_step = symRule.step() * mainScale; params.m_baseGtoPScale = m_currentScaleGtoP; - m_drawer->InsertShape(make_unique_dp(m_spline, params)); + m_insertShape(make_unique_dp(m_spline, params)); } else { @@ -432,7 +434,7 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) Extract(pLineRule, params); params.m_depth = depth; params.m_baseGtoPScale = m_currentScaleGtoP; - m_drawer->InsertShape(make_unique_dp(m_spline, params)); + m_insertShape(make_unique_dp(m_spline, params)); } } } @@ -469,7 +471,7 @@ void ApplyLineFeature::Finish() m2::Spline::iterator it = m_spline.CreateIterator(); while (!it.BeginAgain()) { - m_drawer->InsertShape(make_unique_dp(it.m_pos, viewParams)); + m_insertShape(make_unique_dp(it.m_pos, viewParams)); it.Advance(splineStep); } } diff --git a/drape_frontend/apply_feature_functors.hpp b/drape_frontend/apply_feature_functors.hpp index 8f4028e4c3..13fcb8a693 100644 --- a/drape_frontend/apply_feature_functors.hpp +++ b/drape_frontend/apply_feature_functors.hpp @@ -20,12 +20,14 @@ namespace df { struct TextViewParams; -class RuleDrawer; +class MapShape; + +using TInsertShapeFn = function && shape)>; class BaseApplyFeature { public: - BaseApplyFeature(ref_ptr drawer, FeatureID const & id, + BaseApplyFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions); virtual ~BaseApplyFeature() {} @@ -36,7 +38,7 @@ protected: double depth, TextViewParams & params) const; - ref_ptr m_drawer; + TInsertShapeFn m_insertShape; FeatureID m_id; CaptionDescription const & m_captions; }; @@ -45,7 +47,7 @@ class ApplyPointFeature : public BaseApplyFeature { typedef BaseApplyFeature TBase; public: - ApplyPointFeature(ref_ptr drawer, FeatureID const & id, + ApplyPointFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions); void operator()(m2::PointD const & point); @@ -65,7 +67,7 @@ class ApplyAreaFeature : public ApplyPointFeature { typedef ApplyPointFeature TBase; public: - ApplyAreaFeature(ref_ptr drawer, FeatureID const & id, + ApplyAreaFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions); using TBase::operator (); @@ -81,7 +83,7 @@ class ApplyLineFeature : public BaseApplyFeature { typedef BaseApplyFeature TBase; public: - ApplyLineFeature(ref_ptr drawer, FeatureID const & id, + ApplyLineFeature(TInsertShapeFn const & insertShape, FeatureID const & id, CaptionDescription const & captions, double currentScaleGtoP, bool simplify, size_t pointsCount); diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 8d5287cbbd..efd1584912 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -28,11 +28,6 @@ RuleDrawer::RuleDrawer(TDrawerCallback const & fn, ref_ptr contex m_currentScaleGtoP = 1.0f / m_geometryConvertor.GetScale(); } -void RuleDrawer::InsertShape(drape_ptr && shape) -{ - m_mapShapes.push_back(move(shape)); -} - void RuleDrawer::operator()(FeatureType const & f) { Stylist s; @@ -56,9 +51,14 @@ void RuleDrawer::operator()(FeatureType const & f) int zoomLevel = m_context->GetTileKey().m_zoomLevel; + auto insertShape = [this](drape_ptr && shape) + { + m_mapShapes.push_back(move(shape)); + }; + if (s.AreaStyleExists()) { - ApplyAreaFeature apply(make_ref(this), f.GetID(), s.GetCaptionDescription()); + ApplyAreaFeature apply(insertShape, f.GetID(), s.GetCaptionDescription()); f.ForEachTriangleRef(apply, zoomLevel); if (s.PointStyleExists()) @@ -69,8 +69,8 @@ void RuleDrawer::operator()(FeatureType const & f) } else if (s.LineStyleExists()) { - ApplyLineFeature apply(m_context, f.GetID(), s.GetCaptionDescription(), - m_currentScaleGtoP, zoomLevel >= SIMPLIFY_BOTTOM && zoomLevel <= SIMPLIFY_TOP, f.GetPointsCount()); + ApplyLineFeature apply(insertShape, f.GetID(), s.GetCaptionDescription(), m_currentScaleGtoP, + zoomLevel >= SIMPLIFY_BOTTOM && zoomLevel <= SIMPLIFY_TOP, f.GetPointsCount()); f.ForEachPointRef(apply, zoomLevel); if (apply.HasGeometry()) @@ -80,7 +80,7 @@ void RuleDrawer::operator()(FeatureType const & f) else { ASSERT(s.PointStyleExists(), ()); - ApplyPointFeature apply(make_ref(this), f.GetID(), s.GetCaptionDescription()); + ApplyPointFeature apply(insertShape, f.GetID(), s.GetCaptionDescription()); f.ForEachPointRef(apply, zoomLevel); s.ForEachRule(bind(&ApplyPointFeature::ProcessRule, &apply, _1)); diff --git a/drape_frontend/rule_drawer.hpp b/drape_frontend/rule_drawer.hpp index de6fa1df0a..3b0bb499be 100644 --- a/drape_frontend/rule_drawer.hpp +++ b/drape_frontend/rule_drawer.hpp @@ -27,8 +27,6 @@ public: RuleDrawer(TDrawerCallback const & fn, ref_ptr context); - void InsertShape(drape_ptr && shape); - void operator() (FeatureType const & f); private: diff --git a/geometry/spline.cpp b/geometry/spline.cpp index e24d8c8b03..c3b038e968 100644 --- a/geometry/spline.cpp +++ b/geometry/spline.cpp @@ -25,9 +25,10 @@ Spline::Spline(vector const & path) Spline::Spline(size_t reservedSize) { + ASSERT_LESS(0, reservedSize, ()); m_position.reserve(reservedSize); - m_direction.reserve(reservedSize); - m_length.reserve(reservedSize); + m_direction.reserve(reservedSize - 1); + m_length.reserve(reservedSize - 1); } void Spline::AddPoint(PointD const & pt)