Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mod128.h
Go to the documentation of this file.
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() {
33 } //empty constructor
34
35 DIR128( //constructor
36 inT16 value) { //value to assign
37 value %= MODULUS; //modulo arithmetic
38 if (value < 0)
39 value += MODULUS; //done properly
40 dir = (inT8) value;
41 }
42 DIR128(const FCOORD fc); //quantize vector
43
44 DIR128 & operator= ( //assign of inT16
45 inT16 value) { //value to assign
46 value %= MODULUS; //modulo arithmetic
47 if (value < 0)
48 value += MODULUS; //done properly
49 dir = (inT8) value;
50 return *this;
51 }
52 inT8 operator- ( //subtraction
53 const DIR128 & minus) const//for signed result
54 {
55 //result
56 inT16 result = dir - minus.dir;
57
58 if (result > MODULUS / 2)
59 result -= MODULUS; //get in range
60 else if (result < -MODULUS / 2)
61 result += MODULUS;
62 return (inT8) result;
63 }
64 DIR128 operator+ ( //addition
65 const DIR128 & add) const //of itself
66 {
67 DIR128 result; //sum
68
69 result = dir + add.dir; //let = do the work
70 return result;
71 }
72 DIR128 & operator+= ( //same as +
73 const DIR128 & add) {
74 *this = dir + add.dir; //let = do the work
75 return *this;
76 }
77 inT8 get_dir() const { //access function
78 return dir;
79 }
80 ICOORD vector() const; //turn to vector
81
82 private:
83 inT8 dir; //a direction
84 };
85 #endif