32#include <boost/iterator/iterator_concepts.hpp>
33#include "DGtal/base/Common.h"
34#include "DGtal/kernel/CPointPredicate.h"
35#include "DGtal/geometry/curves/ArithmeticalDSL.h"
49template <
typename DSL>
54 typedef typename DSL::Point
Point;
56 unsigned int nbok = 0;
62 trace.
info() <<
"constructor, copy, assignement, equality" << std::endl;
79 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
84 if ( dsl.isValid() && dsl3.isValid() && dsl5.isValid() )
87 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
92 trace.
info() <<
"not valid dsl" << std::endl;
97 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
101 trace.
info() <<
"a,b,mu,omega accessors" << std::endl;
103 if ( (dsl.a() == 0)&&(dsl.b() == 1)&&(dsl.mu() == 0)&&(dsl.omega() == 1) )
107 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
113 trace.
info() <<
"remainder, position, tests" << std::endl;
116 if ( (dsl7.isValid())
117 && (dsl7.remainder(
Point(8,5) ) == 0)
118 &&(dsl7.remainder(
Point(16,10) ) == 0)
119 &&(dsl7.remainder(
Point(3,2) ) == -1)
120 &&(dsl7.remainder(
Point(5,3) ) == 1) )
124 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
127 if ( (dsl7.orthogonalPosition(
Point(0,0) ) == 0)
128 &&(dsl7.orthogonalPosition(
Point(8,5) ) == 89)
129 &&(dsl7.orthogonalPosition(
Point(1,0) ) == 8)
130 &&(dsl7.orthogonalPosition(
Point(-1,0) ) == -8) )
134 if ( ( dsl7.before(
Point(0,0),
Point(8,5) ) )
136 &&( dsl7.beforeOrEqual(
Point(0,0),
Point(8,5) ) )
137 &&(!dsl7.beforeOrEqual(
Point(8,5),
Point(0,0) ) )
141 &&( dsl7.beforeOrEqual(
Point(8,5),
Point(8,5) ) )
146 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
149 if ( (dsl7.isInDSL(
Point(0,0) ))
150 &&(dsl7.isInDSL(
Point(16,10) ))
151 &&(dsl7.isInDSL(
Point(5,3) ))
152 &&(!dsl7.isInDSL(
Point(3,2) )) )
156 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
159 if ( (dsl7(
Point(0,0) ))
160 &&(dsl7(
Point(16,10) ))
161 &&(dsl7(
Point(5,3) ))
162 &&(!dsl7(
Point(3,2) ))
163 &&(!dsl7(
Point(-1,0) ))
164 &&(dsl7(
Point(-1,-1) )) )
168 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
172 if ( (dsl.remainder(dsl.shift()) == dsl.omega())
173 && (DSL::toCoordinate(dsl.omega()) == dsl.patternLength()) )
176 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
179 if ( (dsl7.getPoint() ==
Point(0,0))
180 &&(DSL(5,8,dsl7.omega()-1).getPoint() ==
Point(0,0)+dsl.shift())
181 &&(DSL(5,8,dsl7.omega()).getPoint() ==
Point(0,0)+dsl.shift())
182 &&(DSL(5,8,dsl7.omega()+1).getPoint() ==
Point(0,0)+2*dsl.shift())
183 &&(DSL(5,8,-dsl7.omega()+1).getPoint() ==
Point(0,0))
184 &&(DSL(5,8,-dsl7.omega()).getPoint() ==
Point(0,0)-dsl.shift())
185 &&(DSL(5,8,-dsl7.omega()-1).getPoint() ==
Point(0,0)-dsl.shift())
190 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
208template <
typename DSL>
209bool rangeTest(
const DSL& dsl)
211 typedef typename DSL::Point
Point;
213 unsigned int nbok = 0;
219 Point origin = dsl.getPoint();
220 Point first =
Point(origin[0]-dsl.b(), origin[1]-dsl.a());
221 Point last =
Point(first[0]+dsl.b(), first[1]+dsl.a());
222 trace.
info() <<
"from " << first <<
" to " << last << std::endl;
228 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
232 typedef typename DSL::ConstIterator I;
237 for (I it = dsl.begin(first), itEnd = dsl.end(last);
238 ( (it != itEnd)&&(res)&&(c<100) );
241 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") ";
245 trace.
info() <<
" : " << c <<
" points " << std::endl;
248 if ( (res)&&(c == (dsl.omega()+1)) )
252 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
257 typedef typename DSL::ConstReverseIterator I;
262 for (I it = dsl.rbegin(last), itEnd = dsl.rend(first);
263 ( (it != itEnd)&&(res)&&(c<100) );
266 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") ";
270 trace.
info() <<
" : " << c <<
" points " << std::endl;
273 if ( (res)&&(c == (dsl.omega()+1)) )
277 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
282 typedef typename DSL::ConstIterator I;
287 I itBegin = dsl.begin(first);
288 for (I it = itBegin, itEnd = dsl.end(last);
289 ( (it != itEnd)&&(res)&&(c<100) );
292 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") " << it.remainder() <<
", ";
293 I it2 = ( itBegin + c );
294 if ( (it != it2) || ((it2 - itBegin) != c) )
298 trace.
info() <<
" : " << c <<
" points " << std::endl;
305 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
310 for (I it = (itBegin+n), itEnd = itBegin;
311 ( (it!=itEnd)&&(res)&&(c < 100) );
314 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") " << it.remainder() <<
", ";
315 I it2 = ( (itBegin+n) - c );
316 if ( (it != it2) || (((itBegin+n) - it2) != c) )
324 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
336template <
typename DSL>
337bool sameOctantTest(
const DSL& dsl1,
const DSL& dsl2)
340 trace.
info() << dsl1 <<
" " << dsl2 << std::endl;
342 typename DSL::Octant::first_type oc;
344 return dsl1.sameOctant(dsl2,&oc);
352template <
typename DSL>
353typename DSL::Octant testOctant(
const typename DSL::Coordinate & a,
const typename DSL::Coordinate & b)
359 return aDSL.octant();
366int main(
int argc,
char** argv )
370 for (
int i = 0; i < argc; ++i )
375 bool res = mainTest<DGtal::ArithmeticalDSL<DGtal::int32_t> >()
376#ifdef WITH_BIGINTEGER
379 && mainTest<DGtal::NaiveDSL<DGtal::int32_t> >()
387 && rangeTest( DSL(5, 8, 16) )
388 && rangeTest( DSL(8, 5, 14) )
389 && rangeTest( DSL(5, -8, 14) )
390 && rangeTest( DSL(8, -5, 14) )
391 && rangeTest( DSL(-5, 8, 14) )
392 && rangeTest( DSL(-8, 5, 14) )
393 && rangeTest( DSL(-5, -8, 14) )
394 && rangeTest( DSL(-8, -5, 14) )
395 && rangeTest( DSL(1, 0, 14) )
396 && rangeTest( DSL(0, -1, 14) )
397 && rangeTest( DSL(0, 1, 14) )
398 && rangeTest( DSL(-1, 0, 14) )
399 && rangeTest( DSL(1, 1, 14) )
400 && rangeTest( DSL(1, -1, 14) )
401 && rangeTest( DSL(-1, 1, 14) )
402 && rangeTest( DSL(-1, -1, 14) )
411 && rangeTest( DSL(5, 8, -16) )
412 && rangeTest( DSL(8, 5, -17) )
413 && rangeTest( DSL(5, -8, -17) )
414 && rangeTest( DSL(8, -5, -17) )
415 && rangeTest( DSL(-5, 8, -17) )
416 && rangeTest( DSL(-8, 5, -17) )
417 && rangeTest( DSL(-5, -8, -17) )
418 && rangeTest( DSL(-8, -5, -17) )
419 && rangeTest( DSL(1, 0, -17) )
420 && rangeTest( DSL(0, -1, -17) )
421 && rangeTest( DSL(0, 1, -17) )
422 && rangeTest( DSL(-1, 0, -17) )
431 && sameOctantTest(DSL(5,8,16),DSL(1,2,3))==
true
432 && sameOctantTest(DSL(5,8,16),DSL(2,1,3))==
false
433 && sameOctantTest(DSL(2,2,16),DSL(6,3,3))==
true
434 && sameOctantTest(DSL(2,2,16),DSL(3,3,3))==
true
435 && sameOctantTest(DSL(5,-8,16),DSL(0,-2,3))==
true
436 && sameOctantTest(DSL(5,8,16),DSL(-2,1,3))==false
444 typedef DSL::Octant Octant;
449 && testOctant<DSL>(0,0) == Octant(-1,-1)
450 && testOctant<DSL>(0,5) == Octant(0,7)
451 && testOctant<DSL>(0,-5) == Octant(3,4)
452 && testOctant<DSL>(5,0) == Octant(1,2)
453 && testOctant<DSL>(-5,0) == Octant(5,6)
454 && testOctant<DSL>(1,1) == Octant(0,1)
455 && testOctant<DSL>(1,-1) == Octant(2,3)
456 && testOctant<DSL>(-1,1) == Octant(6,7)
457 && testOctant<DSL>(-1,-1) == Octant(4,5)
462#ifdef WITH_BIGINTEGER
465 res = res && rangeTest( DSL(5, 8, -26) ) && rangeTest( DSL(5, 8, 13) )
466 && rangeTest( DSL(5, 8, -17) ) && rangeTest( DSL(5, 8, 11313) );
477 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class represents a naive (resp. standard) digital straight line (DSL), ie....
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Defines a predicate on a point.
Go to http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/RandomAccessTraversal....
Go to http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/ReadableIterator.html.