Welcome to mirror list, hosted at ThFree Co, Russian Federation.

coasts_test.cpp « generator_tests « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 009857f780c9c79b6587051fe99bf234300e6f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "testing/testing.hpp"

#include "generator/feature_builder.hpp"
#include "generator/feature_generator.hpp"
#include "generator/feature_helpers.hpp"

#include "coding/pointd_to_pointu.hpp"

#include "geometry/cellid.hpp"
#include "geometry/mercator.hpp"

#include "indexer/cell_id.hpp"
#include "indexer/scales.hpp"

#include "base/logging.hpp"

using namespace std;

namespace
{
  inline m2::PointU D2I(double x, double y)
  {
    return PointDToPointU(m2::PointD(x, y), POINT_COORD_BITS);
  }
}

UNIT_TEST(CellID_CheckRectPoints)
{
  int const level = 6;
  int const count = 1 << 2 * level;

  typedef m2::CellId<19> TId;
  typedef CellIdConverter<MercatorBounds, TId> TConverter;

  for (size_t i = 0; i < count; ++i)
  {
    TId const cell = TId::FromBitsAndLevel(i, level);
    pair<uint32_t, uint32_t> const xy = cell.XY();
    uint32_t const r = 2*cell.Radius();
    uint32_t const bound = (1 << level) * r;

    double minX, minY, maxX, maxY;
    TConverter::GetCellBounds(cell, minX, minY, maxX, maxY);

    double minX_, minY_, maxX_, maxY_;
    if (xy.first > r)
    {
      TId neibour = TId::FromXY(xy.first - r, xy.second, level);
      TConverter::GetCellBounds(neibour, minX_, minY_, maxX_, maxY_);

      TEST_ALMOST_EQUAL_ULPS(minX, maxX_, ());
      TEST_ALMOST_EQUAL_ULPS(minY, minY_, ());
      TEST_ALMOST_EQUAL_ULPS(maxY, maxY_, ());

      TEST_EQUAL(D2I(minX, minY), D2I(maxX_, minY_), ());
      TEST_EQUAL(D2I(minX, maxY), D2I(maxX_, maxY_), ());
    }

    if (xy.first + r < bound)
    {
      TId neibour = TId::FromXY(xy.first + r, xy.second, level);
      TConverter::GetCellBounds(neibour, minX_, minY_, maxX_, maxY_);

      TEST_ALMOST_EQUAL_ULPS(maxX, minX_, ());
      TEST_ALMOST_EQUAL_ULPS(minY, minY_, ());
      TEST_ALMOST_EQUAL_ULPS(maxY, maxY_, ());

      TEST_EQUAL(D2I(maxX, minY), D2I(minX_, minY_), ());
      TEST_EQUAL(D2I(maxX, maxY), D2I(minX_, maxY_), ());
    }

    if (xy.second > r)
    {
      TId neibour = TId::FromXY(xy.first, xy.second - r, level);
      TConverter::GetCellBounds(neibour, minX_, minY_, maxX_, maxY_);

      TEST_ALMOST_EQUAL_ULPS(minY, maxY_, ());
      TEST_ALMOST_EQUAL_ULPS(minX, minX_, ());
      TEST_ALMOST_EQUAL_ULPS(maxX, maxX_, ());

      TEST_EQUAL(D2I(minX, minY), D2I(minX_, maxY_), ());
      TEST_EQUAL(D2I(maxX, minY), D2I(maxX_, maxY_), ());
    }

    if (xy.second + r < bound)
    {
      TId neibour = TId::FromXY(xy.first, xy.second + r, level);
      TConverter::GetCellBounds(neibour, minX_, minY_, maxX_, maxY_);

      TEST_ALMOST_EQUAL_ULPS(maxY, minY_, ());
      TEST_ALMOST_EQUAL_ULPS(minX, minX_, ());
      TEST_ALMOST_EQUAL_ULPS(maxX, maxX_, ());

      TEST_EQUAL(D2I(minX, maxY), D2I(minX_, minY_), ());
      TEST_EQUAL(D2I(maxX, maxY), D2I(maxX_, minY_), ());
    }
  }
}

namespace
{
  class ProcessCoastsBase
  {
    vector<string> const & m_vID;

  protected:
    bool HasID(FeatureBuilder1 const & fb) const
    {
      TEST(fb.IsCoastCell(), ());
      return (find(m_vID.begin(), m_vID.end(), fb.GetName()) != m_vID.end());
    }

  public:
    ProcessCoastsBase(vector<string> const & vID) : m_vID(vID) {}
  };

  class DoPrintCoasts : public ProcessCoastsBase
  {
  public:
    DoPrintCoasts(vector<string> const & vID) : ProcessCoastsBase(vID) {}

    void operator() (FeatureBuilder1 const & fb1, uint64_t)
    {
      if (HasID(fb1))
      {
        FeatureBuilder2 const & fb2 = reinterpret_cast<FeatureBuilder2 const &>(fb1);

        // Check common params.
        TEST(fb2.IsArea(), ());
        int const upperScale = scales::GetUpperScale();
        TEST(fb2.IsDrawableInRange(0, upperScale), ());

        m2::RectD const rect = fb2.GetLimitRect();
        LOG(LINFO, ("ID = ", fb1.GetName(), "Rect = ", rect, "Polygons = ", fb2.GetGeometry()));

        // Make bound rect inflated a little.
        feature::BoundsDistance dist(rect);
        m2::RectD const boundRect = m2::Inflate(rect, dist.GetEpsilon(), dist.GetEpsilon());

        typedef vector<m2::PointD> PointsT;
        typedef list<PointsT> PolygonsT;

        PolygonsT const & poly = fb2.GetGeometry();

        // Check that all simplifications are inside bound rect.
        for (int level = 0; level <= upperScale; ++level)
        {
          TEST(fb2.IsDrawableInRange(level, level), ());

          for (PolygonsT::const_iterator i = poly.begin(); i != poly.end(); ++i)
          {
            PointsT pts;
            feature::SimplifyPoints(dist, level, *i, pts);

            LOG(LINFO, ("Simplified. Level = ", level, "Points = ", pts));

            for (size_t j = 0; j < pts.size(); ++j)
              TEST(boundRect.IsPointInside(pts[j]), (pts[j]));
          }
        }
      }
    }
  };

  class DoCopyCoasts : public ProcessCoastsBase
  {
    feature::FeaturesCollector m_collector;
  public:
    DoCopyCoasts(string const & fName, vector<string> const & vID)
      : ProcessCoastsBase(vID), m_collector(fName)
    {
    }

    void operator() (FeatureBuilder1 const & fb1, uint64_t)
    {
      if (HasID(fb1))
        m_collector(fb1);
    }
  };
}

/*
UNIT_TEST(WorldCoasts_CheckBounds)
{
  vector<string> vID;

  // bounds
  vID.push_back("2222");
  vID.push_back("3333");
  vID.push_back("0000");
  vID.push_back("1111");

  // bad cells
  vID.push_back("2021");
  vID.push_back("2333");
  vID.push_back("3313");
  vID.push_back("1231");
  vID.push_back("32003");
  vID.push_back("21330");
  vID.push_back("20110");
  vID.push_back("03321");
  vID.push_back("12323");
  vID.push_back("1231");
  vID.push_back("1311");

  //DoPrintCoasts doProcess(vID);
  DoCopyCoasts doProcess("/Users/alena/omim/omim/data/WorldCoasts.mwm.tmp", vID);
  feature::ForEachFromDatRawFormat("/Users/alena/omim/omim-indexer-tmp/WorldCoasts.mwm.tmp", doProcess);
}
*/