32 #include "DGtal/base/Common.h"
34 #include "DGtal/geometry/tools/Hull2DHelpers.h"
36 #include "DGtal/geometry/tools/determinant/PredicateFromOrientationFunctor2.h"
37 #include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
41 using namespace DGtal;
52 unsigned int nbok = 0;
56 typedef std::vector<Point> Container;
60 OrientationFunctor orientationFunctor;
62 predicate( orientationFunctor );
65 using namespace functions::Hull2D;
71 Container input, output;
72 openGrahamScan( input.begin(), input.end(), back_inserter( output ), predicate );
73 if (output.size() == 0)
76 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
81 Container input, output;
82 input.push_back(
Point(1,1) );
83 openGrahamScan( input.begin(), input.end(), back_inserter( output ), predicate );
84 if ( (output.size() == 1) &&
85 (output.back() ==
Point(1,1)) )
88 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
93 Container input, output;
94 input.push_back(
Point(1,1) );
95 input.push_back(
Point(1,2) );
96 openGrahamScan( input.begin(), input.end(), back_inserter( output ), predicate );
97 if ( (output.size() == 2) &&
98 (output.at(0) ==
Point(1,1)) &&
99 (output.at(1) ==
Point(1,2)) )
102 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
107 Container input, output;
110 input.push_back(
Point(0,0) );
111 input.push_back(
Point(5,0) );
112 input.push_back(
Point(10,5) );
113 copy( input.begin(), input.end(), ostream_iterator<Point>( cout,
" " ) );
116 openGrahamScan( input.begin(), input.end(), back_inserter( output ), predicate );
118 copy( output.begin(), output.end(), ostream_iterator<Point>( cout,
" " ) );
121 if ( (output.size() == 3) &&
122 (output.at(0) ==
Point(0,0)) &&
123 (output.at(1) ==
Point(5,0)) &&
124 (output.at(2) ==
Point(10,5)) )
127 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
131 input.at(2) =
Point(10,-5);
132 copy( input.begin(), input.end(), ostream_iterator<Point>( cout,
" " ) );
135 openGrahamScan( input.begin(), input.end(), back_inserter( output ), predicate );
137 copy( output.begin(), output.end(), ostream_iterator<Point>( cout,
" " ) );
140 if ( (output.size() == 2) &&
141 (output.at(0) ==
Point(0,0)) &&
142 (output.at(1) ==
Point(10,-5)) )
145 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
148 trace.
info() <<
"several points" << endl;
150 Container input, output;
151 input.push_back(
Point(0,5) );
152 input.push_back(
Point(0,0) );
153 input.push_back(
Point(1,1) );
154 input.push_back(
Point(2,4) );
155 input.push_back(
Point(3,9) );
156 input.push_back(
Point(4,16) );
157 input.push_back(
Point(5,0) );
159 openGrahamScan( (input.begin()+1), input.end(), back_inserter( output ), predicate );
160 if ( (output.size() == 2) &&
161 (output.at(0) ==
Point(0,0)) &&
162 (output.at(1) ==
Point(5,0)) )
165 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
168 openGrahamScan( input.begin(), input.end(), back_inserter( output ), predicate );
169 if ( (output.size() == 3) &&
170 (output.at(0) ==
Point(0,5)) &&
171 (output.at(1) ==
Point(0,0)) &&
172 (output.at(2) ==
Point(5,0)) )
175 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
185 Container input, output;
186 closedGrahamScanFromVertex( input.begin(), input.end(), back_inserter( output ), predicate );
187 if (output.size() == 0)
190 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
195 Container input, output;
196 input.push_back(
Point(1,1) );
197 closedGrahamScanFromVertex( input.begin(), input.end(), back_inserter( output ), predicate );
198 if ( (output.size() == 1) &&
199 (output.back() ==
Point(1,1)) )
202 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
207 Container input, output;
208 input.push_back(
Point(1,1) );
209 input.push_back(
Point(1,2) );
210 closedGrahamScanFromVertex( input.begin(), input.end(), back_inserter( output ), predicate );
211 if ( (output.size() == 2) &&
212 (output.at(0) ==
Point(1,1)) &&
213 (output.at(1) ==
Point(1,2)) )
216 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
222 Container input, output;
223 input.push_back(
Point(0,0) );
224 input.push_back(
Point(5,0) );
225 input.push_back(
Point(10,5) );
226 copy( input.begin(), input.end(), ostream_iterator<Point>( cout,
" " ) );
229 closedGrahamScanFromVertex( input.begin(), input.end(), back_inserter( output ), predicate );
231 copy( output.begin(), output.end(), ostream_iterator<Point>( cout,
" " ) );
234 if ( (output.size() == 3) &&
235 (output.at(0) ==
Point(0,0)) &&
236 (output.at(1) ==
Point(5,0)) &&
237 (output.at(2) ==
Point(10,5)) )
240 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
243 trace.
info() <<
"taking into account the first point" << endl;
245 Container input, output;
246 input.push_back(
Point(0,-1) );
247 input.push_back(
Point(1,0) );
248 input.push_back(
Point(1,5) );
249 input.push_back(
Point(-5,5) );
250 input.push_back(
Point(-5,0) );
251 input.push_back(
Point(-2,1) );
252 copy( input.begin(), input.end(), ostream_iterator<Point>( cout,
" " ) );
255 closedGrahamScanFromVertex( input.begin(), input.end(), back_inserter( output ), predicate );
257 copy( output.begin(), output.end(), ostream_iterator<Point>( cout,
" " ) );
260 if ( (output.size() == 5) &&
261 (output.at(0) ==
Point(0,-1)) &&
262 (output.at(1) ==
Point(1,0)) &&
263 (output.at(2) ==
Point(1,5)) &&
264 (output.at(3) ==
Point(-5,5))&&
265 (output.at(4) ==
Point(-5,0)) )
268 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
277 Container input, output;
278 closedGrahamScanFromAnyPoint( input.begin(), input.end(), back_inserter( output ), predicate );
279 if (output.size() == 0)
282 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
287 Container input, output;
288 input.push_back(
Point(1,1) );
289 closedGrahamScanFromAnyPoint( input.begin(), input.end(), back_inserter( output ), predicate );
290 if ( (output.size() == 1) &&
291 (output.back() ==
Point(1,1)) )
294 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
299 Container input, output;
300 input.push_back(
Point(1,1) );
301 input.push_back(
Point(1,2) );
302 closedGrahamScanFromAnyPoint( input.begin(), input.end(), back_inserter( output ), predicate );
303 if ( (output.size() == 2) &&
304 (output.at(0) ==
Point(1,1)) &&
305 (output.at(1) ==
Point(1,2)) )
308 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
314 Container input, output;
315 input.push_back(
Point(0,0) );
316 input.push_back(
Point(5,0) );
317 input.push_back(
Point(10,5) );
318 copy( input.begin(), input.end(), ostream_iterator<Point>( cout,
" " ) );
321 closedGrahamScanFromAnyPoint( input.begin(), input.end(), back_inserter( output ), predicate );
323 copy( output.begin(), output.end(), ostream_iterator<Point>( cout,
" " ) );
326 if ( (output.size() == 3) &&
327 (output.at(0) ==
Point(0,0)) &&
328 (output.at(1) ==
Point(5,0)) &&
329 (output.at(2) ==
Point(10,5)) )
332 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
335 trace.
info() <<
"taking into account the first point" << endl;
337 Container input, output;
338 input.push_back(
Point(3,2) );
339 input.push_back(
Point(2,2) );
340 input.push_back(
Point(2,1) );
341 input.push_back(
Point(1,1) );
342 input.push_back(
Point(0,1) );
343 input.push_back(
Point(0,0) );
344 input.push_back(
Point(9,0) );
345 input.push_back(
Point(9,6) );
346 input.push_back(
Point(8,6) );
347 input.push_back(
Point(8,5) );
348 input.push_back(
Point(7,5) );
349 input.push_back(
Point(7,4) );
350 input.push_back(
Point(6,4) );
351 input.push_back(
Point(5,4) );
352 input.push_back(
Point(5,3) );
353 input.push_back(
Point(4,3) );
354 input.push_back(
Point(4,2) );
356 copy( input.begin(), input.end(), ostream_iterator<Point>( cout,
" " ) );
359 closedGrahamScanFromAnyPoint( input.begin(), input.end(), back_inserter( output ), predicate );
361 copy( output.begin(), output.end(), ostream_iterator<Point>( cout,
" " ) );
364 if ( (output.size() == 5) &&
365 (output.at(0) ==
Point(0,0)) &&
366 (output.at(1) ==
Point(9,0)) &&
367 (output.at(2) ==
Point(9,6)) &&
368 (output.at(3) ==
Point(8,6)) &&
369 (output.at(4) ==
Point(0,1)) )
372 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
383 int main(
int argc,
char** argv )
387 for (
int i = 0; i < argc; ++i )
392 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: Small adapter to models of COrientationFunctor2. It is a model of concepts::CPointPredicate....
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
bool testHullFunctions2D()
int main(int argc, char **argv)