From 8b41efdc9c03061b300c094a51461ea9bd3c7aca Mon Sep 17 00:00:00 2001 From: vng Date: Sun, 3 Jun 2012 21:30:21 +0300 Subject: [PATCH] [generator] Add coasts generator test. --- generator/feature_sorter.cpp | 26 ------- generator/feature_sorter.hpp | 29 ++++++++ generator/generator_tests/coasts_test.cpp | 84 +++++++++++------------ 3 files changed, 71 insertions(+), 68 deletions(-) diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp index 2ded66e3eb..d6fe84e11f 100644 --- a/generator/feature_sorter.cpp +++ b/generator/feature_sorter.cpp @@ -346,32 +346,6 @@ namespace feature } }; - class BoundsDistance : public mn::DistanceToLineSquare - { - m2::RectD const & m_rect; - double m_eps; - - public: - BoundsDistance(m2::RectD const & rect) - : m_rect(rect), m_eps(5.0E-7) - { - // 5.0E-7 is near with minimal epsilon when integer points are different - // PointD2PointU(x, y) != PointD2PointU(x + m_eps, y + m_eps) - } - - double operator() (m2::PointD const & p) const - { - if (fabs(p.x - m_rect.minX()) <= m_eps || fabs(p.x - m_rect.maxX()) <= m_eps || - fabs(p.y - m_rect.minY()) <= m_eps || fabs(p.y - m_rect.maxY()) <= m_eps) - { - // points near rect should be in a result simplified vector - return std::numeric_limits::max(); - } - - return mn::DistanceToLineSquare::operator()(p); - } - }; - void SimplifyPoints(points_t const & in, points_t & out, int level, bool isCoast, m2::RectD const & rect) { diff --git a/generator/feature_sorter.hpp b/generator/feature_sorter.hpp index a68a322e6e..c7baab9dca 100644 --- a/generator/feature_sorter.hpp +++ b/generator/feature_sorter.hpp @@ -8,6 +8,7 @@ #include "../std/string.hpp" + namespace feature { /// Final generation of data from input feature-dat-file. @@ -27,6 +28,34 @@ namespace feature return AlmostEqual(p1, p2); } + class BoundsDistance : public mn::DistanceToLineSquare + { + m2::RectD const & m_rect; + double m_eps; + + public: + BoundsDistance(m2::RectD const & rect) + : m_rect(rect), m_eps(5.0E-7) + { + // 5.0E-7 is near with minimal epsilon when integer points are different + // PointD2PointU(x, y) != PointD2PointU(x + m_eps, y + m_eps) + } + + double GetEpsilon() const { return m_eps; } + + double operator() (m2::PointD const & p) const + { + if (fabs(p.x - m_rect.minX()) <= m_eps || fabs(p.x - m_rect.maxX()) <= m_eps || + fabs(p.y - m_rect.minY()) <= m_eps || fabs(p.y - m_rect.maxY()) <= m_eps) + { + // points near rect should be in a result simplified vector + return std::numeric_limits::max(); + } + + return mn::DistanceToLineSquare::operator()(p); + } + }; + template void SimplifyPoints(DistanceT dist, PointsContainerT const & in, PointsContainerT & out, int level) { diff --git a/generator/generator_tests/coasts_test.cpp b/generator/generator_tests/coasts_test.cpp index 424670772c..15fce2d399 100644 --- a/generator/generator_tests/coasts_test.cpp +++ b/generator/generator_tests/coasts_test.cpp @@ -1,9 +1,11 @@ #include "../../testing/testing.hpp" #include "../feature_builder.hpp" +#include "../feature_sorter.hpp" #include "../../indexer/mercator.hpp" #include "../../indexer/cell_id.hpp" +#include "../../indexer/scales.hpp" #include "../../geometry/cellid.hpp" @@ -91,10 +93,9 @@ UNIT_TEST(CellID_CheckRectPoints) } } -/* namespace { - class DoGetCoasts + class DoPrintCoasts { vector const & m_vID; @@ -103,67 +104,66 @@ namespace return (find(m_vID.begin(), m_vID.end(), id) != m_vID.end()); } - list m_rects; - - typedef list > polygons_t; - polygons_t m_maxPoly; - public: - DoGetCoasts(vector const & vID) : m_vID(vID) {} + DoPrintCoasts(vector const & vID) : m_vID(vID) {} - void operator() (FeatureBuilder1 const & fb, uint64_t) + void operator() (FeatureBuilder1 const & fb1, uint64_t) { int64_t dummy; - CHECK(fb.GetCoastCell(dummy), ()); + TEST(fb1.GetCoastCell(dummy), ()); - string const id = fb.GetName(); + string const id = fb1.GetName(); if (Has(id)) { - LOG(LINFO, ("ID = ", id, "Rect = ", fb.GetLimitRect(), - "Polygons = ", fb.GetPolygonsCount())); + FeatureBuilder2 const & fb2 = reinterpret_cast(fb1); - m_rects.push_back(fb.GetLimitRect()); + // Check common params. + TEST(fb2.IsArea(), ()); + int const upperScale = scales::GetUpperScale(); + TEST(fb2.IsDrawableInRange(0, upperScale), ()); - polygons_t const & poly = reinterpret_cast(fb).GetPolygons(); + m2::RectD const rect = fb2.GetLimitRect(); + LOG(LINFO, ("ID = ", id, "Rect = ", rect, "Polygons = ", fb2.GetPolygons())); - // get polygon with max points count - size_t maxCount = 0; - m_maxPoly.push_back(vector()); - for (polygons_t::const_iterator i = poly.begin(); i != poly.end(); ++i) - if (i->size() > maxCount) + // Make bound rect inflated a little. + feature::BoundsDistance dist(rect); + m2::RectD const boundRect = m2::Inflate(rect, dist.GetEpsilon(), dist.GetEpsilon()); + + typedef vector PointsT; + typedef list PolygonsT; + + PolygonsT const & poly = fb2.GetPolygons(); + + // Check that all simplifications are inside bound rect. + for (int level = 0; level <= upperScale; ++level) + { + for (PolygonsT::const_iterator i = poly.begin(); i != poly.end(); ++i) { - maxCount = i->size(); - m_maxPoly.back() = *i; + PointsT pts; + feature::SimplifyPoints(dist, *i, pts, level); + + LOG(LINFO, ("Simplified. Level = ", level, "Points = ", pts)); + + for (size_t j = 0; j < pts.size(); ++j) + TEST(boundRect.IsPointInside(pts[j]), (pts[j])); } + } } } - - void DumpMaxPolygons() - { - LOG(LINFO, ("Original")); - for (polygons_t::const_iterator i = m_maxPoly.begin(); i != m_maxPoly.end(); ++i) - { - m2::RectD r; - feature::CalcRect(*i, r); - LOG(LINFO, ("Polygon points count = ", i->size(), "Polygon rect = ", r)); - } - - LOG(LINFO, ("Simplified")); - /// @todo Check simplified polygons - } }; } +/* UNIT_TEST(WorldCoasts_CheckBounds) { vector vID; - vID.push_back("2213023"); - vID.push_back("2213021"); + vID.push_back("1231"); + vID.push_back("123203"); + vID.push_back("12323"); + vID.push_back("03321"); - DoGetCoasts doGet(vID); + DoPrintCoasts doGet(vID); feature::ForEachFromDatRawFormat( - "/Users/alena/omim/omim-indexer-tmp/WorldCoasts.mwm", doGet); - - doGet.DumpMaxPolygons(); + "/Users/alena/omim/omim-indexer-tmp/WorldCoasts.mwm.tmp", doGet); } */