diff --git a/indexer/feature.cpp b/indexer/feature.cpp index 6f6561299f..f2fa581936 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -98,6 +98,19 @@ void FeatureType::ParseHeader2() const } } +void FeatureType::ResetGeometry() const +{ + m_points.clear(); + m_triangles.clear(); + + if (GetFeatureType() != GEOM_POINT) + m_limitRect = m2::RectD(); + + m_bHeader2Parsed = m_bPointsParsed = m_bTrianglesParsed = false; + + m_pLoader->ResetGeometry(); +} + uint32_t FeatureType::ParseGeometry(int scale) const { uint32_t sz = 0; @@ -155,6 +168,10 @@ string FeatureType::DebugString(int scale) const s += " Triangles:"; Points2String(s, m_triangles); break; + + case GEOM_UNDEFINED: + ASSERT(false, ("Assume that we have valid feature always")); + break; } return s; diff --git a/indexer/feature.hpp b/indexer/feature.hpp index 0357f820de..c42bf7ab06 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -159,6 +159,8 @@ public: /// @name Parse functions. Do simple dispatching to m_pLoader. //@{ void ParseHeader2() const; + + void ResetGeometry() const; uint32_t ParseGeometry(int scale) const; uint32_t ParseTriangles(int scale) const; //@} diff --git a/indexer/feature_covering.cpp b/indexer/feature_covering.cpp index 7aa3fb4307..e5ebc49dbf 100644 --- a/indexer/feature_covering.cpp +++ b/indexer/feature_covering.cpp @@ -120,23 +120,28 @@ namespace covering vector CoverFeature(FeatureType const & f, int cellDepth, uint64_t cellPenaltyArea) { - FeatureIntersector featureIntersector; - f.ForEachPointRef(featureIntersector, FeatureType::BEST_GEOMETRY); - f.ForEachTriangleRef(featureIntersector, FeatureType::BEST_GEOMETRY); + // We need to cover feature for the best geometry, because it's indexed once for the + // first top level scale. Do reset current cached geometry first. + f.ResetGeometry(); + int const scale = FeatureType::BEST_GEOMETRY; - CHECK(!featureIntersector.m_trg.empty() || !featureIntersector.m_polyline.empty(), \ - (f.DebugString(FeatureType::BEST_GEOMETRY))); + FeatureIntersector fIsect; + f.ForEachPointRef(fIsect, scale); + f.ForEachTriangleRef(fIsect, scale); - if (featureIntersector.m_trg.empty() && featureIntersector.m_polyline.size() == 1) + CHECK(!(fIsect.m_trg.empty() && fIsect.m_polyline.empty()) && + f.GetLimitRect(scale).IsValid(), (f.DebugString(scale))); + + if (fIsect.m_trg.empty() && fIsect.m_polyline.size() == 1) { - m2::PointD const pt = featureIntersector.m_polyline[0]; + m2::PointD const pt = fIsect.m_polyline[0]; return vector( 1, RectId::FromXY(static_cast(pt.x), static_cast(pt.y), RectId::DEPTH_LEVELS - 1).ToInt64(cellDepth)); } vector cells; - covering::CoverObject(featureIntersector, cellPenaltyArea, cells, cellDepth, RectId::Root()); + covering::CoverObject(fIsect, cellPenaltyArea, cells, cellDepth, RectId::Root()); vector res(cells.size()); for (size_t i = 0; i < cells.size(); ++i) diff --git a/indexer/feature_loader_base.cpp b/indexer/feature_loader_base.cpp index bc69121361..1a6ebca998 100644 --- a/indexer/feature_loader_base.cpp +++ b/indexer/feature_loader_base.cpp @@ -74,6 +74,12 @@ void LoaderBase::Init(BufferT data) m_pF = 0; m_CommonOffset = m_Header2Offset = 0; + + ResetGeometry(); +} + +void LoaderBase::ResetGeometry() +{ m_ptsSimpMask = 0; m_ptsOffsets.clear(); diff --git a/indexer/feature_loader_base.hpp b/indexer/feature_loader_base.hpp index 1a1d31473d..a0c7fac347 100644 --- a/indexer/feature_loader_base.hpp +++ b/indexer/feature_loader_base.hpp @@ -62,6 +62,8 @@ namespace feature //@{ void Init(BufferT data); inline void InitFeature(FeatureType * p) { m_pF = p; } + + void ResetGeometry(); //@} virtual uint8_t GetHeader() = 0;