Limbo 3.5.4
Loading...
Searching...
No Matches
test_p2r.cpp
Go to the documentation of this file.
1
6
7#include <iostream>
8#include <vector>
9#include <list>
10#include <set>
12using std::cout;
13using std::endl;
14using std::vector;
15using std::list;
16using std::set;
17using namespace limbo::geometry;
18
22struct Point
23{
25 typedef int value_type;
34 value_type const& x() const {return m_x;}
39 value_type const& y() const {return m_y;}
43 void x(value_type v) {m_x = v;}
47 void y(value_type v) {m_y = v;}
48
49 //bool operator==(Point const& rhs) {return x() == rhs.x() && y() == rhs.y();}
50};
51
52namespace limbo { namespace geometry {
53
59template <>
61{
65 typedef int coordinate_type;
66
73 static coordinate_type get(const point_type& point, orientation_2d orient)
74 {
75 if (orient == HORIZONTAL) return point.x();
76 else if (orient == VERTICAL) return point.y();
77 else assert(0);
78 }
79
85 static void set(point_type& point, orientation_2d orient, coordinate_type value)
86 {
87 if (orient == HORIZONTAL) return point.x(value);
88 else if (orient == VERTICAL) return point.y(value);
89 else assert(0);
90 }
91
98 {
99 point_type p;
100 p.x(x); p.y(y);
101 return p;
102 }
103};
104
105}}
106
111{
113 typedef int value_type;
114
123
128 value_type const& xl() const {return m_xl;}
133 value_type const& yl() const {return m_yl;}
138 value_type const& xh() const {return m_xh;}
143 value_type const& yh() const {return m_yh;}
148 void xl(value_type v) {m_xl = v;}
153 void yl(value_type v) {m_yl = v;}
158 void xh(value_type v) {m_xh = v;}
163 void yh(value_type v) {m_yh = v;}
164};
165
166namespace limbo { namespace geometry {
167
171template <>
173{
177 typedef int coordinate_type;
178
185 static coordinate_type get(const rectangle_type& rect, direction_2d dir)
186 {
187 switch (dir)
188 {
189 case LEFT: return rect.xl();
190 case BOTTOM: return rect.yl();
191 case RIGHT: return rect.xh();
192 case TOP: return rect.yh();
193 default: assert(0);
194 }
195 }
196
202 static void set(rectangle_type& rect, direction_2d dir, coordinate_type value)
203 {
204 switch (dir)
205 {
206 case LEFT: rect.xl(value); break;
207 case BOTTOM: rect.yl(value); break;
208 case RIGHT: rect.xh(value); break;
209 case TOP: rect.yh(value); break;
210 default: assert(0);
211 }
212 }
213
219 {
220 rectangle_type rect;
221 rect.xl(xl); rect.yl(yl);
222 rect.xh(xh); rect.yh(yh);
223 return rect;
224 }
225};
226
227}}
228
233void test1(string const& filename)
234{
235 vector<Rectangle> vRect;
236 Polygon2Rectangle<vector<Point>, vector<Rectangle> > p2r (vRect, HOR_VER_SLICING);
237 assert(p2r.read(filename));
238 assert(p2r());
239 p2r.print("p2r1.gp");
240}
241
246void test2(string const& filename)
247{
248 vector<Rectangle> vRect;
249 Polygon2Rectangle<list<Point>, vector<Rectangle> > p2r (vRect, HOR_VER_SLICING);
250 assert(p2r.read(filename));
251 assert(p2r());
252 p2r.print("p2r2.gp");
253}
254
259void test3(string const& filename)
260{
261 vector<Rectangle> vRect;
263 assert(p2r.read(filename));
264 assert(p2r());
265 p2r.print("p2r3.gp");
266}
267
274int main(int argc, char** argv)
275{
276 if (argc > 1)
277 {
278 test1(argv[1]);
279 test2(argv[1]);
280 test3(argv[1]);
281 }
282 else cout << "at least 1 argument is required" << endl;
283
284 return 0;
285}
a generic implementation of polygon-to-rectangle conversion
a class implement conversion from manhattan polygon to rectangle
bool read(string const &filename)
read polygon from file try to be compatible to gnuplot format
void print(string const &filename) const
print polygon to file in gnuplot format
a class denoting orientation of lines
Definition Geometry.h:93
namespace for Limbo.Geometry
Definition Geometry.h:21
@ HOR_VER_SLICING
horizontal/vertical slicing and choose rectangle with larger area every time
Definition Geometry.h:43
namespace for Limbo
a custom point class
Definition test_p2r.cpp:23
void y(value_type v)
set y coordinate
Definition test_p2r.cpp:47
int value_type
coordinate type
Definition test_p2r.cpp:25
value_type m_x
x coordinate
Definition test_p2r.cpp:27
value_type const & y() const
access y coordinate
Definition test_p2r.cpp:39
value_type const & x() const
access x coordinate
Definition test_p2r.cpp:34
value_type m_y
y coordinate
Definition test_p2r.cpp:29
void x(value_type v)
set x coordinate
Definition test_p2r.cpp:43
a custom rectangle class
Definition test_p2r.cpp:111
value_type m_yl
bottom
Definition test_p2r.cpp:118
void xh(value_type v)
set right coordinate
Definition test_p2r.cpp:158
value_type m_yh
top
Definition test_p2r.cpp:122
value_type const & yh() const
access top coordinate
Definition test_p2r.cpp:143
void yh(value_type v)
set top coordinate
Definition test_p2r.cpp:163
void yl(value_type v)
set bottom coordinate
Definition test_p2r.cpp:153
int value_type
coordinate type
Definition test_p2r.cpp:113
void xl(value_type v)
set left coordinate
Definition test_p2r.cpp:148
value_type m_xh
right
Definition test_p2r.cpp:120
value_type const & yl() const
access bottom coordinate
Definition test_p2r.cpp:133
value_type const & xl() const
access left coordinate
Definition test_p2r.cpp:128
value_type const & xh() const
access right coordinate
Definition test_p2r.cpp:138
value_type m_xl
left
Definition test_p2r.cpp:116
static coordinate_type get(const point_type &point, orientation_2d orient)
access coordinates
Definition test_p2r.cpp:73
static point_type construct(coordinate_type x, coordinate_type y)
construct a point object
Definition test_p2r.cpp:97
static void set(point_type &point, orientation_2d orient, coordinate_type value)
set coordinates
Definition test_p2r.cpp:85
type traits for point
Definition Geometry.h:196
static coordinate_type get(const rectangle_type &rect, direction_2d dir)
access coordinates
Definition test_p2r.cpp:185
static void set(rectangle_type &rect, direction_2d dir, coordinate_type value)
set coordinates
Definition test_p2r.cpp:202
static rectangle_type construct(coordinate_type xl, coordinate_type yl, coordinate_type xh, coordinate_type yh)
construct rectangle
Definition test_p2r.cpp:218
type traits for rectangle
Definition Geometry.h:227
int main()
void test2(string const &filename)
test polygon-to-rectangle for std::list
Definition test_p2r.cpp:246
void test3(string const &filename)
test polygon-to-rectangle for std::set
Definition test_p2r.cpp:259
void test1()
test function API