DIR128 Class Reference

#include <mod128.h>

List of all members.


Detailed Description

Class which implements modulo arithmetic.

Definition at line 36 of file mod128.h.

Public Member Functions

Private Attributes


Constructor & Destructor Documentation

DIR128::DIR128 (  )  [inline]

Definition at line 39 of file mod128.h.

00039              { 
00040     }                            //empty constructor

DIR128::DIR128 ( INT16  value  )  [inline]

Definition at line 42 of file mod128.h.

References MODULUS.

00043                         {  //value to assign
00044       value %= MODULUS;          //modulo arithmetic
00045       if (value < 0)
00046         value += MODULUS;        //done properly
00047       dir = (INT8) value;
00048     }

DIR128::DIR128 ( const FCOORD  fc  ) 

Quantize the direction of an FCOORD to make a DIR128.

Definition at line 64 of file mod128.cpp.

References dir, dirtab, and MODULUS.

00066                 {
00067   int high, low, current;        //binary search
00068 
00069   low = 0;
00070   if (fc.y () == 0) {
00071     if (fc.x () >= 0)
00072       dir = 0;
00073     else
00074       dir = MODULUS / 2;
00075     return;
00076   }
00077   high = MODULUS;
00078   do {
00079     current = (high + low) / 2;
00080     if (dirtab[current] * fc >= 0)
00081       low = current;
00082     else
00083       high = current;
00084   }
00085   while (high - low > 1);
00086   dir = low;
00087 }


Member Function Documentation

INT8 DIR128::get_dir (  )  const [inline]

Definition at line 84 of file mod128.h.

Referenced by edgesteps_to_edgepts().

00084                          {  //access function
00085       return dir;
00086     }

DIR128 DIR128::operator+ ( const DIR128 add  )  const [inline]

Definition at line 71 of file mod128.h.

References dir.

00073     {
00074       DIR128 result;             //sum
00075 
00076       result = dir + add.dir;    //let = do the work
00077       return result;
00078     }

DIR128& DIR128::operator+= ( const DIR128 add  )  [inline]

Definition at line 79 of file mod128.h.

References dir.

00080                         {
00081       *this = dir + add.dir;     //let = do the work
00082       return *this;
00083     }

INT8 DIR128::operator- ( const DIR128 minus  )  const [inline]

Definition at line 59 of file mod128.h.

References MODULUS.

00061     {
00062                                  //result
00063       INT16 result = dir - minus.dir;
00064 
00065       if (result > MODULUS / 2)
00066         result -= MODULUS;       //get in range
00067       else if (result < -MODULUS / 2)
00068         result += MODULUS;
00069       return (INT8) result;
00070     }

DIR128& DIR128::operator= ( INT16  value  )  [inline]

Definition at line 51 of file mod128.h.

References MODULUS.

00052                  {               //value to assign
00053       value %= MODULUS;          //modulo arithmetic
00054       if (value < 0)
00055         value += MODULUS;        //done properly
00056       dir = (INT8) value;
00057       return *this;
00058     }

ICOORD DIR128::vector (  )  const

Convert a direction to a vector.

Definition at line 93 of file mod128.cpp.

References dir, and dirtab.

00093                             {  //convert to vector
00094   return dirtab[dir];            //easy really
00095 }


Member Data Documentation

INT8 DIR128::dir [private]

Definition at line 90 of file mod128.h.

Referenced by DIR128(), operator+(), operator+=(), and vector().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:31 2007 for Tesseract by  doxygen 1.5.1