Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Tools/XVGeometry.h

00001 // *** BEGIN_XVISION2_COPYRIGHT_NOTICE ***
00002 // *** END_XVISION2_COPYRIGHT_NOTICE ***
00003 
00004 #ifndef _XVGEOMETRY_H_
00005 #define _XVGEOMETRY_H_
00006 
00007 #include <sys/types.h>
00008 #include <math.h>
00009 
00010 template <class T>
00011 class XV2Vec {
00012 
00013 protected:
00014 
00015   T posx;
00016   T posy;
00017 
00018 public:
00019 
00020   inline const T & PosX() const { return posx; }
00021   inline const T & PosY() const { return posy; }
00022 
00023   inline const T & x() const { return posx; }
00024   inline const T & y() const { return posy; }
00025 
00026   inline XV2Vec(const T px, const T py) {
00027     posx = px;
00028     posy = py;
00029   }
00030 
00031   inline XV2Vec(const XV2Vec & xvp) {
00032     posx = xvp.posx;
00033     posy = xvp.posy;
00034   }
00035 
00036   inline XV2Vec() {
00037     posx = 0;
00038     posy = 0;
00039   }
00040 
00041   inline void setX(T val) { posx = val; }
00042   inline void setY(T val) { posy = val; }
00043 
00044   inline virtual void reposition(const XV2Vec<T> & xvp) {
00045     posx = xvp.posx;
00046     posy = xvp.posy;
00047   }
00048 
00049   inline virtual void reposition(const T px, const T py) {
00050     posx = px;
00051     posy = py;
00052   }
00053  
00054   inline XV2Vec<T> & operator = (const XV2Vec<T> & xvp) {
00055     posx = xvp.posx;
00056     posy = xvp.posy;
00057     return *this;
00058   }
00059 
00060 #define MAKE_XV2VEC_OP_XV2VEC(_OP_) \
00061   inline XV2Vec<T> & operator _OP_ (const XV2Vec<T> & p){ \
00062     posx _OP_ p.PosX();  posy _OP_ p.PosY(); return *this; \
00063   };
00064 
00065 MAKE_XV2VEC_OP_XV2VEC(+=);
00066 MAKE_XV2VEC_OP_XV2VEC(-=);
00067 
00068 #define MAKE_XV2VEC_OP_VAL(_OP_) \
00069   inline XV2Vec<T> & operator _OP_  (T val){ \
00070     posx _OP_ val;  posy _OP_ val; return *this; \
00071   };
00072 
00073 MAKE_XV2VEC_OP_VAL(+=);
00074 MAKE_XV2VEC_OP_VAL(-=);
00075 MAKE_XV2VEC_OP_VAL(*=);
00076 MAKE_XV2VEC_OP_VAL(/=); 
00077 
00078   template <class T2>
00079   operator XV2Vec<T2> () const { return XV2Vec<T2>((T2)(this->posx), (T2)(this->posy)); }
00080 };
00081 
00082 #define MAKE_COMPARE_OP_XVPOS_DIFF(OP) \
00083 template <class T1, class T2>\
00084 inline bool operator OP (const XV2Vec<T1> & p1, const XV2Vec<T2> & p2) { \
00085   return (p1.PosX() OP p2.PosX()) && (p1.PosY() OP p2.PosY()); \
00086 }; 
00087 
00088 MAKE_COMPARE_OP_XVPOS_DIFF(==);
00089 MAKE_COMPARE_OP_XVPOS_DIFF(!=);
00090 MAKE_COMPARE_OP_XVPOS_DIFF(<=);
00091 MAKE_COMPARE_OP_XVPOS_DIFF(>=);
00092 MAKE_COMPARE_OP_XVPOS_DIFF(<);
00093 MAKE_COMPARE_OP_XVPOS_DIFF(>);
00094 
00095 #define MAKE_COMPARE_OP_XVPOS(OP) \
00096 template <class T>\
00097 inline bool operator OP (const XV2Vec<T> & p1, const XV2Vec<T> & p2) { \
00098   return (p1.PosX() OP p2.PosX()) && (p1.PosY() OP p2.PosY()); \
00099 }; 
00100 
00101 MAKE_COMPARE_OP_XVPOS(==);
00102 MAKE_COMPARE_OP_XVPOS(!=);
00103 MAKE_COMPARE_OP_XVPOS(<=);
00104 MAKE_COMPARE_OP_XVPOS(>=);
00105 MAKE_COMPARE_OP_XVPOS(<);
00106 MAKE_COMPARE_OP_XVPOS(>);
00107 
00108 template <class T>
00109 inline XV2Vec<T> operator - (const XV2Vec<T> & p){ return XV2Vec<T>(- p.PosX(), -p.PosY()); }
00110 
00115 #define MAKE_XVPOS_OP_XVPOS(OP) \
00116 template <class T1, class T2>\
00117 inline XV2Vec<T1> operator OP (const XV2Vec<T1> & p1, const XV2Vec<T2> & p2) { \
00118   return XV2Vec<T1>((T1)(p1.PosX() OP p2.PosX()), (T1)(p1.PosY() OP p2.PosY())); \
00119 };
00120 
00121 MAKE_XVPOS_OP_XVPOS(+);
00122 MAKE_XVPOS_OP_XVPOS(-);
00123 
00128 #define MAKE_XVPOS_OP_VAL(OP) \
00129 template <class T>\
00130 inline XV2Vec<T> operator OP (const XV2Vec<T> & p1,  T p2) { \
00131   return XV2Vec<T>((T)(p1.PosX() OP p2), (T)(p1.PosY() OP p2)); \
00132 }; 
00133 
00134 MAKE_XVPOS_OP_VAL(+);
00135 MAKE_XVPOS_OP_VAL(-);
00136 MAKE_XVPOS_OP_VAL(*);
00137 MAKE_XVPOS_OP_VAL(/);
00138 
00139 template <class T>
00140 inline XV2Vec<int> round(const XV2Vec<T> &x) {
00141   return XV2Vec<int>(round(x.x()),round(x.y()));
00142 }
00143 
00144 template <class T>
00145 inline XV2Vec<T> rint(const XV2Vec<T> &x) {
00146   return XV2Vec<T>(rint(x.x()),rint(x.y()));
00147 }
00148 
00149 #endif

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000