3 * Various inline template definitions.
6 // Written by Norman Vine, started June 2000.
8 // Copyright (C) 2000 Norman Vine - nhv@cape.com
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
31 // return the sign of a value
33 inline int SG_SIGN(const T x) {
34 return x < T(0) ? -1 : 1;
37 // return the minimum of two values
39 inline T SG_MIN2(const T a, const T b) {
43 // return the minimum of three values
45 inline T SG_MIN3( const T a, const T b, const T c) {
46 return (a < b ? SG_MIN2 (a, c) : SG_MIN2 (b, c));
49 // return the maximum of two values
51 inline T SG_MAX2(const T a, const T b) {
55 // return the maximum of three values
57 inline T SG_MAX3 (const T a, const T b, const T c) {
58 return (a > b ? SG_MAX2 (a, c) : SG_MAX2 (b, c));
61 // return the minimum and maximum of three values
63 inline void SG_MIN_MAX3 ( T &min, T &max, const T a, const T b, const T c) {
85 inline void SG_SWAP( T &a, T &b) {
86 T c = a; a = b; b = c;
89 // clamp a value to lie between min and max
91 inline void SG_CLAMP_RANGE(T &x, const T min, const T max ) {
92 if ( x < min ) { x = min; }
93 if ( x > max ) { x = max; }
96 // normalize a value to lie between min and max
98 inline void SG_NORMALIZE_RANGE( T &val, const T min, const T max ) {
100 while( val >= max ) val -= step;
101 while( val < min ) val += step;
104 #endif // _SG_INLINES_H