DGtal
0.6.devel
Main Page
Related Pages
Modules
Namespaces
Data Structures
Examples
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
src
DGtal
arithmetic
IntegerComputer.h
1
17
#pragma once
18
31
#if defined(IntegerComputer_RECURSES)
32
#error Recursive header files inclusion detected in IntegerComputer.h
33
#else // defined(IntegerComputer_RECURSES)
34
35
#define IntegerComputer_RECURSES
36
37
#if !defined IntegerComputer_h
38
39
#define IntegerComputer_h
40
42
// Inclusions
43
#include <iostream>
44
#include "DGtal/base/Common.h"
45
#include "DGtal/kernel/NumberTraits.h"
46
#include "DGtal/kernel/CUnsignedInteger.h"
47
#include "DGtal/kernel/CInteger.h"
48
#include "DGtal/kernel/SpaceND.h"
50
51
namespace
DGtal
52
{
53
55
// template class IntegerComputer
81
template
<
typename
TInteger>
82
class
IntegerComputer
83
{
84
// ----------------------- Associated types ------------------------------
85
public
:
86
typedef
IntegerComputer<TInteger>
Self
;
87
typedef
typename
NumberTraits<TInteger>::SignedVersion
Integer
;
88
typedef
typename
NumberTraits<Integer>::ParamType
IntegerParamType
;
89
90
typedef
typename
NumberTraits<TInteger>::UnsignedVersion
UnsignedInteger
;
91
typedef
typename
NumberTraits<UnsignedInteger>::ParamType
UnsignedIntegerParamType
;
92
93
typedef
typename
SpaceND<2,Integer>::Point
Point2I
;
94
typedef
typename
SpaceND<2,Integer>::Vector
Vector2I
;
95
typedef
typename
SpaceND<3,Integer>::Point
Point3I
;
96
typedef
typename
SpaceND<3,Integer>::Vector
Vector3I
;
97
98
BOOST_CONCEPT_ASSERT
((
CInteger<Integer>
));
99
BOOST_CONCEPT_ASSERT
((
CUnsignedInteger<UnsignedInteger>
));
100
101
// ----------------------- Standard services ------------------------------
102
public
:
103
107
~IntegerComputer
();
108
117
IntegerComputer
();
118
127
IntegerComputer
(
const
Self
& other );
128
138
Self
&
operator=
(
const
Self
& other );
139
140
141
// ----------------------- Integer services ------------------------------
142
public
:
143
148
static
bool
isZero
(
IntegerParamType
a );
149
154
static
bool
isNotZero
(
IntegerParamType
a );
155
160
static
bool
isPositive
(
IntegerParamType
a );
161
166
static
bool
isNegative
(
IntegerParamType
a );
167
172
static
bool
isPositiveOrZero
(
IntegerParamType
a );
173
178
static
bool
isNegativeOrZero
(
IntegerParamType
a );
179
184
static
Integer
abs
(
IntegerParamType
a );
185
191
static
Integer
max
(
IntegerParamType
a,
IntegerParamType
b );
192
199
static
Integer
max
(
IntegerParamType
a,
IntegerParamType
b,
IntegerParamType
c );
200
206
static
Integer
min
(
IntegerParamType
a,
IntegerParamType
b );
207
214
static
Integer
min
(
IntegerParamType
a,
IntegerParamType
b,
IntegerParamType
c );
215
229
void
getEuclideanDiv
(
Integer
& q,
Integer
& r,
230
IntegerParamType
a,
IntegerParamType
b )
const
;
231
238
Integer
floorDiv
(
IntegerParamType
na,
IntegerParamType
nb )
const
;
239
246
Integer
ceilDiv
(
IntegerParamType
na,
IntegerParamType
nb )
const
;
247
256
void
getFloorCeilDiv
(
Integer
& fl,
Integer
& ce,
257
IntegerParamType
na,
IntegerParamType
nb )
const
;
258
267
static
Integer
staticGcd
(
IntegerParamType
a,
IntegerParamType
b );
268
277
Integer
gcd
(
IntegerParamType
a,
IntegerParamType
b )
const
;
278
287
void
getGcd
(
Integer
& g,
IntegerParamType
a,
IntegerParamType
b )
const
;
288
299
Integer
getCFrac
( std::vector<Integer> & quotients,
300
IntegerParamType
a,
IntegerParamType
b )
const
;
316
template
<
typename
OutputIterator>
317
Integer
getCFrac
( OutputIterator outIt,
318
IntegerParamType
a,
IntegerParamType
b )
const
;
319
330
Point2I
convergent
(
const
std::vector<Integer> & quotients,
331
unsigned
int
k )
const
;
332
333
// ----------------------- Point2I services ------------------------------
334
public
:
340
void
reduce
(
Vector2I
& p )
const
;
341
342
350
Integer
crossProduct
(
const
Vector2I
& u,
const
Vector2I
& v)
const
;
351
359
void
getCrossProduct
(
Integer
& cp,
360
const
Vector2I
& u,
const
Vector2I
& v)
const
;
361
369
Integer
dotProduct
(
const
Vector2I
& u,
const
Vector2I
& v )
const
;
370
378
void
getDotProduct
(
Integer
& dp,
379
const
Vector2I
& u,
const
Vector2I
& v)
const
;
380
392
Vector2I
extendedEuclid
(
IntegerParamType
a,
IntegerParamType
b,
393
IntegerParamType
c )
const
;
394
409
void
getCoefficientIntersection
(
Integer
& fl,
Integer
& ce,
410
const
Vector2I
& p,
411
const
Vector2I
& u,
412
const
Vector2I
& N,
413
IntegerParamType
c )
const
;
414
440
void
getValidBezout
(
Vector2I
& v,
441
const
Point2I
& A,
const
Vector2I
& u,
442
const
Vector2I
& N,
IntegerParamType
c,
443
const
Vector2I
& N2,
IntegerParamType
c2,
444
bool
compute_v =
true
)
const
;
445
446
// ----------------------- Point3I services ------------------------------
447
public
:
448
454
void
reduce
(
Vector3I
& p )
const
;
455
463
Integer
dotProduct
(
const
Vector3I
& u,
const
Vector3I
& v)
const
;
464
472
void
getDotProduct
(
Integer
& dp,
473
const
Vector3I
& u,
const
Vector3I
& v)
const
;
474
475
476
// ----------------------- Interface --------------------------------------
477
public
:
478
483
void
selfDisplay
( std::ostream & out )
const
;
484
489
bool
isValid
()
const
;
490
491
// ------------------------- Protected Datas ------------------------------
492
private
:
493
// ------------------------- Private Datas --------------------------------
494
private
:
495
497
mutable
Integer
_m_a
;
499
mutable
Integer
_m_b
;
501
mutable
Integer
_m_a0
;
503
mutable
Integer
_m_a1
;
505
mutable
Integer
_m_q
;
507
mutable
Integer
_m_r
;
511
mutable
std::vector<Integer>
_m_bezout
[ 4 ];
513
mutable
Vector2I
_m_v
;
515
mutable
Vector2I
_m_v0
;
517
mutable
Vector2I
_m_v1
;
519
mutable
Integer
_m_c0
;
521
mutable
Integer
_m_c1
;
523
mutable
Integer
_m_c2
;
524
525
// ------------------------- Hidden services ------------------------------
526
protected
:
527
528
529
// ------------------------- Internals ------------------------------------
530
private
:
531
532
};
// end of class IntegerComputer
533
534
541
template
<
typename
TInteger>
542
std::ostream&
543
operator<< ( std::ostream & out, const IntegerComputer<TInteger> & object );
544
545
}
// namespace DGtal
546
547
549
// Includes inline functions.
550
#include "DGtal/arithmetic/IntegerComputer.ih"
551
552
// //
554
555
#endif // !defined IntegerComputer_h
556
557
#undef IntegerComputer_RECURSES
558
#endif // else defined(IntegerComputer_RECURSES)
Generated on Wed Dec 19 2012 19:10:27 for DGtal by
1.8.1.1