tesseract
4.1.1
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
() =
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 =
static_cast<
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 =
static_cast<
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
static_cast<
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
FCOORD
Definition:
points.h:189
DLLSYM
#define DLLSYM
Definition:
platform.h:21
operator+=
ICOORD & operator+=(ICOORD &op1, const ICOORD &op2)
Definition:
points.h:381
DIR128::DIR128
DIR128(int16_t value)
Definition:
mod128.h:34
MODULUS
#define MODULUS
Definition:
mod128.h:25
operator-
ICOORD operator-(const ICOORD &src)
Definition:
points.h:345
points.h
DIR128
Definition:
mod128.h:30
DIR128::DIR128
DIR128()=default
DIR128::get_dir
int8_t get_dir() const
Definition:
mod128.h:76
operator+
ICOORD operator+(const ICOORD &op1, const ICOORD &op2)
Definition:
points.h:363
src
ccstruct
mod128.h
Generated on Thu Mar 26 2020 00:00:00 for tesseract by
1.8.18