36 #include "DGtal/base/Common.h"
37 #include "DGtal/kernel/CPointPredicate.h"
38 #include "DGtal/arithmetic/CPositiveIrreducibleFraction.h"
39 #include "DGtal/arithmetic/IntegerComputer.h"
40 #include "DGtal/arithmetic/LighterSternBrocot.h"
41 #include "DGtal/arithmetic/LightSternBrocot.h"
42 #include "DGtal/arithmetic/Pattern.h"
43 #include "DGtal/arithmetic/StandardDSLQ0.h"
44 #include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
48 using namespace DGtal;
54 template <
typename Quotient>
56 equalCFrac(
const std::vector<Quotient> & c1,
const std::vector<Quotient> & c2 )
58 auto s = c1.size() < c2.size() ? c1.size() : c2.size();
63 for (
unsigned int i = 0; i < s; ++i )
65 Quotient q1 = c1[ i ];
66 if ( ( s != c1.size() ) && ( i == s - 1 ) ) q1 += c1.back();
67 Quotient q2 = c2[ i ];
68 if ( ( s != c2.size() ) && ( i == s - 1 ) ) q2 += c2.back();
69 if ( q1 != q2 )
return false;
74 template <
typename SB>
78 typedef typename SB::Quotient Quotient;
79 typedef typename SB::Fraction Fraction;
80 unsigned int nbok = 0;
92 std::vector<Quotient> cf1;
94 Fraction f1 = SB::fraction( p, q );
95 std::vector<Quotient> cf1_bis;
96 f1.getCFrac( cf1_bis );
97 bool ok = equalCFrac<Quotient>( cf1, cf1_bis );
98 trace.
info() <<
" - p / q = " << p <<
" / " << q << std::endl;
102 ++nb; nbok += ok ? 1 : 0;
103 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
106 const auto depth = cf1.size();
107 for (
unsigned int k = 1; k < depth; ++k )
109 std::vector<Quotient> cf1_red;
110 Fraction fr = f1.reduced( k );
111 fr.getCFrac( cf1_red );
112 cf1.resize( depth - k );
113 ok = equalCFrac<Quotient>( cf1, cf1_red );
114 ++nb; nbok += ok ? 1 : 0;
115 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
116 <<
"reduced(" << k <<
")=";
118 std::cerr << std::endl;
126 template <
typename SB>
130 typedef typename SB::Fraction Fraction;
131 unsigned int nbok = 0;
140 Fraction f1 = SB::fraction( p, q );
141 trace.
info() <<
"p / q = " << p <<
" / " << q << std::endl;
145 nbok += ( ( p == f1.p() ) && ( q == f1.q() ) ) ? 1 : 0;
147 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
148 <<
"( ( p == f1.p() ) && ( q == f1.q() ) )"
150 trace.
info() <<
"- nbFractions = " << SB::instance().nbFractions << std::endl;
156 template <
typename SB>
160 typedef typename SB::Quotient Quotient;
161 typedef typename SB::Fraction Fraction;
163 typedef typename MyPattern::Vector2I Vector2I;
164 unsigned int nbok = 0;
168 MyPattern pattern( p*6, q*6 );
172 trace.
beginBlock (
"Testing block: Smallest covering subpatterns of ODD pattern." );
173 MyPattern pat_odd( 5, 12 );
174 trace.
info() <<
"ODD " << pat_odd <<
" " << pat_odd.rE() << endl;
180 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
182 trace.
info() <<
"sub(0,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
183 ++nb; nbok += sp.slope() == SB::fraction( 5, 12 ) ? 1 : 0;
184 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
186 trace.
info() <<
"sub(1,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
187 ++nb; nbok += sp.slope() == SB::fraction( 5, 12 ) ? 1 : 0;
188 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
190 trace.
info() <<
"sub(7,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
191 ++nb; nbok += sp.slope() == SB::fraction( 3, 7 ) ? 1 : 0;
192 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
194 trace.
info() <<
"sub(8,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
195 ++nb; nbok += sp.slope() == SB::fraction( 3, 7 ) ? 1 : 0;
196 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
198 trace.
info() <<
"sub(13,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
199 ++nb; nbok += sp.slope() == SB::fraction( 3, 7 ) ? 1 : 0;
200 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
202 trace.
info() <<
"sub(14,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
203 ++nb; nbok += sp.slope() == SB::fraction( 1, 2 ) ? 1 : 0;
204 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
206 trace.
info() <<
"sub(15,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
207 ++nb; nbok += sp.slope() == SB::fraction( 1, 2 ) ? 1 : 0;
209 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering left Subpatterns." << endl;
212 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
214 trace.
info() <<
"sub(0,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
215 ++nb; nbok += sp.slope() == SB::fraction( 5, 12 ) ? 1 : 0;
216 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
218 trace.
info() <<
"sub(0,15) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
219 ++nb; nbok += sp.slope() == SB::fraction( 5, 12 ) ? 1 : 0;
220 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
222 trace.
info() <<
"sub(0,14) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
223 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 2 ? 1 : 0;
224 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
226 trace.
info() <<
"sub(0,8) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
227 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 2 ? 1 : 0;
228 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
230 trace.
info() <<
"sub(0,7) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
231 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
232 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
234 trace.
info() <<
"sub(0,1) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
235 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
237 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering right Subpatterns." << endl;
240 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
242 trace.
info() <<
"sub(1,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
243 ++nb; nbok += sp.slope() == SB::fraction( 5, 12 ) ? 1 : 0;
244 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
246 trace.
info() <<
"sub(2,14) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
247 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 2 ? 1 : 0;
248 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
250 trace.
info() <<
"sub(7,15) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
251 ++nb; nbok += sp.slope() == SB::fraction( 3, 7 ) && np == 1 ? 1 : 0;
252 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
254 trace.
info() <<
"sub(7,14) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
255 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
256 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
258 trace.
info() <<
"sub(3,6) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
259 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
260 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
262 trace.
info() <<
"sub(6,8) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
263 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 2 ? 1 : 0;
264 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
266 trace.
info() <<
"sub(8,12) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
267 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
268 pat_odd.getSmallestCoveringSubpattern( sp, np, start,
270 trace.
info() <<
"sub(15,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
271 ++nb; nbok += sp.slope() == SB::fraction( 1, 2 ) && np == 1 ? 1 : 0;
273 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering middle Subpatterns." << endl;
277 trace.
beginBlock (
"Testing block: Smallest covering subpatterns of EVEN pattern." );
278 MyPattern pat_even( 12, 17 );
279 trace.
info() <<
"EVEN " << pat_even <<
" " << pat_even.rE() << endl;
282 pat_even.getSmallestCoveringSubpattern( sp, np, start,
284 trace.
info() <<
"sub(0,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
285 ++nb; nbok += sp.slope() == SB::fraction( 12, 17 ) ? 1 : 0;
286 pat_even.getSmallestCoveringSubpattern( sp, np, start,
288 trace.
info() <<
"sub(0,25) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
289 ++nb; nbok += sp.slope() == SB::fraction( 12, 17 ) ? 1 : 0;
290 pat_even.getSmallestCoveringSubpattern( sp, np, start,
292 trace.
info() <<
"sub(0,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
293 ++nb; nbok += sp.slope() == SB::fraction( 7, 10 ) ? 1 : 0;
294 pat_even.getSmallestCoveringSubpattern( sp, np, start,
296 trace.
info() <<
"sub(0,6) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
297 ++nb; nbok += sp.slope() == SB::fraction( 7, 10 ) ? 1 : 0;
298 pat_even.getSmallestCoveringSubpattern( sp, np, start,
300 trace.
info() <<
"sub(0,5) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
301 ++nb; nbok += sp.slope() == SB::fraction( 2, 3 ) ? 1 : 0;
302 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering left Subpatterns." << endl;
305 pat_even.getSmallestCoveringSubpattern( sp, np, start,
307 trace.
info() <<
"sub(4,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
308 ++nb; nbok += sp.slope() == SB::fraction( 12, 17 ) ? 1 : 0;
309 pat_even.getSmallestCoveringSubpattern( sp, np, start,
311 trace.
info() <<
"sub(5,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
312 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 2 ? 1 : 0;
313 pat_even.getSmallestCoveringSubpattern( sp, np, start,
315 trace.
info() <<
"sub(16,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
316 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 2 ? 1 : 0;
317 pat_even.getSmallestCoveringSubpattern( sp, np, start,
319 trace.
info() <<
"sub(17,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
320 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
321 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering right Subpatterns." << endl;
324 pat_even.getSmallestCoveringSubpattern( sp, np, start,
326 trace.
info() <<
"sub(1,27) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
327 ++nb; nbok += sp.slope() == SB::fraction( 12, 17 ) ? 1 : 0;
328 pat_even.getSmallestCoveringSubpattern( sp, np, start,
330 trace.
info() <<
"sub(5,24) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
331 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 2 ? 1 : 0;
332 pat_even.getSmallestCoveringSubpattern( sp, np, start,
334 trace.
info() <<
"sub(4,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
335 ++nb; nbok += sp.slope() == SB::fraction( 7, 10 ) && np == 1 ? 1 : 0;
336 pat_even.getSmallestCoveringSubpattern( sp, np, start,
338 trace.
info() <<
"sub(5,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
339 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
340 pat_even.getSmallestCoveringSubpattern( sp, np, start,
342 trace.
info() <<
"sub(7,12) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
343 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
344 pat_even.getSmallestCoveringSubpattern( sp, np, start,
346 trace.
info() <<
"sub(1,4) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
347 ++nb; nbok += sp.slope() == SB::fraction( 2, 3 ) && np == 1 ? 1 : 0;
348 pat_even.getSmallestCoveringSubpattern( sp, np, start,
350 trace.
info() <<
"sub(18,20) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
351 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
352 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering middle Subpatterns." << endl;
358 trace.
beginBlock (
"Testing block: greatest included subpatterns of ODD pattern." );
359 trace.
info() <<
"ODD " << pat_odd <<
" " << pat_odd.rE() << endl;
362 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
364 trace.
info() <<
"sub(0,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
365 ++nb; nbok += sp.slope() == SB::fraction( 5, 12 ) ? 1 : 0;
366 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
368 trace.
info() <<
"sub(1,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
369 ++nb; nbok += sp.slope() == SB::fraction( 3, 7 ) ? 1 : 0;
370 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
372 trace.
info() <<
"sub(7,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
373 ++nb; nbok += sp.slope() == SB::fraction( 3, 7 ) ? 1 : 0;
374 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
376 trace.
info() <<
"sub(8,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
377 ++nb; nbok += sp.slope() == SB::fraction( 1, 2 ) ? 1 : 0;
378 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
380 trace.
info() <<
"sub(13,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
381 ++nb; nbok += sp.slope() == SB::fraction( 1, 2 ) ? 1 : 0;
382 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
384 trace.
info() <<
"sub(14,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
385 ++nb; nbok += sp.slope() == SB::fraction( 1, 2 ) ? 1 : 0;
386 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
388 trace.
info() <<
"sub(15,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
389 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
391 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering left Subpatterns." << endl;
394 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
396 trace.
info() <<
"sub(0,15) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
397 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 2 ? 1 : 0;
398 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
400 trace.
info() <<
"sub(0,14) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
401 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 2 ? 1 : 0;
402 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
404 trace.
info() <<
"sub(0,13) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
405 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
406 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
408 trace.
info() <<
"sub(0,7) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
409 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
410 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
412 trace.
info() <<
"sub(0,6) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
413 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
414 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
416 trace.
info() <<
"sub(0,1) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
417 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
419 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering right Subpatterns." << endl;
422 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
424 trace.
info() <<
"sub(1,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
425 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) ? 1 : 0;
426 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
428 trace.
info() <<
"sub(2,14) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
429 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
430 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
432 trace.
info() <<
"sub(7,15) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
433 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
434 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
436 trace.
info() <<
"sub(7,14) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
437 ++nb; nbok += sp.slope() == SB::fraction( 2, 5 ) && np == 1 ? 1 : 0;
438 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
440 trace.
info() <<
"sub(3,6) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
441 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
442 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
444 trace.
info() <<
"sub(6,8) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
445 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
446 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
448 trace.
info() <<
"sub(8,12) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
449 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
450 pat_odd.getGreatestIncludedSubpattern( sp, np, start,
452 trace.
info() <<
"sub(15,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
453 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
455 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering middle Subpatterns." << endl;
459 trace.
beginBlock (
"Testing block: Greatest included subpatterns of EVEN pattern." );
460 trace.
info() <<
"EVEN " << pat_even <<
" " << pat_even.rE() << endl;
463 pat_even.getGreatestIncludedSubpattern( sp, np, start,
465 trace.
info() <<
"sub(0,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
466 ++nb; nbok += sp.slope() == SB::fraction( 12, 17 ) ? 1 : 0;
467 pat_even.getGreatestIncludedSubpattern( sp, np, start,
469 trace.
info() <<
"sub(0,25) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
470 ++nb; nbok += sp.slope() == SB::fraction( 7, 10 ) ? 1 : 0;
471 pat_even.getGreatestIncludedSubpattern( sp, np, start,
473 trace.
info() <<
"sub(0,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
474 ++nb; nbok += sp.slope() == SB::fraction( 7, 10 ) ? 1 : 0;
475 pat_even.getGreatestIncludedSubpattern( sp, np, start,
477 trace.
info() <<
"sub(0,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
478 ++nb; nbok += sp.slope() == SB::fraction( 2, 3 ) ? 1 : 0;
479 pat_even.getGreatestIncludedSubpattern( sp, np, start,
481 trace.
info() <<
"sub(0,6) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
482 ++nb; nbok += sp.slope() == SB::fraction( 2, 3 ) ? 1 : 0;
483 pat_even.getGreatestIncludedSubpattern( sp, np, start,
485 trace.
info() <<
"sub(0,5) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
486 ++nb; nbok += sp.slope() == SB::fraction( 2, 3 ) ? 1 : 0;
487 pat_even.getGreatestIncludedSubpattern( sp, np, start,
489 trace.
info() <<
"sub(0,4) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
490 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
491 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering left Subpatterns." << endl;
494 pat_even.getGreatestIncludedSubpattern( sp, np, start,
496 trace.
info() <<
"sub(4,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
497 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 2 ? 1 : 0;
498 pat_even.getGreatestIncludedSubpattern( sp, np, start,
500 trace.
info() <<
"sub(5,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
501 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 2 ? 1 : 0;
502 pat_even.getGreatestIncludedSubpattern( sp, np, start,
504 trace.
info() <<
"sub(16,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
505 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
506 pat_even.getGreatestIncludedSubpattern( sp, np, start,
508 trace.
info() <<
"sub(17,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
509 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
510 pat_even.getGreatestIncludedSubpattern( sp, np, start,
512 trace.
info() <<
"sub(18,29) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
513 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
514 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering right Subpatterns." << endl;
517 pat_even.getGreatestIncludedSubpattern( sp, np, start,
519 trace.
info() <<
"sub(1,27) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
520 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
521 pat_even.getGreatestIncludedSubpattern( sp, np, start,
523 trace.
info() <<
"sub(5,24) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
524 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
525 pat_even.getGreatestIncludedSubpattern( sp, np, start,
527 trace.
info() <<
"sub(4,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
528 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
529 pat_even.getGreatestIncludedSubpattern( sp, np, start,
531 trace.
info() <<
"sub(5,17) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
532 ++nb; nbok += sp.slope() == SB::fraction( 5, 7 ) && np == 1 ? 1 : 0;
533 pat_even.getGreatestIncludedSubpattern( sp, np, start,
535 trace.
info() <<
"sub(5,16) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
536 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
537 pat_even.getGreatestIncludedSubpattern( sp, np, start,
539 trace.
info() <<
"sub(1,4) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
540 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
541 pat_even.getGreatestIncludedSubpattern( sp, np, start,
543 trace.
info() <<
"sub(18,20) = " << sp <<
" " << sp.rE() <<
"^" << np << endl;
544 ++nb; nbok += sp.slope() == Fraction() ? 1 : 0;
545 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") covering middle Subpatterns." << endl;
548 trace.
info() <<
"Odd pattern " << pat_odd << endl;
549 trace.
info() <<
" U(0)=" << pat_odd.U( 0 )
550 <<
" L(0)=" << pat_odd.L( 0 )
551 <<
" U(1)=" << pat_odd.U( 1 )
552 <<
" L(1)=" << pat_odd.L( 1 ) << endl;
554 trace.
info() <<
"Even pattern " << pat_even << endl;
555 trace.
info() <<
" U(0)=" << pat_even.U( 0 )
556 <<
" L(0)=" << pat_even.L( 0 )
557 <<
" U(1)=" << pat_even.U( 1 )
558 <<
" L(1)=" << pat_even.L( 1 ) << endl;
563 template <
typename Fraction>
569 typedef typename DSL::Vector2I Vector2I;
572 unsigned int nbok = 0;
575 for (
Integer mu = -5; mu < 30; ++mu )
581 trace.
info() <<
"- U=" << U <<
" r(U)=" << D1.r( U )
582 <<
", L=" <<
L <<
" r(L)=" << D1.r(
L ) << endl;
583 ++nb; nbok += D1.r( U ) == D1.mu() ? 1 : 0;
584 ++nb; nbok += D1.r(
L ) == D1.mup() ? 1 : 0;
588 for (
Integer x = -5; x < 30; ++x )
590 Point P = D2.lowestY( x );
591 ++nb; nbok += D2( P ) && ( ! D2( P - Vector2I(0,1) ) ) ? 1 : 0;
592 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
593 <<
"D2(P) && ! D2(P-y) P=" << P <<
" r(P)=" << D2.r( P )
595 P = D2.uppermostY( x );
596 ++nb; nbok += D2( P ) && ( ! D2( P + Vector2I(0,1) ) ) ? 1 : 0;
597 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
598 <<
"D2(P) && ! D2(P+y) P=" << P <<
" r(P)=" << D2.r( P )
601 for (
Integer y = -5; y < 30; ++y )
603 Point P = D2.lowestX( y );
604 ++nb; nbok += D2( P ) && ( ! D2( P - Vector2I(1,0) ) ) ? 1 : 0;
605 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
606 <<
"D2(P) && ! D2(P-x) P=" << P <<
" r(P)=" << D2.r( P )
608 P = D2.uppermostX( y );
609 ++nb; nbok += D2( P ) && ( ! D2( P + Vector2I(1,0) ) ) ? 1 : 0;
610 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
611 <<
"D2(P) && ! D2(P+x) P=" << P <<
" r(P)=" << D2.r( P )
618 template <
typename DSL>
627 DSL S = D.reversedSmartDSS( A, B );
632 while ( ( dss.end() != it_end )
633 && ( dss.extendFront() ) ) {}
634 bool ok = S.a() == dss.a()
636 && S.mu() == dss.mu();
639 trace.
info() <<
"-------------------------------------------------------"
642 <<
" " << D.pattern().rE() << endl;
643 trace.
info() <<
"S(" << A <<
"," << B <<
") = "
644 << S <<
" " << S.pattern() << endl;
645 trace.
info() <<
"ArithDSS = " << dss << std::endl;
655 template <
typename Fraction>
662 unsigned int nbok = 0;
666 for (
unsigned int i = 0; i < 100; ++i )
668 Integer a( rand() % 12000 + 1 );
669 Integer b( rand() % 12000 + 1 );
670 if ( ic.
gcd( a, b ) == 1 )
673 <<
" Test DSL has slope " << a <<
"/" << b << std::endl;
674 for (
Integer mu = 0; mu < 5; ++mu )
676 DSL D( a, b, rand() % 10000 );
677 for (
Integer x = 0; x < 10; ++x )
680 Integer x2 = x1 + 1 + ( rand() % 1000 );
681 Point A = D.lowestY( x1 );
682 Point B = D.lowestY( x2 );
683 ++nb; nbok += checkSubStandardDSLQ0<DSL>( D, A, B ) ? 1 : 0;
685 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") correct reversedSmartDSS."
687 if ( nbok != nb ) assert(
false);
692 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") correct reversedSmartDSS."
704 unsigned int nbtests = 10;
705 unsigned int nbok = 0;
710 for (
unsigned int i = 0; i < nbtests; ++i )
712 nbok += testInitFraction<SB>() ? 1 : 0;
715 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") init fractions." << endl;
719 for (
unsigned int i = 0; i < nbtests; ++i )
721 nbok += testReducedFraction<SB>() ? 1 : 0;
724 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") reduced fractions." << endl;
728 trace.
info() <<
"- nbFractions = " << SB::instance().nbFractions << endl;
735 template <
typename SB>
738 typedef typename SB::Quotient Quotient;
740 typedef typename SB::Fraction Fraction;
743 std::vector<Quotient> quotients;
744 std::vector<Quotient> qcfrac;
745 std::back_insert_iterator< Fraction > itout =
746 std::back_inserter( f );
747 unsigned int size = ( rand() % 20 ) + 10;
748 for (
unsigned int i = 0; i < size; ++i )
750 Quotient q = ( i == 0 )
752 : ( rand() % 5 ) + 1;
753 *itout++ = std::make_pair( q, (Quotient) i );
754 quotients.push_back( q );
758 qcfrac.push_back( (*it).first );
762 trace.
info() << ( ok ?
"(OK)" :
"(ERR)" );
763 for (
unsigned int i = 0; i < quotients.size(); ++i )
764 std::cerr <<
" " << quotients[ i ];
767 f.selfDisplay( std::cerr );
772 template <
typename SB>
775 unsigned int nbtests = 1000;
776 unsigned int nbok = 0;
779 for (
unsigned int i = 0; i < nbtests; ++i )
781 ++nb; nbok += testContinuedFraction<SB>() ? 1 : 0;
782 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
783 <<
" continued fractions." << std::endl;
789 template <
typename LSB>
793 typedef typename LSB::Fraction Fraction;
796 std::cerr <<
"SB = " << lsb << std::endl;
799 std::cerr <<
"pat = " << pat.
rE() <<
" depth=" << pat.
slope().k()
802 std::cerr <<
"spat= " << spat.
rE() <<
" depth=" << spat.
slope().k()
805 std::cerr <<
"sspat= " << sspat.
rE() <<
" depth=" << sspat.
slope().k()
810 std::cerr <<
"pat = " << pat.
rE() <<
" depth=" << pat.
slope().k()
813 std::cerr <<
"spat= " << spat.
rE() <<
" depth=" << spat.
slope().k()
816 std::cerr <<
"sspat= " << sspat.
rE() <<
" depth=" << sspat.
slope().k()
825 template <
typename SB>
829 typedef typename SB::Fraction Fraction;
834 DSL D(1077,1495,6081);
839 ASSERT( D( A ) &&
"Point A belongs to D." );
840 ASSERT( D( B ) &&
"Point A belongs to D." );
841 DSL D1 = D.reversedSmartDSS(A,B);
842 std::cerr << D1 << std::endl;
843 return D1.slope() == Fraction( 1, 1 );
855 typedef SB::Fraction Fraction;
861 testTrivial<SB>(
"LrSB" );
862 testTrivial<SB2>(
"LSB" );
863 testTrivial<SB3>(
"SB" );
868 && testSubStandardDSLQ0<Fraction>()
869 && testContinuedFractions<SB>()
870 && testAncestors<SB>();
871 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
ConstIterator begin() const
Integer getCFrac(std::vector< Integer > "ients, IntegerParamType a, IntegerParamType b) const
Integer gcd(IntegerParamType a, IntegerParamType b) const
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Pattern previousPattern() const
Aim: Represents a digital straight line with slope in the first quadrant (Q0: x >= 0,...
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
void beginBlock(const std::string &keyword="")
Point::Coordinate Integer
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
boost::int32_t int32_t
signed 32-bit integer.
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Aim: The traits class for all models of Cinteger.
Aim: Defines a predicate on a point.
Aim: Defines positive irreducible fractions, i.e. fraction p/q, p and q non-negative integers,...
void display(ostream &out, const AContainer &C)
bool testSubStandardDSLQ0()
bool testReducedFraction()
bool checkSubStandardDSLQ0(const DSL &D, const typename DSL::Point &A, const typename DSL::Point &B)
bool testLighterSternBrocot()
bool testContinuedFraction()
bool testContinuedFractions()
bool testTrivial(const string &lsb)
bool equalCFrac(const std::vector< Quotient > &c1, const std::vector< Quotient > &c2)