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
ModuloComputer.ih
1
30
31
#include <cstdlib>
33
35
// IMPLEMENTATION of inline methods.
37
39
// ----------------------- Standard services ------------------------------
40
41
46
template
<
typename
T>
47
inline
48
DGtal::ModuloComputer<T>::ModuloComputer
(
UnsignedIntegerParamType
m )
49
: k( m )
50
{
51
}
52
54
// Interface - public :
55
56
57
62
template
<
typename
T>
63
inline
64
void
65
DGtal::ModuloComputer<T>::increment
(
UnsignedInteger
& i )
const
66
{
67
if
( ++i == k ) i = 0;
68
}
69
70
75
template
<
typename
T>
76
inline
77
void
78
DGtal::ModuloComputer<T>::decrement
(
UnsignedInteger
& i )
const
79
{
80
if
( i == 0 ) i = k;
81
--i;
82
}
83
84
89
template
<
typename
T>
90
inline
91
typename
DGtal::ModuloComputer<T>::UnsignedInteger
92
DGtal::ModuloComputer<T>::next
(
UnsignedIntegerParamType
i )
const
93
{
94
95
return
( (i+1) == k ) ? 0 : (i+1);
96
}
97
98
103
template
<
typename
T>
104
inline
105
typename
DGtal::ModuloComputer<T>::UnsignedInteger
106
DGtal::ModuloComputer<T>::previous
(
UnsignedIntegerParamType
i )
const
107
{
108
return
( i == 0 ) ? k - 1 : i - 1;
109
}
110
111
116
template
<
typename
T>
117
inline
118
typename
DGtal::ModuloComputer<T>::UnsignedInteger
119
DGtal::ModuloComputer<T>::cast
(
IntegerParamType
i )
const
120
{
121
Integer
tmp = i;
122
while
( tmp < 0 ) tmp += k;
123
UnsignedInteger
ip = (
Integer
) tmp;
124
while
( ip >= k ) ip -= k;
125
return
ip;
126
}
127
128
137
template
<
typename
T>
138
inline
139
bool
140
DGtal::ModuloComputer<T>::less
(
UnsignedIntegerParamType
i,
UnsignedIntegerParamType
j )
const
141
{
142
Integer
d = ( (T) j ) - ( (T) i );
143
if
( d > 0 )
144
return
d < (T) ( k / 2 );
145
else
146
return
(-d) >= (T) ( k / 2 );
147
}
148
149
157
template
<
typename
T>
158
inline
159
typename
DGtal::ModuloComputer<T>::UnsignedInteger
160
DGtal::ModuloComputer<T>::posDiff
(
UnsignedIntegerParamType
j,
UnsignedIntegerParamType
i )
const
161
{
162
return
( i <= j ) ? j - i : j + k - i;
163
}
164
165
166
171
template
<
typename
T>
172
inline
173
void
174
DGtal::ModuloComputer<T>::selfDisplay
( std::ostream & out )
const
175
{
176
out <<
"[ModuloComputer]"
;
177
}
178
183
template
<
typename
T>
184
inline
185
bool
186
DGtal::ModuloComputer<T>::isValid
()
const
187
{
188
return
true
;
189
}
190
191
192
Generated on Wed Dec 19 2012 19:10:32 for DGtal by
1.8.1.1