tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
mod128.h
1 /**********************************************************************
2  * File: mod128.h (Formerly dir128.h)
3  * Description: Header for class which implements modulo arithmetic.
4  * Author: Ray Smith
5  * Created: Tue Mar 26 17:48:13 GMT 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef MOD128_H
21 #define MOD128_H
22 
23 #include "points.h"
24 
25 #define MODULUS 128 /*range of directions */
26 #define DIRBITS 7 //no of bits used
27 #define DIRSCALE 1000 //length of vector
28 
29 class DLLSYM DIR128
30 {
31  public:
32  DIR128() = default;
33 
34  DIR128( //constructor
35  int16_t value) { //value to assign
36  value %= MODULUS; //modulo arithmetic
37  if (value < 0)
38  value += MODULUS; //done properly
39  dir = (int8_t) value;
40  }
41  DIR128(const FCOORD fc); //quantize vector
42 
43  DIR128 & operator= ( //assign of int16_t
44  int16_t value) { //value to assign
45  value %= MODULUS; //modulo arithmetic
46  if (value < 0)
47  value += MODULUS; //done properly
48  dir = (int8_t) value;
49  return *this;
50  }
51  int8_t operator- ( //subtraction
52  const DIR128 & minus) const//for signed result
53  {
54  //result
55  int16_t result = dir - minus.dir;
56 
57  if (result > MODULUS / 2)
58  result -= MODULUS; //get in range
59  else if (result < -MODULUS / 2)
60  result += MODULUS;
61  return (int8_t) result;
62  }
63  DIR128 operator+ ( //addition
64  const DIR128 & add) const //of itself
65  {
66  DIR128 result; //sum
67 
68  result = dir + add.dir; //let = do the work
69  return result;
70  }
71  DIR128 & operator+= ( //same as +
72  const DIR128 & add) {
73  *this = dir + add.dir; //let = do the work
74  return *this;
75  }
76  int8_t get_dir() const { //access function
77  return dir;
78  }
79 
80  private:
81  int8_t dir; //a direction
82 };
83 #endif
int8_t dir
Definition: mod128.h:81
Definition: mod128.h:29
DIR128(int16_t value)
Definition: mod128.h:34
int8_t get_dir() const
Definition: mod128.h:76
Definition: points.h:189