head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.40; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.57; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.03; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.00; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# sg_inlines.h

Go to the documentation of this file.

    00001
    00006 // Written by Norman Vine, started June 2000.
    00007 //
    00008 // Copyright (C) 2000  Norman Vine  - nhv@@cape.com
    00009 //
    00010 // This library is free software; you can redistribute it and/or
    00011 // modify it under the terms of the GNU Library General Public
    00012 // License as published by the Free Software Foundation; either
    00013 // version 2 of the License, or (at your option) any later version.
    00014 //
    00015 // This library is distributed in the hope that it will be useful,
    00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018 // Library General Public License for more details.
    00019 //
    00020 // You should have received a copy of the GNU Library General Public
    00021 // License along with this library; if not, write to the
    00022 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00023 // Boston, MA  02111-1307, USA.
    00024 //
    00025 // $Id: sg_inlines.h,v 1.3 2002/04/25 15:09:10 david Exp $
    00026
    00027
    00028 #ifndef _SG_INLINES_H
    00029 #define _SG_INLINES_H
    00030
    00031 // return the sign of a value
    00032 template <class T>
    00033 inline int SG_SIGN(const T x) {
    00034     return x < T(0) ? -1 : 1;
    00035 }
    00036
    00037 // return the minimum of two values
    00038 template <class T>
    00039 inline T SG_MIN2(const T a, const T b) {
    00040     return a < b ? a : b;
    00041 }
    00042
    00043 // return the minimum of three values
    00044 template <class T>
    00045 inline T SG_MIN3( const T a, const T b, const T c) {
    00046     return (a < b ? SG_MIN2 (a, c) : SG_MIN2 (b, c));
    00047 }
    00048
    00049 // return the maximum of two values
    00050 template <class T>
    00051 inline T SG_MAX2(const T a, const T b) {
    00052     return  a > b ? a : b;
    00053 }
    00054
    00055 // return the maximum of three values
    00056 template <class T>
    00057 inline T SG_MAX3 (const T a, const T b, const T c) {
    00058     return (a > b ? SG_MAX2 (a, c) : SG_MAX2 (b, c));
    00059 }
    00060
    00061 // return the minimum and maximum of three values
    00062 template <class T>
    00063 inline void SG_MIN_MAX3 ( T &min, T &max, const T a, const T b, const T c) {
    00064     if( a > b ) {
    00065         if( a > c ) {
    00066             max = a;
    00067             min = SG_MIN2 (b, c);
    00068         } else {
    00069             max = c;
    00070             min = SG_MIN2 (a, b);
    00071         }
    00072     } else {
    00073         if( b > c ) {
    00074             max = b;
    00075             min = SG_MIN2 (a, c);
    00076         } else {
    00077             max = c;
    00078             min = SG_MIN2 (a, b);
    00079         }
    00080     }
    00081 }
    00082
    00083 // swap two values
    00084 template <class T>
    00085 inline void SG_SWAP( T &a, T &b) {
    00086     T c = a;  a = b;  b = c;
    00087 }
    00088
    00089 // clamp a value to lie between min and max
    00090 template <class T>
    00091 inline void SG_CLAMP_RANGE(T &x, const T min, const T max ) {
    00092     if ( x < min ) { x = min; }
    00093     if ( x > max ) { x = max; }
    00094 }
    00095
    00096 // normalize a value to lie between min and max
    00097 template <class T>
    00098 inline void SG_NORMALIZE_RANGE( T &val, const T min, const T max ) {
    00099     T step = max - min;
    00100     while( val >= max )  val -= step;
    00101     while( val < min ) val += step;
    00102 };
    00103
    00104 #endif // _SG_INLINES_H

@ 1.3 log @Oops, try again. @ text @d109 1 a109 1