File: rect_merger_test.cpp

package info (click to toggle)
pingus 0.7.6-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,672 kB
  • sloc: cpp: 42,080; xml: 2,319; lisp: 521; ruby: 455; ansic: 365; objc: 248; sh: 247; makefile: 140; python: 15
file content (132 lines) | stat: -rw-r--r-- 4,830 bytes parent folder | download | duplicates (7)
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
//  Pingus - A free Lemmings clone
//  Copyright (C) 1998-2009 Ingo Ruhnke <grumbel@gmx.de>
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <stdlib.h>

#include "engine/display/delta/rect_merger.hpp"

int main(int argc, char** argv)
{
  int t = 1216020230; // 20
  //1216032809 // 20
  //int t = time(NULL);
  //int t = 1216035347; 

  srand(t);

  std::cerr << t << std::endl;

  std::vector<Rect> rects_in;
  std::vector<Rect> rects_out;

  // Generate random rectangles
  if (0)
    for(int i = 0; i < 400; ++i)
      {
        rects_in.push_back(Rect(Vector2i(rand() % 800,
                                         rand() % 800),
                                Size(rand() % 60 + 10,
                                     rand() % 60 + 10)));
      }

  rects_in.push_back(Rect(380, 279, 412, 311));
  rects_in.push_back(Rect(307, 280, 339, 312));
  rects_in.push_back(Rect(397, 279, 429, 311));
  rects_in.push_back(Rect(354, 280, 386, 312));
  rects_in.push_back(Rect(282, 277, 314, 309));
  rects_in.push_back(Rect(441, 282, 473, 314));
  rects_in.push_back(Rect(531, 281, 563, 313));
  rects_in.push_back(Rect(249, 280, 281, 312));
  rects_in.push_back(Rect(4, 112, 36, 144));
  rects_in.push_back(Rect(381, 279, 413, 311));
  rects_in.push_back(Rect(306, 280, 338, 312));
  rects_in.push_back(Rect(396, 279, 428, 311));
  rects_in.push_back(Rect(355, 280, 387, 312));
  rects_in.push_back(Rect(283, 277, 315, 309));
  rects_in.push_back(Rect(440, 282, 472, 314));
  rects_in.push_back(Rect(530, 281, 562, 313));
  rects_in.push_back(Rect(249, 280, 281, 312));
  rects_in.push_back(Rect(4, 112, 36, 144));
                                        
  merge_rectangles(rects_in, rects_out);
  
  if (1) // print results as SVG 
    {
      std::cout << "<?xml version='1.0' standalone='no'?>\n"
                << "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' "
                << "'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>\n"
                << "<svg width='800' height='800' "
                << "xmlns='http://www.w3.org/2000/svg' version='1.1'>" << std::endl;

      std::cout << "<g>" << std::endl;
      for(std::vector<Rect>::iterator i = rects_in.begin(); i != rects_in.end(); ++i)
        std::cout << "  <rect fill='blue' style='fill-opacity:0.5' x='" << i->left << "' y='" << i->top 
                  << "' width='" << i->get_width() << "' height='" << i->get_height() << "' />" << std::endl;
      std::cout << "</g>" << std::endl;
      std::cout << std::endl;

      std::cout << "<g>" << std::endl;  
      for(std::vector<Rect>::iterator i = rects_out.begin(); i != rects_out.end(); ++i)
        std::cout << "  <rect fill='yellow' stroke='black' style='fill-opacity:0.5;stroke-width:1px' x='" << i->left << "' y='" << i->top 
                  << "' width='" << i->get_width() << "' height='" << i->get_height() << "' />" << std::endl;
      std::cout << "</g>" << std::endl;
      std::cout << "</svg>" << std::endl;
    }

  return 0;
}

/*

  if (1)
    {
      std::cout << "--- Merge rectangles: " << rects_in.size() << std::endl;
      for(std::vector<Rect>::const_iterator i = rects_in.begin(); i != rects_in.end(); ++i)
        {
          std::cout << "  rectin: " << *i << std::endl;
        }
    }

  for(std::vector<Row>::const_iterator i = rows.begin(); i != rows.end(); ++i)
    {
      std::cout << "Row: " << i->marks.size() << " ";
      for(std::vector<Mark>::const_iterator j = i->marks.begin(); j != i->marks.end(); ++j)
        {
          std::cout << ((j->type == Mark::START_MARK) ? "'(" : "')")
                      << j->pos 
                      << "' ";          
        }
      std::cout << std::endl;
    }

  // Print rows
  if (0)
    for(std::vector<Row>::iterator i = rows.begin(); i != rows.end(); ++i)
      {
        std::cout << "  row: " << i->top << "-" << i->bottom << " - ";
        for(std::vector<Mark>::iterator mark_it = i->marks.begin(); mark_it != i->marks.end(); ++mark_it)
          {
            std::cout << ((mark_it->type == Mark::START_MARK) ? "'(" : "')")
                      << mark_it->pos 
                      << "' ";
          }
        std::cout << std::endl;
      }

 */

/* EOF */