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

geo_utils.h

Go to the documentation of this file.
00001 /***************************************************************************************************/ 00002 /***************************************************************************************************/ 00012 /***************************************************************************************************/ 00013 /***************************************************************************************************/ 00014 #ifndef GEO_UTILS_H 00015 #define GEO_UTILS_H 00016 00017 00018 /*------------------------------------ Prototypes ---------------------------------------------*/ 00019 class cPoint2D; 00020 class cRectangle; 00021 class cPositive_Rectangle; 00022 class cHV_Seg; 00023 class cSeg; 00024 00025 /*------------------------------------ Includes ---------------------------------------------*/ 00026 #include <iostream> 00027 00028 /*------------------------------------- Globals -----------------------------------------------*/ 00030 extern float Get_Distance( cPoint2D& p1 , cPoint2D& p2 ); 00031 00033 extern unsigned int Get_Square_Distance( cPoint2D& p1 , cPoint2D& p2 ); 00034 00035 00036 00037 /*------------------------------------- Classes ---------------------------------------------*/ 00038 00039 00040 /*************************************************************************************************/ 00042 /*************************************************************************************************/ 00043 class cPoint2D 00044 { 00045 friend std::ostream &operator<<(std::ostream &os, const cPoint2D &ex) { return os << "[" << ex.X << "," << ex.Y << "]"; }; 00046 public: 00048 inline cPoint2D() 00049 { 00050 X=0; 00051 Y=0; 00052 }; 00053 // constructeur, d'un point en x,y 00054 inline cPoint2D(int x,int y) 00055 { 00056 X=x ; 00057 Y=y; 00058 }; 00059 00061 inline Get_X() { return X;}; 00063 inline Get_Y() { return Y;}; 00065 inline Set(int x, int y) 00066 { 00067 X=x; 00068 Y=y; 00069 }; 00070 00072 inline bool operator==(cPoint2D& p) 00073 { 00074 return ( (X==p.X) && (Y==p.Y) ); 00075 }; 00076 00078 inline bool operator!=(cPoint2D& p) 00079 { 00080 return ( (X!=p.X) || (Y!=p.Y) ); 00081 }; 00082 00083 int X; 00084 int Y; 00085 }; 00086 00087 00088 00089 /*************************************************************************************************/ 00091 /*************************************************************************************************/ 00092 class cRectangle 00093 { 00094 friend std::ostream &operator<<(std::ostream &os, const cRectangle &ex) { return os << "[" << ex.p0 <<"<->" << ex.p1 << "]"; }; 00095 public: 00097 cRectangle() 00098 { 00099 p0.X=0; 00100 p0.Y=0; 00101 p1.X=0; 00102 p1.Y=0; 00103 }; 00105 cRectangle(int x0 , int y0 , int x1 , int y1) 00106 { 00107 p0.X = x0; 00108 p0.Y = y0; 00109 p1.X = x1; 00110 p1.Y = y1; 00111 }; 00113 cRectangle(cPoint2D pA , cPoint2D pB) 00114 { 00115 p0=pA ; 00116 p1=pB; 00117 }; 00119 void Get_Centre(cPoint2D & p); 00120 00121 cPoint2D p0; 00122 cPoint2D p1; 00123 }; 00124 00125 00126 00127 00128 /*************************************************************************************************/ 00130 00133 class cPositive_Rectangle : public cRectangle 00134 { 00135 public: 00137 cPositive_Rectangle():cRectangle() {}; 00139 cPositive_Rectangle(cPoint2D &pA , cPoint2D &pB); 00140 00142 void Get_Nord_Seg( cHV_Seg & seg ); 00144 void Get_Ouest_Seg( cHV_Seg & seg ); 00146 void Get_Est_Seg( cHV_Seg & seg ); 00148 void Get_Sud_Seg( cHV_Seg & seg ); 00149 00151 inline bool In( int x , int y ) 00152 { 00153 return ( x>=p0.X && x <=p1.X && y>=p0.Y && y <=p1.Y ); 00154 } 00155 00157 bool In( cPoint2D &pA ); 00158 }; 00159 00160 00161 00162 /*************************************************************************************************/ 00164 /*************************************************************************************************/ 00165 class cSeg 00166 { 00167 friend std::ostream &operator<<(std::ostream &os, const cSeg &ex) { return os << "[" << ex.p0 << "," << ex.p1 << "]"; }; 00168 public: 00170 cSeg() 00171 { 00172 p0.Set(0,0); 00173 p1.Set(0,0); 00174 }; 00175 00177 cSeg(cPoint2D &pA , cPoint2D &pB) 00178 { 00179 p0=pA; 00180 p1=pB; 00181 }; 00182 00184 void Get_Middle(cPoint2D& p); 00186 float Get_Square_Distance_From_Point( cPoint2D &pA ); 00188 cPoint2D& Get_p0() { return p0;}; 00190 cPoint2D& Get_p1() { return p1;}; 00192 bool operator==(cSeg& seg2); 00194 unsigned int Get_Square_Length(); 00195 00196 virtual void Set( cPoint2D &pA , cPoint2D &pB ) { p0=pA;p1=pB; }; 00197 00198 protected: 00199 cPoint2D p0; 00200 cPoint2D p1; 00201 }; 00202 00203 00204 00205 /*************************************************************************************************/ 00207 00209 class cHV_Seg : public cSeg 00210 { 00211 public: 00213 cHV_Seg():cSeg() { bHorizontal=true;}; 00215 cHV_Seg(cPoint2D &pA , cPoint2D &pB); 00216 00217 // fixe le segment comme allant de 'pA' à 'pB' 00218 void Set( cPoint2D &pA , cPoint2D &pB ); 00219 00221 00223 bool Get_Intersection( cHV_Seg& seg , cHV_Seg& result); 00224 00226 00238 int Get_Complementaires( cHV_Seg& seg , cHV_Seg& complementaire1, cHV_Seg& complementaire2); 00239 00241 bool Contient_Point(cPoint2D & A); 00242 00244 int Get_Exact_Intersection(cSeg &seg , cPoint2D & A , cHV_Seg& seg_result); 00245 00247 inline bool Is_Horizontal() { return bHorizontal;}; 00248 00249 bool cHV_Seg::Contient( cHV_Seg& seg ); 00250 00251 bool On_Same_Line( cHV_Seg& seg ); 00252 private: 00253 bool bHorizontal; 00254 00255 }; 00256 00257 00258 #endif

Generated on Fri May 21 19:22:37 2004 for LIBELL by doxygen 1.3.7