00001 #ifndef PHIL_UTIL
00002 #define PHIL_UTIL
00003
00004
00005
00006
00007 #include <cmath>
00008 #include <vector>
00009 #include <clipper/clipper.h>
00010
00011 namespace
00012 {
00013
00014
00016
00017
00018
00019 template<class T> inline static int Nint( const T& a ) { return int( rint( a ) ); }
00020
00021
00023
00024 template<class T1, class T2> inline static T1 Max(const T1& a, const T2& b)
00025 { return (a > b) ? a : b; }
00026
00027
00029
00030 template<class T1, class T2> inline static T1 Min(const T1& a, const T2& b)
00031 { return (a < b) ? a : b; }
00032
00033
00034
00035
00036 template<class T1, class T2> inline static bool
00037 Close(const T1& a, const T2& b,
00038 const T1& tol=1.0e-6)
00039 { return std::abs(a-b)<=tol; }
00040
00041
00042 template<class T> inline bool IsInList(const std::vector<T>& list,
00043 const T& item)
00044
00045 {
00046 return (std::find(list.begin(),list.end(),item) != list.end());
00047 }
00048
00049 template<class T> bool EqualList(const std::vector<T>& list1,
00050 const std::vector<T>& list2)
00051
00052 {
00053 if (list1.size() != list2.size()) return false;
00054 for (int i=0;i<list2.size();i++)
00055 {
00056 if ( ! IsInList<T>(list1,list2[i])) return false;
00057 }
00058 return true;
00059 }
00060 }
00061
00062 #endif