From e495039d778dbe6360b05f2b81cecc2efcb00bc3 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 28 Jul 2015 17:06:39 +0300 Subject: [PATCH] VNG review fixes. --- generator/world_map_generator.hpp | 21 ++++++++++++--------- geometry/region2d.hpp | 12 ++++++++---- geometry/tree4d.hpp | 28 +++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/generator/world_map_generator.hpp b/generator/world_map_generator.hpp index 740342400e..468adaa639 100644 --- a/generator/world_map_generator.hpp +++ b/generator/world_map_generator.hpp @@ -4,6 +4,7 @@ #include "generator/generate_info.hpp" #include "geometry/tree4d.hpp" +#include "geometry/region2d.hpp" #include "indexer/scales.hpp" @@ -16,9 +17,13 @@ namespace class WaterBoundaryChecker { uint32_t m_boundaryType; - deque m_waterRegions; - m4::Tree m_tree; + struct RegionTraits + { + m2::RectD const & LimitRect(m2::RegionD const & r) const { return r.GetRect(); } + }; + m4::Tree m_tree; + size_t m_totalFeatures = 0; size_t m_totalBorders = 0; size_t m_skippedBorders = 0; @@ -55,16 +60,14 @@ public: ++total; - vector points; for (size_t i = 0; i < numGeometries; ++i) { uint64_t numPoints = 0; file.Read(&numPoints, sizeof(numPoints)); - points.resize(numPoints); + + vector points(numPoints); file.Read(points.data(), sizeof(m2::PointD) * numPoints); - m_waterRegions.push_back(m2::RegionD()); - m_waterRegions.back().Assign(points.begin(), points.end()); - m_tree.Add(m_waterRegions.size() - 1, m_waterRegions.back().GetRect()); + m_tree.Add(m2::RegionD(move(points))); } } LOG(LINFO, ("Load", total, "water geometries")); @@ -94,10 +97,10 @@ public: { m2::PointD const & p = pts[i]; m2::RectD r(p.x - kExtension, p.y - kExtension, p.x + kExtension, p.y + kExtension); - m_tree.ForEachInRect(r, [&](size_t index) + m_tree.ForEachInRect(r, [&](m2::RegionD const & rgn) { ++m_selectedPolygons; - hits[i] += m_waterRegions[index].Contains(p) ? 1 : 0; + hits[i] += rgn.Contains(p) ? 1 : 0; }); } diff --git a/geometry/region2d.hpp b/geometry/region2d.hpp index 71d3f6f53a..11897587fa 100644 --- a/geometry/region2d.hpp +++ b/geometry/region2d.hpp @@ -80,11 +80,15 @@ namespace m2 //@} public: - Region() {} + Region() = default; + + explicit Region(vector && points) : m_points(move(points)) + { + CalcLimitRect(); + } template - Region(IterT first, IterT last) - : m_points(first, last) + Region(IterT first, IterT last) : m_points(first, last) { CalcLimitRect(); } @@ -119,7 +123,7 @@ namespace m2 for_each(m_points.begin(), m_points.end(), toDo); } - inline m2::Rect GetRect() const { return m_rect; } + inline m2::Rect const & GetRect() const { return m_rect; } inline size_t GetPointsCount() const { return m_points.size(); } inline bool IsValid() const { return GetPointsCount() > 2; } diff --git a/geometry/tree4d.hpp b/geometry/tree4d.hpp index caef044fbe..3b9ee92f1f 100644 --- a/geometry/tree4d.hpp +++ b/geometry/tree4d.hpp @@ -25,8 +25,17 @@ namespace m4 template > class Tree { - struct ValueT + class ValueT { + void SetRect(m2::RectD const & r) + { + m_pts[0] = r.minX(); + m_pts[1] = r.minY(); + m_pts[2] = r.maxX(); + m_pts[3] = r.maxY(); + } + + public: T m_val; double m_pts[4]; @@ -34,10 +43,11 @@ namespace m4 ValueT(T const & t, m2::RectD const & r) : m_val(t) { - m_pts[0] = r.minX(); - m_pts[1] = r.minY(); - m_pts[2] = r.maxX(); - m_pts[3] = r.maxY(); + SetRect(r); + } + ValueT(T && t, m2::RectD const & r) : m_val(move(t)) + { + SetRect(r); } bool IsIntersect(m2::RectD const & r) const @@ -129,11 +139,19 @@ namespace m4 { Add(obj, GetLimitRect(obj)); } + void Add(T && obj) + { + Add(move(obj), GetLimitRect(obj)); + } void Add(T const & obj, m2::RectD const & rect) { m_tree.insert(ValueT(obj, rect)); } + void Add(T && obj, m2::RectD const & rect) + { + m_tree.insert(ValueT(move(obj), rect)); + } private: template