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;
61 trace.
info() <<
"constructor, copy, assignment, equality" << std::endl;
78 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
83 if ( dsl.isValid() && dsl3.isValid() && dsl5.isValid() )
86 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
91 trace.
info() <<
"not valid dsl" << std::endl;
96 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
100 trace.
info() <<
"a,b,mu,omega accessors" << std::endl;
102 if ( (dsl.a() == 0)&&(dsl.b() == 1)&&(dsl.mu() == 0)&&(dsl.omega() == 1) )
106 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
112 trace.
info() <<
"remainder, position, tests" << std::endl;
115 if ( (dsl7.isValid())
116 && (dsl7.remainder(
Point(8,5) ) == 0)
117 &&(dsl7.remainder(
Point(16,10) ) == 0)
118 &&(dsl7.remainder(
Point(3,2) ) == -1)
119 &&(dsl7.remainder(
Point(5,3) ) == 1) )
123 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
126 if ( (dsl7.orthogonalPosition(
Point(0,0) ) == 0)
127 &&(dsl7.orthogonalPosition(
Point(8,5) ) == 89)
128 &&(dsl7.orthogonalPosition(
Point(1,0) ) == 8)
129 &&(dsl7.orthogonalPosition(
Point(-1,0) ) == -8) )
133 if ( ( dsl7.before(
Point(0,0),
Point(8,5) ) )
135 &&( dsl7.beforeOrEqual(
Point(0,0),
Point(8,5) ) )
136 &&(!dsl7.beforeOrEqual(
Point(8,5),
Point(0,0) ) )
140 &&( dsl7.beforeOrEqual(
Point(8,5),
Point(8,5) ) )
145 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
148 if ( (dsl7.isInDSL(
Point(0,0) ))
149 &&(dsl7.isInDSL(
Point(16,10) ))
150 &&(dsl7.isInDSL(
Point(5,3) ))
151 &&(!dsl7.isInDSL(
Point(3,2) )) )
155 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
158 if ( (dsl7(
Point(0,0) ))
159 &&(dsl7(
Point(16,10) ))
160 &&(dsl7(
Point(5,3) ))
161 &&(!dsl7(
Point(3,2) ))
162 &&(!dsl7(
Point(-1,0) ))
163 &&(dsl7(
Point(-1,-1) )) )
167 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
171 if ( (dsl.remainder(dsl.shift()) == dsl.omega())
172 && (DSL::toCoordinate(dsl.omega()) == dsl.patternLength()) )
175 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
178 if ( (dsl7.getPoint() ==
Point(0,0))
179 &&(DSL(5,8,dsl7.omega()-1).getPoint() ==
Point(0,0)+dsl.shift())
180 &&(DSL(5,8,dsl7.omega()).getPoint() ==
Point(0,0)+dsl.shift())
181 &&(DSL(5,8,dsl7.omega()+1).getPoint() ==
Point(0,0)+2*dsl.shift())
182 &&(DSL(5,8,-dsl7.omega()+1).getPoint() ==
Point(0,0))
183 &&(DSL(5,8,-dsl7.omega()).getPoint() ==
Point(0,0)-dsl.shift())
184 &&(DSL(5,8,-dsl7.omega()-1).getPoint() ==
Point(0,0)-dsl.shift())
189 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
207template <
typename DSL>
208bool rangeTest(
const DSL& dsl)
210 typedef typename DSL::Point
Point;
212 unsigned int nbok = 0;
218 Point origin = dsl.getPoint();
219 Point first =
Point(origin[0]-dsl.b(), origin[1]-dsl.a());
220 Point last =
Point(first[0]+dsl.b(), first[1]+dsl.a());
221 trace.
info() <<
"from " << first <<
" to " << last << std::endl;
227 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
231 typedef typename DSL::ConstIterator I;
236 for (I it = dsl.begin(first), itEnd = dsl.end(last);
237 ( (it != itEnd)&&(res)&&(c<100) );
240 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") ";
244 trace.
info() <<
" : " << c <<
" points " << std::endl;
247 if ( (res)&&(c == (dsl.omega()+1)) )
251 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
256 typedef typename DSL::ConstReverseIterator I;
261 for (I it = dsl.rbegin(last), itEnd = dsl.rend(first);
262 ( (it != itEnd)&&(res)&&(c<100) );
265 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") ";
269 trace.
info() <<
" : " << c <<
" points " << std::endl;
272 if ( (res)&&(c == (dsl.omega()+1)) )
276 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
281 typedef typename DSL::ConstIterator I;
286 I itBegin = dsl.begin(first);
287 for (I it = itBegin, itEnd = dsl.end(last);
288 ( (it != itEnd)&&(res)&&(c<100) );
291 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") " << it.remainder() <<
", ";
292 I it2 = ( itBegin + c );
293 if ( (it != it2) || ((it2 - itBegin) != c) )
297 trace.
info() <<
" : " << c <<
" points " << std::endl;
304 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
309 for (I it = (itBegin+n), itEnd = itBegin;
310 ( (it!=itEnd)&&(res)&&(c < 100) );
313 trace.
info() <<
"(" << it->operator[](0) <<
"," << it->operator[](1) <<
") " << it.remainder() <<
", ";
314 I it2 = ( (itBegin+n) - c );
315 if ( (it != it2) || (((itBegin+n) - it2) != c) )
323 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
335template <
typename DSL>
336bool sameOctantTest(
const DSL& dsl1,
const DSL& dsl2)
339 trace.
info() << dsl1 <<
" " << dsl2 << std::endl;
341 typename DSL::Octant::first_type oc;
343 return dsl1.sameOctant(dsl2,&oc);
351template <
typename DSL>
352typename DSL::Octant testOctant(
const typename DSL::Coordinate & a,
const typename DSL::Coordinate & b)
358 return aDSL.octant();
365int main(
int argc,
char** argv )
369 for (
int i = 0; i < argc; ++i )
374 bool res = mainTest<DGtal::ArithmeticalDSL<DGtal::int32_t> >()
376 && mainTest<DGtal::NaiveDSL<DGtal::int32_t> >()
384 && rangeTest( DSL(5, 8, 16) )
385 && rangeTest( DSL(8, 5, 14) )
386 && rangeTest( DSL(5, -8, 14) )
387 && rangeTest( DSL(8, -5, 14) )
388 && rangeTest( DSL(-5, 8, 14) )
389 && rangeTest( DSL(-8, 5, 14) )
390 && rangeTest( DSL(-5, -8, 14) )
391 && rangeTest( DSL(-8, -5, 14) )
392 && rangeTest( DSL(1, 0, 14) )
393 && rangeTest( DSL(0, -1, 14) )
394 && rangeTest( DSL(0, 1, 14) )
395 && rangeTest( DSL(-1, 0, 14) )
396 && rangeTest( DSL(1, 1, 14) )
397 && rangeTest( DSL(1, -1, 14) )
398 && rangeTest( DSL(-1, 1, 14) )
399 && rangeTest( DSL(-1, -1, 14) )
408 && rangeTest( DSL(5, 8, -16) )
409 && rangeTest( DSL(8, 5, -17) )
410 && rangeTest( DSL(5, -8, -17) )
411 && rangeTest( DSL(8, -5, -17) )
412 && rangeTest( DSL(-5, 8, -17) )
413 && rangeTest( DSL(-8, 5, -17) )
414 && rangeTest( DSL(-5, -8, -17) )
415 && rangeTest( DSL(-8, -5, -17) )
416 && rangeTest( DSL(1, 0, -17) )
417 && rangeTest( DSL(0, -1, -17) )
418 && rangeTest( DSL(0, 1, -17) )
419 && rangeTest( DSL(-1, 0, -17) )
428 && sameOctantTest(DSL(5,8,16),DSL(1,2,3))==
true
429 && sameOctantTest(DSL(5,8,16),DSL(2,1,3))==
false
430 && sameOctantTest(DSL(2,2,16),DSL(6,3,3))==
true
431 && sameOctantTest(DSL(2,2,16),DSL(3,3,3))==
true
432 && sameOctantTest(DSL(5,-8,16),DSL(0,-2,3))==
true
433 && sameOctantTest(DSL(5,8,16),DSL(-2,1,3))==false
441 typedef DSL::Octant Octant;
446 && testOctant<DSL>(0,0) == Octant(-1,-1)
447 && testOctant<DSL>(0,5) == Octant(0,7)
448 && testOctant<DSL>(0,-5) == Octant(3,4)
449 && testOctant<DSL>(5,0) == Octant(1,2)
450 && testOctant<DSL>(-5,0) == Octant(5,6)
451 && testOctant<DSL>(1,1) == Octant(0,1)
452 && testOctant<DSL>(1,-1) == Octant(2,3)
453 && testOctant<DSL>(-1,1) == Octant(6,7)
454 && testOctant<DSL>(-1,-1) == Octant(4,5)
461 res = res && rangeTest( DSL(5, 8, -26) ) && rangeTest( DSL(5, 8, 13) )
462 && rangeTest( DSL(5, 8, -17) ) && rangeTest( DSL(5, 8, 11313) );
472 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.