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

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

#include "generator/tesselator.hpp"

#include "base/logging.hpp"


namespace
{
  typedef m2::PointD P;

  class DoDump
  {
    size_t & m_count;
  public:
    DoDump(size_t & count) : m_count(count)
    {
      m_count = 0;
    }
    void operator() (P const & p1, P const & p2, P const & p3)
    {
      ++m_count;
      LOG(LINFO, (p1, p2, p3));
    }
  };

  size_t RunTest(list<vector<P> > const & l)
  {
    tesselator::TrianglesInfo info;
    tesselator::TesselateInterior(l, info);

    size_t count;
    info.ForEachTriangle(DoDump(count));
    return count;
  }

  size_t RunTess(P const * arr, size_t count)
  {
    list<vector<P> > l;
    l.push_back(vector<P>());
    l.back().assign(arr, arr + count);

    return RunTest(l);
  }
}

UNIT_TEST(Tesselator_SelfISect)
{
  P arr[] = { P(0, 0), P(0, 4), P(4, 4), P(1, 1), P(1, 3), P(4, 0), P(0, 0) };
  TEST_EQUAL(6, RunTess(arr, ARRAY_SIZE(arr)), ());
}

UNIT_TEST(Tesselator_Odd)
{
  P arr[] = { P(-100, -100), P(100, 100), P(100, -100) };

  size_t const count = ARRAY_SIZE(arr);

  list<vector<P> > l;
  l.push_back(vector<P>());
  l.back().assign(arr, arr + count);
  l.push_back(vector<P>());
  l.back().assign(arr, arr + count);

  TEST_EQUAL(0, RunTest(l), ());

  P arr1[] = { P(-100, -100), P(100, -100), P(100, 100), P(-100, 100) };

  l.push_back(vector<P>());
  l.back().assign(arr1, arr1 + ARRAY_SIZE(arr1));

  TEST_EQUAL(2, RunTest(l), ());
}