rtcMisc.h
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002  * Copyright (C) 2009
00003  * Robert Bosch LLC
00004  * Research and Technology Center North America
00005  * Palo Alto, California
00006  *
00007  * All rights reserved.
00008  *
00009  *------------------------------------------------------------------------------
00010  * project ....: Autonomous Technologies
00011  * description.:
00012  * authors ....: Soeren Kammel
00013  * organization: Robert Bosch LLC
00014  * creation ...: 01/26/2009
00015  * modified ...: $Date: 2009-02-16 17:39:28 -0800 (Mon, 16 Feb 2009) $
00016  * changed by .: $Author: kls1pal $
00017  * revision ...: $Revision: 48 $
00018  *------------------------------------------------------------------------------*/
00019 
00020 #ifndef RTCBASE_MISC_H_
00021 #define RTCBASE_MISC_H_
00022 
00023 #include <cmath>
00024 
00025 namespace rtc {
00026 
00027 #define EPSILON  0.00001
00028 
00029         // check id close to zero
00030 template <class T> inline bool fZero(T x) {return ( (x < EPSILON) && (x > -EPSILON) );}
00031 
00032         // round to closest integer
00033 template <class T> inline int rInt(const T x) {return (x > 0 ? int(x+.5) : int(x-.5));}
00034 //template <class T> inline T rInt(const T x) {return (x > 0 ? T(floor(x+.5)) : T(floor(x-.5)));}
00035 
00036         // round x to closest multiple of b; warning does not work if b is negative and x is positive
00037 template <class T> inline T roundTo(const T x, const T b) {return b*T(floor(x/b+0.5));}
00038 
00039 template <class T>
00040 class rect {
00041 public:
00042         rect() {}
00043         rect(T x_, T y_, T width_, T height_) : x(x_), y(y_), width(width_), height(height_) {}
00044         virtual ~rect() {}
00045 
00046 T x, y;
00047 T width, height;
00048 };
00049 
00050 typedef rect<unsigned int> rectui;
00051 typedef rect<float> rectf;
00052 typedef rect<double> rectd;
00053 
00054 template <class T>
00055 class size {
00056 public:
00057         size() {}
00058         size(T width_, T height_) : width(width_), height(height_) {}
00059         virtual ~size() {}
00060 
00061 T width, height;
00062 };
00063 
00064 typedef size<unsigned int> sizeui;
00065 typedef size<float> sizef;
00066 typedef size<double> sized;
00067 
00068 
00069 template<class T, void*(T::*mem_fn)(void*)>
00070 void* threadCBWrapper(void* ptr)
00071         {
00072         return (static_cast<T*>(ptr)->*mem_fn)(NULL);
00073         }
00074 
00075 #ifdef __DARWIN__
00076 inline void pthread_yield() {pthread_yield_np();}
00077 #endif
00078 
00079 }       // namespace rtc
00080 
00081 #endif // RTCBASE_MISC_H_


rtc
Author(s): Benjamin Pitzer
autogenerated on Mon Oct 6 2014 10:07:35