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 General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 // return the sign of a value
32 inline int SG_SIGN(const T x) {
33 return x < T(0) ? -1 : 1;
36 // return the minimum of two values
38 inline T SG_MIN2(const T a, const T b) {
42 // return the minimum of three values
44 inline T SG_MIN3( const T a, const T b, const T c) {
45 return (a < b ? SG_MIN2 (a, c) : SG_MIN2 (b, c));
48 // return the maximum of two values
50 inline T SG_MAX2(const T a, const T b) {
54 // return the maximum of three values
56 inline T SG_MAX3 (const T a, const T b, const T c) {
57 return (a > b ? SG_MAX2 (a, c) : SG_MAX2 (b, c));
60 // return the minimum and maximum of three values
62 inline void SG_MIN_MAX3 ( T &min, T &max, const T a, const T b, const T c) {
84 inline void SG_SWAP( T &a, T &b) {
85 T c = a; a = b; b = c;
88 // clamp a value to lie between min and max
90 inline void SG_CLAMP_RANGE(T &x, const T min, const T max ) {
91 if ( x < min ) { x = min; }
92 if ( x > max ) { x = max; }
95 // normalize a value to lie between min and max
97 inline void SG_NORMALIZE_RANGE( T &val, const T min, const T max ) {
99 while( val >= max ) val -= step;
100 while( val < min ) val += step;
103 #endif // _SG_INLINES_H