DGtal  0.9.3beta
testStandardDSLQ0-LSB-reversedSmartDSS-benchmark.cpp
1 
30 #include <cstdlib>
32 #include <iostream>
33 #include <map>
34 #include "DGtal/base/Common.h"
35 #include "DGtal/kernel/CPointPredicate.h"
36 #include "DGtal/arithmetic/IntegerComputer.h"
37 #include "DGtal/arithmetic/LightSternBrocot.h"
38 #include "DGtal/arithmetic/Pattern.h"
39 #include "DGtal/arithmetic/StandardDSLQ0.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 // Functions for testing class LightSternBrocot.
48 
49 template <typename DSL>
50 bool checkSubStandardDSLQ0( const DSL & D,
51  const typename DSL::Point & A,
52  const typename DSL::Point & B )
53 {
54  DSL S = D.reversedSmartDSS( A, B );
55  std::cout << D.a() << " " << D.b() << " " << D.mu() << " "
56  << S.a() << " " << S.b() << " " << S.mu() << " "
57  << A[0] << " " << A[1] << " " << B[0] << " " << B[1]
58  << std::endl;
59  return true;
60 }
61 
62 template <typename Fraction>
63 bool testSubStandardDSLQ0( unsigned int nbtries,
64  typename Fraction::Integer moda,
65  typename Fraction::Integer modb,
66  typename Fraction::Integer modx )
67 {
68  typedef StandardDSLQ0<Fraction> DSL;
69  typedef typename Fraction::Integer Integer;
70  typedef typename DSL::Point Point;
72 
73  std::cout << "# a b mu a1 b1 mu1 Ax Ay Bx By" << std::endl;
74  for ( unsigned int i = 0; i < nbtries; ++i )
75  {
76  Integer a( rand() % moda + 1 );
77  Integer b( rand() % modb + 1 );
78  if ( ic.gcd( a, b ) == 1 )
79  {
80  for ( Integer mu = 0; mu < 5; ++mu )
81  {
82  DSL D( a, b, rand() % (moda+modb) );
83  for ( Integer x = 0; x < 10; ++x )
84  {
85  Integer x1 = rand() % modx;
86  Integer x2 = x1 + 1 + ( rand() % modx );
87  Point A = D.lowestY( x1 );
88  Point B = D.lowestY( x2 );
89  checkSubStandardDSLQ0<DSL>( D, A, B );
90  }
91  }
92  }
93  }
94  return true;
95 }
96 
97 
99 // Standard services - public :
100 
101 int main( int argc, char** argv)
102 {
104  typedef SB::Fraction Fraction;
105  typedef Fraction::Integer Integer;
106  unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 10000;
107  Integer moda = ( argc > 2 ) ? atoll( argv[ 2 ] ) : 12000;
108  Integer modb = ( argc > 3 ) ? atoll( argv[ 3 ] ) : 12000;
109  Integer modx = ( argc > 4 ) ? atoll( argv[ 4 ] ) : 1000;
110  testSubStandardDSLQ0<Fraction>( nbtries, moda, modb, modx );
111  return true;
112 }
113 // //
DGtal::int32_t Integer
Definition: StdDefs.h:74
Aim: Represents a digital straight line with slope in the first quadrant (Q0: x >= 0...
Definition: StandardDSLQ0.h:79
STL namespace.
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
DGtal is the top-level namespace which contains all DGtal functions and types.
Integer gcd(IntegerParamType a, IntegerParamType b) const