Limbo
3.5.4
Toggle main menu visibility
Loading...
Searching...
No Matches
test
geometry
test_uint64.cpp
1
6
7
#include <iostream>
8
#include <vector>
9
#include <list>
10
#include <set>
11
#include <
limbo/geometry/Polygon2Rectangle.h
>
12
using
std::cout;
13
using
std::endl;
14
using
std::vector;
15
using
std::list;
16
using
std::set;
17
using namespace
limbo::geometry
;
18
22
struct
Point
23
{
25
typedef
uint64_t
value_type
;
27
value_type
m_x
;
29
value_type
m_y
;
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
52
namespace
limbo
{
namespace
geometry
{
53
59
template
<>
60
struct
point_traits
<Point>
61
{
63
typedef
Point
point_type
;
65
typedef
uint64_t
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
97
static
point_type
construct
(
coordinate_type
x,
coordinate_type
y)
98
{
99
point_type
p;
100
p.
x
(x); p.
y
(y);
101
return
p;
102
}
103
};
104
105
}}
106
110
struct
Rectangle
111
{
113
typedef
uint64_t
value_type
;
114
116
value_type
m_xl
;
118
value_type
m_yl
;
120
value_type
m_xh
;
122
value_type
m_yh
;
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
166
namespace
limbo
{
namespace
geometry
{
167
171
template
<>
172
struct
rectangle_traits
<Rectangle>
173
{
175
typedef
Rectangle
rectangle_type
;
177
typedef
uint64_t
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
218
static
rectangle_type
construct
(
coordinate_type
xl,
coordinate_type
yl,
coordinate_type
xh,
coordinate_type
yh)
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
233
void
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
246
void
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
259
void
test3
(
string
const
& filename)
260
{
261
vector<Rectangle> vRect;
262
Polygon2Rectangle<set<Point, point_compare_type>
, vector<Rectangle> > p2r (vRect,
HOR_VER_SLICING
);
263
assert(p2r.read(filename));
264
assert(p2r());
265
p2r.print(
"p2r3.gp"
);
266
}
267
274
int
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
}
Polygon2Rectangle.h
a generic implementation of polygon-to-rectangle conversion
limbo::geometry::Polygon2Rectangle
a class implement conversion from manhattan polygon to rectangle
Definition
Polygon2Rectangle.h:91
limbo::geometry::orientation_2d
a class denoting orientation of lines
Definition
Geometry.h:93
limbo::geometry
namespace for Limbo.Geometry
Definition
Geometry.h:21
limbo::geometry::HOR_VER_SLICING
@ HOR_VER_SLICING
horizontal/vertical slicing and choose rectangle with larger area every time
Definition
Geometry.h:43
limbo
namespace for Limbo
Definition
GraphUtility.h:23
Point
a custom point class
Definition
test_p2r.cpp:23
Point::y
void y(value_type v)
set y coordinate
Definition
test_uint64.cpp:47
Point::value_type
int value_type
coordinate type
Definition
test_p2r.cpp:25
Point::m_x
value_type m_x
x coordinate
Definition
test_p2r.cpp:27
Point::y
value_type const & y() const
access y coordinate
Definition
test_uint64.cpp:39
Point::x
value_type const & x() const
access x coordinate
Definition
test_uint64.cpp:34
Point::m_y
value_type m_y
y coordinate
Definition
test_p2r.cpp:29
Point::x
void x(value_type v)
set x coordinate
Definition
test_uint64.cpp:43
Rectangle
a custom rectangle class
Definition
test_p2r.cpp:111
Rectangle::m_yl
value_type m_yl
bottom
Definition
test_p2r.cpp:118
Rectangle::xh
void xh(value_type v)
set right coordinate
Definition
test_uint64.cpp:158
Rectangle::m_yh
value_type m_yh
top
Definition
test_p2r.cpp:122
Rectangle::yh
value_type const & yh() const
access top coordinate
Definition
test_uint64.cpp:143
Rectangle::yh
void yh(value_type v)
set top coordinate
Definition
test_uint64.cpp:163
Rectangle::yl
void yl(value_type v)
set bottom coordinate
Definition
test_uint64.cpp:153
Rectangle::value_type
int value_type
coordinate type
Definition
test_p2r.cpp:113
Rectangle::xl
void xl(value_type v)
set left coordinate
Definition
test_uint64.cpp:148
Rectangle::m_xh
value_type m_xh
right
Definition
test_p2r.cpp:120
Rectangle::yl
value_type const & yl() const
access bottom coordinate
Definition
test_uint64.cpp:133
Rectangle::xl
value_type const & xl() const
access left coordinate
Definition
test_uint64.cpp:128
Rectangle::xh
value_type const & xh() const
access right coordinate
Definition
test_uint64.cpp:138
Rectangle::m_xl
value_type m_xl
left
Definition
test_p2r.cpp:116
limbo::geometry::point_traits< Point >::point_type
Point point_type
point type
Definition
test_p2r.cpp:63
limbo::geometry::point_traits< Point >::get
static coordinate_type get(const point_type &point, orientation_2d orient)
access coordinates
Definition
test_uint64.cpp:73
limbo::geometry::point_traits< Point >::construct
static point_type construct(coordinate_type x, coordinate_type y)
construct a point object
Definition
test_uint64.cpp:97
limbo::geometry::point_traits< Point >::coordinate_type
int coordinate_type
coordinate type
Definition
test_p2r.cpp:65
limbo::geometry::point_traits< Point >::set
static void set(point_type &point, orientation_2d orient, coordinate_type value)
set coordinates
Definition
test_uint64.cpp:85
limbo::geometry::point_traits
type traits for point
Definition
Geometry.h:196
limbo::geometry::rectangle_traits< Rectangle >::coordinate_type
int coordinate_type
coordinate type
Definition
test_p2r.cpp:177
limbo::geometry::rectangle_traits< Rectangle >::get
static coordinate_type get(const rectangle_type &rect, direction_2d dir)
access coordinates
Definition
test_uint64.cpp:185
limbo::geometry::rectangle_traits< Rectangle >::rectangle_type
Rectangle rectangle_type
rectangle type
Definition
test_p2r.cpp:175
limbo::geometry::rectangle_traits< Rectangle >::set
static void set(rectangle_type &rect, direction_2d dir, coordinate_type value)
set coordinates
Definition
test_uint64.cpp:202
limbo::geometry::rectangle_traits< Rectangle >::construct
static rectangle_type construct(coordinate_type xl, coordinate_type yl, coordinate_type xh, coordinate_type yh)
construct rectangle
Definition
test_uint64.cpp:218
limbo::geometry::rectangle_traits
type traits for rectangle
Definition
Geometry.h:227
main
int main()
Definition
test_ChromaticNumber.cpp:78
test2
void test2(string const &filename)
test std::list
Definition
test_blibapi.cpp:46
test3
void test3(string const &filename)
test std::set
Definition
test_blibapi.cpp:58
test1
void test1()
test function API
Definition
test_solvers.cpp:11
Generated on
for Limbo by
1.17.0