Tesseract  3.02
tesseract-ocr/ccstruct/mod128.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        mod128.h  (Formerly dir128.h)
00003  * Description: Header for class which implements modulo arithmetic.
00004  * Author:                                      Ray Smith
00005  * Created:                                     Tue Mar 26 17:48:13 GMT 1991
00006  *
00007  * (C) Copyright 1991, Hewlett-Packard Ltd.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef           MOD128_H
00021 #define           MOD128_H
00022 
00023 #include          "points.h"
00024 
00025 #define MODULUS       128        /*range of directions */
00026 #define DIRBITS       7          //no of bits used
00027 #define DIRSCALE      1000       //length of vector
00028 
00029 class DLLSYM DIR128
00030 {
00031   public:
00032     DIR128() {
00033     }                            //empty constructor
00034 
00035     DIR128(                //constructor
00036            inT16 value) {  //value to assign
00037       value %= MODULUS;          //modulo arithmetic
00038       if (value < 0)
00039         value += MODULUS;        //done properly
00040       dir = (inT8) value;
00041     }
00042     DIR128(const FCOORD fc);  //quantize vector
00043 
00044     DIR128 & operator= (         //assign of inT16
00045     inT16 value) {               //value to assign
00046       value %= MODULUS;          //modulo arithmetic
00047       if (value < 0)
00048         value += MODULUS;        //done properly
00049       dir = (inT8) value;
00050       return *this;
00051     }
00052     inT8 operator- (             //subtraction
00053       const DIR128 & minus) const//for signed result
00054     {
00055                                  //result
00056       inT16 result = dir - minus.dir;
00057 
00058       if (result > MODULUS / 2)
00059         result -= MODULUS;       //get in range
00060       else if (result < -MODULUS / 2)
00061         result += MODULUS;
00062       return (inT8) result;
00063     }
00064     DIR128 operator+ (           //addition
00065       const DIR128 & add) const  //of itself
00066     {
00067       DIR128 result;             //sum
00068 
00069       result = dir + add.dir;    //let = do the work
00070       return result;
00071     }
00072     DIR128 & operator+= (        //same as +
00073     const DIR128 & add) {
00074       *this = dir + add.dir;     //let = do the work
00075       return *this;
00076     }
00077     inT8 get_dir() const {  //access function
00078       return dir;
00079     }
00080     ICOORD vector() const;  //turn to vector
00081 
00082   private:
00083     inT8 dir;                    //a direction
00084 };
00085 #endif