Main Page | Class Hierarchy | Class List | File List | Class Members

matrixTool.h

00001 /*============================================================================ 00002 File: matrixTool.h 00003 Purpose: 00004 Revision: $Id: matrixTool.h,v 1.2 2002/05/13 21:07:45 philosophil Exp $ 00005 Created by: Philippe Lavoie (26 January, 1998) 00006 Modified by: 00007 00008 Copyright notice: 00009 Copyright (C) 1996-1999 Philippe Lavoie 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License as published by the Free Software Foundation; either 00014 version 2 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public 00022 License along with this library; if not, write to the Free 00023 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 =============================================================================*/ 00025 00026 #ifndef _Matrix_matrixTool_h_ 00027 #define _Matrix_matrixTool_h_ 00028 00029 #include "matrix_global.h" 00030 00031 namespace PLib { 00032 00033 00034 00035 00036 template <class T> 00037 inline int compareT(T*a, T* b){ 00038 if(*(a) > *(b)) 00039 return 1 ; 00040 if(*(a) < *(b)) 00041 return -1 ; 00042 return 0 ; 00043 } 00044 00045 // These functions are needed for qSort (in vector.h and matrix.h) 00046 inline int compareInt(const void* a, const void* b){ 00047 return compareT((int*)a,(int*)b) ; 00048 } 00049 00050 inline int compareFloat(const void* a, const void* b){ 00051 return compareT((float*)a,(float*)b) ; 00052 } 00053 00054 inline int compareDouble(const void* a, const void* b){ 00055 return compareT((float*)a,(float*)b) ; 00056 } 00057 00058 template <class T> 00059 inline T absolute(T a){ 00060 return ( a<T() ) ? -a : a ; 00061 } 00062 00063 inline double absolute(double a) { return fabs(a) ; } 00064 inline float absolute(float a) { return fabs(a) ; } 00065 00066 template <class T> 00067 inline T to2power(T a){ 00068 return a*a ; 00069 } 00070 00071 template <class T> 00072 inline T minimum(T a, T b){ 00073 return a<b ? a : b ; 00074 } 00075 00076 template <class T> 00077 inline T maximum(T a, T b){ 00078 return a>b ? a : b ; 00079 } 00080 00081 // Use minimumRef or maximumRef if you want to pass by reference 00082 // You should only use this for special types and not for 00083 // the base types 00084 template <class T> 00085 inline T minimumRef(const T &a, const T &b){ 00086 return a<b ? a : b ; 00087 } 00088 00089 template <class T> 00090 inline T maximumRef(const T &a, const T &b){ 00091 return a>b ? a : b ; 00092 } 00093 00094 00095 // Some often used inline functions 00096 00097 // definition for Complex, HPoint_3D, Point_3D, Vector2 and Coordinate 00098 // follows 00099 00100 inline Complex minimum(Complex a, Complex b){ 00101 double r,i ; 00102 r = minimum(real(a),real(b)) ; 00103 i = minimum(imag(a),imag(b)) ; 00104 return Complex(r,i) ; 00105 } 00106 00107 inline Complex maximum(Complex a, Complex b){ 00108 double r,i ; 00109 r = maximum(real(a),real(b)) ; 00110 i = maximum(imag(a),imag(b)) ; 00111 return Complex(r,i) ; 00112 } 00113 00114 00115 inline Complex minimumByRef(const Complex &a, const Complex &b){ 00116 double r,i ; 00117 r = minimum(real(a),real(b)) ; 00118 i = minimum(imag(a),imag(b)) ; 00119 return Complex(r,i) ; 00120 } 00121 00122 00123 inline Complex maximumByRef(const Complex &a, const Complex &b){ 00124 double r,i ; 00125 r = maximum(real(a),real(b)) ; 00126 i = maximum(imag(a),imag(b)) ; 00127 return Complex(r,i) ; 00128 } 00129 00130 00148 template<class T> inline void boundTo(T& a, T low, T high){ 00149 if(a<=low) a = low ; 00150 if(a>=high) a = high ; 00151 } 00152 00153 } // end namespace 00154 00155 #endif

Generated on Wed Aug 18 07:07:37 2004 for NURBS++ by doxygen 1.3.7