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

feature_merger_test.cpp « generator_tests « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c43c08089847be2a6430e1bfc4fc9d542b384f19 (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
#include "testing/testing.hpp"

#include "generator/feature_merger.hpp"


namespace
{
  typedef m2::PointD P;

  class VectorEmitter : public FeatureEmitterIFace
  {
    vector<FeatureBuilder1> m_vec;
  public:
    virtual void operator() (FeatureBuilder1 const & fb)
    {
      m_vec.push_back(fb);
    }

    size_t GetSize() const { return m_vec.size(); }

    void Check(uint32_t type, size_t count) const
    {
      size_t test = 0;
      for (size_t i = 0; i < m_vec.size(); ++i)
        if (m_vec[i].HasType(type))
          ++test;

      TEST_EQUAL(test, count, ());
    }
  };
}

UNIT_TEST(FeatureMerger_MultipleTypes)
{
  P arrPt[] = { P(0, 0), P(1, 1), P(2, 2), P(3, 3) };
  size_t const count = ARRAY_SIZE(arrPt)-1;

  FeatureBuilder1 arrF[count];

  for (size_t i = 0; i < count; ++i)
  {
    arrF[i].SetLinear();
    arrF[i].AddPoint(arrPt[i]);
    arrF[i].AddPoint(arrPt[i+1]);

    arrF[i].AddType(0);
  }

  arrF[0].AddType(1);
  arrF[1].AddType(1);
  arrF[0].AddType(2);
  arrF[1].AddType(2);

  arrF[1].AddType(3);
  arrF[2].AddType(3);
  arrF[1].AddType(4);
  arrF[2].AddType(4);

  FeatureMergeProcessor processor(POINT_COORD_BITS);

  for (size_t i = 0; i < count; ++i)
    processor(arrF[i]);

  VectorEmitter emitter;
  processor.DoMerge(emitter);

  TEST_EQUAL(emitter.GetSize(), 3, ());

  emitter.Check(0, 1);
  emitter.Check(1, 1);
  emitter.Check(2, 1);
  emitter.Check(3, 1);
  emitter.Check(4, 1);
}

UNIT_TEST(FeatureMerger_Branches)
{
  /* Try to unite next configuration
          o
         /\
     o--o--o--o
         \/
         o
  */

  vector<FeatureBuilder1> vF;

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-2, 0));
  vF.back().AddPoint(P(-1, 0));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-1, 0));
  vF.back().AddPoint(P(0, 1));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-1, 0));
  vF.back().AddPoint(P(0, 0));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-1, 0));
  vF.back().AddPoint(P(0, -1));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(0, 1));
  vF.back().AddPoint(P(1, 0));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(0, 0));
  vF.back().AddPoint(P(1, 0));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(0, -1));
  vF.back().AddPoint(P(1, 0));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(1, 0));
  vF.back().AddPoint(P(2, 0));

  FeatureMergeProcessor processor(POINT_COORD_BITS);

  for (size_t i = 0; i < vF.size(); ++i)
  {
    vF[i].SetLinear();
    vF[i].AddType(0);

    processor(vF[i]);
  }

  VectorEmitter emitter;
  processor.DoMerge(emitter);

  TEST_LESS_OR_EQUAL(emitter.GetSize(), 2, ());
}

UNIT_TEST(FeatureMerger_Rounds)
{
  vector<FeatureBuilder1> vF;

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-10, 0));
  vF.back().AddPoint(P(-5, 0));

  // make first round feature
  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-4, 1));
  vF.back().AddPoint(P(-3, 0));
  vF.back().AddPoint(P(-4, -1));
  vF.back().AddPoint(P(-5, 0));
  vF.back().AddPoint(P(-4, 1));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(-3, 0));
  vF.back().AddPoint(P(3, 0));

  // make second round feature
  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(4, -1));
  vF.back().AddPoint(P(3, 0));
  vF.back().AddPoint(P(4, 1));
  vF.back().AddPoint(P(5, 0));
  vF.back().AddPoint(P(4, -1));

  vF.push_back(FeatureBuilder1());
  vF.back().AddPoint(P(5, 0));
  vF.back().AddPoint(P(10, 0));

  FeatureMergeProcessor processor(POINT_COORD_BITS);

  for (size_t i = 0; i < vF.size(); ++i)
  {
    vF[i].SetLinear();
    vF[i].AddType(0);

    processor(vF[i]);
  }

  VectorEmitter emitter;
  processor.DoMerge(emitter);

  TEST_EQUAL(emitter.GetSize(), 1, ());
}