2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file AngleComputer.ih
20 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
21 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
23 * @author (backported by) Bertrand Kerautret (\c kerautre@loria.fr )
24 * LORIA (CNRS, UMR 7503), University of Nancy, France
28 * Implementation of inline methods defined in AngleComputer.h
30 * This file is part of the DGtal library.
33///////////////////////////////////////////////////////////////////////////////
34// IMPLEMENTATION of inline methods.
35///////////////////////////////////////////////////////////////////////////////
37//////////////////////////////////////////////////////////////////////////////
39//////////////////////////////////////////////////////////////////////////////
43///////////////////////////////////////////////////////////////////////////////
44// Implementation of inline methods //
50 * @return the corresponding angle in [0:2pi[
54DGtal::AngleComputer::cast( float i )
56 while ( i < 0.0f ) i += (float) (M_PI*2.0);
57 while ( i > (double)(M_PI*2.0) ) i -= (float)(M_PI*2.0);
63 * Less comparator modulo. Be careful, modulo comparisons have no
64 * sense when the absolute difference of the values are around pi.
66 * @param i any angle in [0:2pi[
67 * @param j any angle in [0:2pi[
68 * @return 'true' if [i] strictly precedes [j] in a window 'pi'.
72DGtal::AngleComputer::less( float i, float j )
83 * Performs j - i modulo 2pi, assuming less(i,j) is true.
85 * @param j any angle in [0:2pi[
86 * @param i any angle in [0:2pi[
87 * @return the value j - i, always positive.
91DGtal::AngleComputer::posDiff( float j, float i )
93 return ( i <= j ) ? j - i : j + (float)(M_PI*2.0) - i;
97 * Performs j - i, assuming th result is in [-pi:pi[
99 * @param j any angle in [0:2pi[
100 * @param i any angle in [0:2pi[
101 * @return the value j - i, always positive.
105DGtal::AngleComputer::deviation( float j, float i )
107 return less( i, j ) ? posDiff( j, i ) : -posDiff( i, j );
112 * Equivalent to 'less( i, j ) ? i : j'.
114 * @param i any angle in [0:2pi[
115 * @param j any angle in [0:2pi[
116 * @return the smallest angle of [i] and [j] in a window 'pi'.
120DGtal::AngleComputer::min( float i, float j )
122 return less( i, j ) ? i : j;
126 * Equivalent to 'less( i, j ) ? j : i'.
128 * @param i any angle in [0:2pi[
129 * @param j any angle in [0:2pi[
130 * @return the greatest angle of [i] and [j] in a window 'pi'.
134DGtal::AngleComputer::max( float i, float j )
136 return less( i, j ) ? j : i;
142 * @param i any angle.
143 * @return the corresponding angle in [0:2pi[
147DGtal::AngleComputer::cast( double i )
149 while ( i < 0.0 ) i += (float)(M_PI*2.0);
150 while ( i > (float)(M_PI*2.0) ) i -= (float)(M_PI*2.0);
156 * Less comparator modulo. Be careful, modulo comparisons have no
157 * sense when the absolute difference of the values are around pi.
159 * @param i any angle in [0:2pi[
160 * @param j any angle in [0:2pi[
161 * @return 'true' if [i] strictly precedes [j] in a window 'pi'.
165DGtal::AngleComputer::less( double i, double j )
176 * Performs j - i modulo 2pi, assuming less(i,j) is true.
178 * @param j any angle in [0:2pi[
179 * @param i any angle in [0:2pi[
180 * @return the value j - i, always positive.
184DGtal::AngleComputer::posDiff( double j, double i )
186 return ( i <= j ) ? j - i : j + (float)(M_PI*2.0) - i;
190 * Performs j - i, assuming th result is in [-pi:pi[
192 * @param j any angle in [0:2pi[
193 * @param i any angle in [0:2pi[
194 * @return the value j - i, always positive.
198DGtal::AngleComputer::deviation( double j, double i )
200 return less( i, j ) ? posDiff( j, i ) : -posDiff( i, j );
205 * Equivalent to 'less( i, j ) ? i : j'.
207 * @param i any angle in [0:2pi[
208 * @param j any angle in [0:2pi[
209 * @return the smallest angle of [i] and [j] in a window 'pi'.
213DGtal::AngleComputer::min( double i, double j )
215 return less( i, j ) ? i : j;
219 * Equivalent to 'less( i, j ) ? j : i'.
221 * @param i any angle in [0:2pi[
222 * @param j any angle in [0:2pi[
223 * @return the greatest angle of [i] and [j] in a window 'pi'.
227DGtal::AngleComputer::max( double i, double j )
229 return less( i, j ) ? j : i;
236///////////////////////////////////////////////////////////////////////////////