DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testPolarPointComparatorBy2x2DetComputer.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
34
#include "DGtal/kernel/PointVector.h"
35
#include "DGtal/geometry/tools/PolarPointComparatorBy2x2DetComputer.h"
37
38
using namespace
std
;
39
using namespace
DGtal
;
40
42
// Functions for testing class PolarPointComparatorBy2x2DetComputer.
44
47
bool
testPolarPointComparatorBy2x2DetComputer
()
48
{
49
unsigned
int
nbok = 0;
50
unsigned
int
nb = 0;
51
52
trace
.
beginBlock
(
"Testing block ..."
);
53
54
typedef
PointVector<2,DGtal::int32_t>
Point
;
55
56
Point
origin(0,0);
57
functors::PolarPointComparatorBy2x2DetComputer<Point>
comp( origin );
58
trace
.
info
() << comp << endl;
59
60
//same half-plane
61
trace
.
info
() <<
"same half-plane"
<< endl;
62
if
( comp(
Point
(2,1),
Point
(1,2) ) )
63
nbok++;
64
nb++;
65
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
66
67
if
( ! comp(
Point
(1,2),
Point
(2,1) ) )
68
nbok++;
69
nb++;
70
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
71
72
if
( comp(
Point
(2,1),
Point
(-1,2) ) )
73
nbok++;
74
nb++;
75
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
76
77
if
( comp(
Point
(1,-2),
Point
(2,-1) ) )
78
nbok++;
79
nb++;
80
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
81
82
//different half-plane
83
trace
.
info
() <<
"different half-plane"
<< endl;
84
if
( comp(
Point
(1,2),
Point
(2,-1) ) )
85
nbok++;
86
nb++;
87
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
88
89
if
( ! comp(
Point
(2,-1),
Point
(1,2) ) )
90
nbok++;
91
nb++;
92
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
93
94
//y-coordinate equal to 0
95
trace
.
info
() <<
"y-coordinate == 0"
<< endl;
96
if
( comp(
Point
(1,0),
Point
(3,3) ) )
97
nbok++;
98
nb++;
99
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
100
101
if
( ! comp(
Point
(3,3),
Point
(1,0) ) )
102
nbok++;
103
nb++;
104
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
105
106
if
( comp(
Point
(3,3),
Point
(-1,0) ) )
107
nbok++;
108
nb++;
109
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
110
111
if
( comp(
Point
(1,0),
Point
(3,-3) ) )
112
nbok++;
113
nb++;
114
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
115
116
//aligned
117
trace
.
info
() <<
"aligned points"
<< endl;
118
if
( ! comp(
Point
(3,3),
Point
(1,1) ) )
119
nbok++;
120
nb++;
121
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
122
123
if
( comp(
Point
(1,1),
Point
(3,3) ) )
124
nbok++;
125
nb++;
126
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
127
128
if
( ! comp(
Point
(-3,-3),
Point
(1,1) ) )
129
nbok++;
130
nb++;
131
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
132
133
//y-coordinate equal to 0 AND aligned
134
trace
.
info
() <<
"aligned points on the horizontal axis"
<< endl;
135
if
( comp(
Point
(1,0),
Point
(5,0) ) )
136
nbok++;
137
nb++;
138
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
139
140
if
( ! comp(
Point
(5,0),
Point
(1,0) ) )
141
nbok++;
142
nb++;
143
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
144
145
if
( comp(
Point
(1,0),
Point
(-5,0) ) )
146
nbok++;
147
nb++;
148
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
149
150
if
( comp(
Point
(5,0),
Point
(-5,0) ) )
151
nbok++;
152
nb++;
153
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
154
155
if
( ! comp(
Point
(-5,0),
Point
(5,0) ) )
156
nbok++;
157
nb++;
158
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
159
160
if
( comp(
Point
(-1,0),
Point
(-5,0) ) )
161
nbok++;
162
nb++;
163
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
164
165
//degenerated
166
trace
.
info
() <<
"point equality"
<< endl;
167
if
( comp(
Point
(0,0),
Point
(3,3) ) )
168
nbok++;
169
nb++;
170
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
171
172
if
( comp(
Point
(0,0),
Point
(-3,-3) ) )
173
nbok++;
174
nb++;
175
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
176
177
if
( ! comp(
Point
(2,1),
Point
(2,1) ) )
178
nbok++;
179
nb++;
180
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
181
182
trace
.
endBlock
();
183
184
return
nbok == nb;
185
}
186
190
bool
testSort
()
191
{
192
unsigned
int
nbok = 0;
193
unsigned
int
nb = 0;
194
195
trace
.
beginBlock
(
"Testing block ..."
);
196
197
typedef
PointVector<2,DGtal::int32_t>
Point
;
198
Point
origin(0,0);
199
200
std::vector<Point>
g
, v;
201
//data
202
v.push_back(
Point
(3,4) );
203
v.push_back(
Point
(5,0) );
204
v.push_back(
Point
(4,3) );
205
v.push_back(
Point
(0,5) );
206
v.push_back(
Point
(-3,-4) );
207
v.push_back(
Point
(-5,0) );
208
v.push_back(
Point
(-4,-3) );
209
v.push_back(
Point
(0,-5) );
210
v.push_back(
Point
(3,-4) );
211
v.push_back(
Point
(4,-3) );
212
v.push_back(
Point
(-3,4) );
213
v.push_back(
Point
(-4,3) );
214
//ground truth
215
g
.push_back(
Point
(5,0) );
216
g
.push_back(
Point
(4,3) );
217
g
.push_back(
Point
(3,4) );
218
g
.push_back(
Point
(0,5) );
219
g
.push_back(
Point
(-3,4) );
220
g
.push_back(
Point
(-4,3) );
221
g
.push_back(
Point
(-5,0) );
222
g
.push_back(
Point
(-4,-3) );
223
g
.push_back(
Point
(-3,-4) );
224
g
.push_back(
Point
(0,-5) );
225
g
.push_back(
Point
(3,-4) );
226
g
.push_back(
Point
(4,-3) );
227
228
//sort
229
functors::PolarPointComparatorBy2x2DetComputer<Point>
comp( origin );
230
std::sort(v.begin(), v.end(), comp);
231
std::copy(v.begin(), v.end(), ostream_iterator<Point>( std::cout,
" "
) );
232
std::cout << std::endl;
233
234
if
( std::equal(v.begin(), v.end(),
g
.begin()) )
235
nbok++;
236
nb++;
237
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
238
239
//with a different pole
240
comp.
setPole
(
Point
(5,0) );
241
std::sort(v.begin(), v.end(), comp);
242
std::copy(v.begin(), v.end(), ostream_iterator<Point>( std::cout,
" "
) );
243
std::cout << std::endl;
244
245
if
( std::equal(v.begin(), v.end(),
g
.begin()) )
246
nbok++;
247
nb++;
248
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< endl;
249
250
trace
.
endBlock
();
251
252
return
nbok == nb;
253
}
254
256
// Standard services - public :
257
258
int
main
(
int
argc,
char
** argv )
259
{
260
trace
.
beginBlock
(
"Testing class PolarPointComparatorBy2x2DetComputer"
);
261
trace
.
info
() <<
"Args:"
;
262
for
(
int
i = 0; i < argc; ++i )
263
trace
.
info
() <<
" "
<< argv[ i ];
264
trace
.
info
() << endl;
265
266
bool
res =
testPolarPointComparatorBy2x2DetComputer
()
267
&&
testSort
();
268
269
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
270
trace
.
endBlock
();
271
return
res ? 0 : 1;
272
}
273
// //
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::functors::PolarPointComparatorBy2x2DetComputer
Aim: Class that implements a binary point predicate, which is able to compare the position of two giv...
Definition
PolarPointComparatorBy2x2DetComputer.h:80
DGtal::functors::PolarPointComparatorBy2x2DetComputer::setPole
void setPole(const Point &aPole)
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
g
std::mt19937 g(rd())
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testSort
bool testSort()
Definition
testPolarPointComparatorBy2x2DetComputer.cpp:190
testPolarPointComparatorBy2x2DetComputer
bool testPolarPointComparatorBy2x2DetComputer()
Definition
testPolarPointComparatorBy2x2DetComputer.cpp:47
tests
geometry
tools
testPolarPointComparatorBy2x2DetComputer.cpp
Generated on
for DGtal by
1.18.0