diff options
author | vng <viktor.govako@gmail.com> | 2011-05-16 00:05:02 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:17:20 +0300 |
commit | 7449344cdb66ac2f27ea63f99976e5f9c103fcc9 (patch) | |
tree | 7f8ebb29536f30759f9c1bb4730d60ece990bf79 | |
parent | 2ed412128b1d3ef69ccdb8c1151818ed9058628d (diff) |
Fix linear features merging.
-rw-r--r-- | generator/feature_merger.cpp | 40 | ||||
-rw-r--r-- | generator/feature_merger.hpp | 2 | ||||
-rw-r--r-- | generator/generator_tests/feature_merger_test.cpp | 2 |
3 files changed, 30 insertions, 14 deletions
diff --git a/generator/feature_merger.cpp b/generator/feature_merger.cpp index 48d8b22261..6f1a8896de 100644 --- a/generator/feature_merger.cpp +++ b/generator/feature_merger.cpp @@ -9,22 +9,30 @@ MergedFeatureBuilder1::MergedFeatureBuilder1(FeatureBuilder1 const & fb) m_Params.SortTypes(); } -void MergedFeatureBuilder1::AppendFeature(MergedFeatureBuilder1 const & fb) +void MergedFeatureBuilder1::AppendFeature(MergedFeatureBuilder1 const & fb, bool toBack) { - bool reverse = false; - if (LastPoint().SquareLength(fb.FirstPoint()) > LastPoint().SquareLength(fb.LastPoint())) - reverse = true; + m2::PointD const pt = toBack ? LastPoint() : FirstPoint(); - int const size = fb.m_Geometry.size(); - if (reverse) + bool fromEnd = false; + if ((pt.SquareLength(fb.FirstPoint()) > pt.SquareLength(fb.LastPoint())) == toBack) + fromEnd = true; + + for (size_t i = 0; i < fb.m_Geometry.size(); ++i) + m_LimitRect.Add(fb.m_Geometry[i]); + + if (fromEnd) { - for (int i = size-2; i >=0; --i) - AddPoint(fb.m_Geometry[i]); + if (toBack) + m_Geometry.insert(m_Geometry.end(), fb.m_Geometry.rbegin() + 1, fb.m_Geometry.rend()); + else + m_Geometry.insert(m_Geometry.begin(), fb.m_Geometry.rbegin(), fb.m_Geometry.rend() - 1); } else { - for (int i = 1; i < size; ++i) - AddPoint(fb.m_Geometry[i]); + if (toBack) + m_Geometry.insert(m_Geometry.end(), fb.m_Geometry.begin() + 1, fb.m_Geometry.end()); + else + m_Geometry.insert(m_Geometry.begin(), fb.m_Geometry.begin(), fb.m_Geometry.end() - 1); } } @@ -101,8 +109,16 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter) // Cycle while merging. while (true) { - map_t::iterator it = m_map.find(get_key(curr.LastPoint())); bool isMerged = false; + + bool toBack = true; + map_t::iterator it = m_map.find(get_key(curr.LastPoint())); + if (it == m_map.end()) + { + it = m_map.find(get_key(curr.FirstPoint())); + toBack = false; + } + if (it != m_map.end()) { // Find best feature to continue. @@ -113,7 +129,7 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter) if (pp->HasType(type)) { isMerged = true; - curr.AppendFeature(*(pp)); + curr.AppendFeature(*pp, toBack); if (pp->PopExactType(type)) { diff --git a/generator/feature_merger.hpp b/generator/feature_merger.hpp index f11d3eb762..89763578ca 100644 --- a/generator/feature_merger.hpp +++ b/generator/feature_merger.hpp @@ -13,7 +13,7 @@ public: MergedFeatureBuilder1() {} MergedFeatureBuilder1(FeatureBuilder1 const & fb); - void AppendFeature(MergedFeatureBuilder1 const & fb); + void AppendFeature(MergedFeatureBuilder1 const & fb, bool toBack); bool EqualGeometry(MergedFeatureBuilder1 const & fb) const; diff --git a/generator/generator_tests/feature_merger_test.cpp b/generator/generator_tests/feature_merger_test.cpp index adb26e7eb8..e2b014d160 100644 --- a/generator/generator_tests/feature_merger_test.cpp +++ b/generator/generator_tests/feature_merger_test.cpp @@ -129,5 +129,5 @@ UNIT_TEST(FeatureMerger_Branches) VectorEmitter emitter; processor.DoMerge(emitter); - TEST_EQUAL(emitter.GetSize(), 2, ()); + TEST_EQUAL(emitter.GetSize(), 1, ()); } |