ccstruct/ipoints.h

Go to the documentation of this file.
00001 
00020 #ifndef           IPOINTS_H
00021 #define           IPOINTS_H
00022 
00023 #include          <math.h>
00024 
00028 inline ICOORD
00029 operator! (                      //rotate 90 deg anti
00030 const ICOORD & src               //thing to rotate
00031 ) {
00032   ICOORD result;                 //output
00033 
00034   result.xcoord = -src.ycoord;
00035   result.ycoord = src.xcoord;
00036   return result;
00037 }
00038 
00042 inline ICOORD
00043 operator- (                      //unary minus
00044 const ICOORD & src               //thing to minus
00045 ) {
00046   ICOORD result;                 //output
00047 
00048   result.xcoord = -src.xcoord;
00049   result.ycoord = -src.ycoord;
00050   return result;
00051 }
00052 
00053 
00057 inline ICOORD
00058 operator+ (                      //sum vectors
00059 const ICOORD & op1,              //operands
00060 const ICOORD & op2) {
00061   ICOORD sum;                    //result
00062 
00063   sum.xcoord = op1.xcoord + op2.xcoord;
00064   sum.ycoord = op1.ycoord + op2.ycoord;
00065   return sum;
00066 }
00067 
00068 
00072 inline ICOORD &
00073 operator+= (                     //sum vectors
00074 ICOORD & op1,                    //operands
00075 const ICOORD & op2) {
00076   op1.xcoord += op2.xcoord;
00077   op1.ycoord += op2.ycoord;
00078   return op1;
00079 }
00080 
00081 
00085 inline ICOORD
00086 operator- (                      //subtract vectors
00087 const ICOORD & op1,              //operands
00088 const ICOORD & op2) {
00089   ICOORD sum;                    //result
00090 
00091   sum.xcoord = op1.xcoord - op2.xcoord;
00092   sum.ycoord = op1.ycoord - op2.ycoord;
00093   return sum;
00094 }
00095 
00096 
00100 inline ICOORD &
00101 operator-= (                     //sum vectors
00102 ICOORD & op1,                    //operands
00103 const ICOORD & op2) {
00104   op1.xcoord -= op2.xcoord;
00105   op1.ycoord -= op2.ycoord;
00106   return op1;
00107 }
00108 
00109 
00113 inline INT32
00114 operator% (                      //scalar product
00115 const ICOORD & op1,              //operands
00116 const ICOORD & op2) {
00117   return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
00118 }
00119 
00120 
00124 inline INT32 operator *(                    //cross product
00125                         const ICOORD &op1,  //operands
00126                         const ICOORD &op2) {
00127   return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
00128 }
00129 
00130 
00134 inline ICOORD operator *(                    //scalar multiply
00135                          const ICOORD &op1,  //operands
00136                          INT16 scale) {
00137   ICOORD result;                 //output
00138 
00139   result.xcoord = op1.xcoord * scale;
00140   result.ycoord = op1.ycoord * scale;
00141   return result;
00142 }
00143 
00144 
00145 inline ICOORD operator *(                   //scalar multiply
00146                          INT16 scale,
00147                          const ICOORD &op1  //operands
00148                         ) {
00149   ICOORD result;                 //output
00150 
00151   result.xcoord = op1.xcoord * scale;
00152   result.ycoord = op1.ycoord * scale;
00153   return result;
00154 }
00155 
00156 
00160 inline ICOORD &
00161 operator*= (                     //scalar multiply
00162 ICOORD & op1,                    //operands
00163 INT16 scale) {
00164   op1.xcoord *= scale;
00165   op1.ycoord *= scale;
00166   return op1;
00167 }
00168 
00169 
00174 inline ICOORD
00175 operator/ (                      //scalar divide
00176 const ICOORD & op1,              //operands
00177 INT16 scale) {
00178   ICOORD result;                 //output
00179 
00180   result.xcoord = op1.xcoord / scale;
00181   result.ycoord = op1.ycoord / scale;
00182   return result;
00183 }
00184 
00185 
00189 inline ICOORD &
00190 operator/= (                     //scalar divide
00191 ICOORD & op1,                    //operands
00192 INT16 scale) {
00193   op1.xcoord /= scale;
00194   op1.ycoord /= scale;
00195   return op1;
00196 }
00197 
00198 
00202 inline void ICOORD::rotate(  //rotate by vector
00203                            const FCOORD& vec) {
00204   INT16 tmp;
00205 
00206   tmp = (INT16) floor (xcoord * vec.x () - ycoord * vec.y () + 0.5);
00207   ycoord = (INT16) floor (ycoord * vec.x () + xcoord * vec.y () + 0.5);
00208   xcoord = tmp;
00209 }
00210 
00211 
00215 inline FCOORD
00216 operator! (                      //rotate 90 deg anti
00217 const FCOORD & src               //thing to rotate
00218 ) {
00219   FCOORD result;                 //output
00220 
00221   result.xcoord = -src.ycoord;
00222   result.ycoord = src.xcoord;
00223   return result;
00224 }
00225 
00226 
00230 inline FCOORD
00231 operator- (                      //unary minus
00232 const FCOORD & src               //thing to minus
00233 ) {
00234   FCOORD result;                 //output
00235 
00236   result.xcoord = -src.xcoord;
00237   result.ycoord = -src.ycoord;
00238   return result;
00239 }
00240 
00241 
00245 inline FCOORD
00246 operator+ (                      //sum vectors
00247 const FCOORD & op1,              //operands
00248 const FCOORD & op2) {
00249   FCOORD sum;                    //result
00250 
00251   sum.xcoord = op1.xcoord + op2.xcoord;
00252   sum.ycoord = op1.ycoord + op2.ycoord;
00253   return sum;
00254 }
00255 
00256 
00260 inline FCOORD &
00261 operator+= (                     //sum vectors
00262 FCOORD & op1,                    //operands
00263 const FCOORD & op2) {
00264   op1.xcoord += op2.xcoord;
00265   op1.ycoord += op2.ycoord;
00266   return op1;
00267 }
00268 
00269 
00273 inline FCOORD
00274 operator- (                      //subtract vectors
00275 const FCOORD & op1,              //operands
00276 const FCOORD & op2) {
00277   FCOORD sum;                    //result
00278 
00279   sum.xcoord = op1.xcoord - op2.xcoord;
00280   sum.ycoord = op1.ycoord - op2.ycoord;
00281   return sum;
00282 }
00283 
00284 
00288 inline FCOORD &
00289 operator-= (                     //sum vectors
00290 FCOORD & op1,                    //operands
00291 const FCOORD & op2) {
00292   op1.xcoord -= op2.xcoord;
00293   op1.ycoord -= op2.ycoord;
00294   return op1;
00295 }
00296 
00297 
00301 inline float
00302 operator% (                      //scalar product
00303 const FCOORD & op1,              //operands
00304 const FCOORD & op2) {
00305   return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
00306 }
00307 
00308 
00312 inline float operator *(                    //cross product
00313                         const FCOORD &op1,  //operands
00314                         const FCOORD &op2) {
00315   return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
00316 }
00317 
00318 
00322 inline FCOORD operator *(                    //scalar multiply
00323                          const FCOORD &op1,  //operands
00324                          float scale) {
00325   FCOORD result;                 //output
00326 
00327   result.xcoord = op1.xcoord * scale;
00328   result.ycoord = op1.ycoord * scale;
00329   return result;
00330 }
00331 
00332 
00333 inline FCOORD operator *(                   //scalar multiply
00334                          float scale,
00335                          const FCOORD &op1  //operands
00336                         ) {
00337   FCOORD result;                 //output
00338 
00339   result.xcoord = op1.xcoord * scale;
00340   result.ycoord = op1.ycoord * scale;
00341   return result;
00342 }
00343 
00344 
00348 inline FCOORD &
00349 operator*= (                     //scalar multiply
00350 FCOORD & op1,                    //operands
00351 float scale) {
00352   op1.xcoord *= scale;
00353   op1.ycoord *= scale;
00354   return op1;
00355 }
00356 
00357 
00361 inline FCOORD
00362 operator/ (                      //scalar divide
00363 const FCOORD & op1,              //operands
00364 float scale) {
00365   FCOORD result;                 //output
00366 
00367   if (scale != 0) {
00368     result.xcoord = op1.xcoord / scale;
00369     result.ycoord = op1.ycoord / scale;
00370   }
00371   return result;
00372 }
00373 
00374 
00378 inline FCOORD &
00379 operator/= (                     //scalar divide
00380 FCOORD & op1,                    //operands
00381 float scale) {
00382   if (scale != 0) {
00383     op1.xcoord /= scale;
00384     op1.ycoord /= scale;
00385   }
00386   return op1;
00387 }
00388 
00389 
00393 inline void FCOORD::rotate(  //rotate by vector
00394                            const FCOORD vec) {
00395   float tmp;
00396 
00397   tmp = xcoord * vec.x () - ycoord * vec.y ();
00398   ycoord = ycoord * vec.x () + xcoord * vec.y ();
00399   xcoord = tmp;
00400 }
00401 #endif

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1