tesseract v5.3.3.20231005
tesseract::DIR128 Class Reference

#include <mod128.h>

Public Member Functions

 DIR128 ()=default
 
 DIR128 (int16_t value)
 
 DIR128 (const FCOORD fc)
 
DIR128operator= (int16_t value)
 
int8_t operator- (const DIR128 &minus) const
 
DIR128 operator+ (const DIR128 &add) const
 
DIR128operator+= (const DIR128 &add)
 
int8_t get_dir () const
 

Public Attributes

int8_t dir
 

Detailed Description

Definition at line 30 of file mod128.h.

Constructor & Destructor Documentation

◆ DIR128() [1/3]

tesseract::DIR128::DIR128 ( )
default

◆ DIR128() [2/3]

tesseract::DIR128::DIR128 ( int16_t  value)
inline

Definition at line 34 of file mod128.h.

35 { // value to assign
36 value %= MODULUS; // modulo arithmetic
37 if (value < 0) {
38 value += MODULUS; // done properly
39 }
40 dir = static_cast<int8_t>(value);
41 }
#define MODULUS
Definition: mod128.h:26
int value
int8_t dir
Definition: mod128.h:83

◆ DIR128() [3/3]

tesseract::DIR128::DIR128 ( const FCOORD  fc)

Definition at line 51 of file mod128.cpp.

53 {
54 int high, low, current; // binary search
55
56 low = 0;
57 if (fc.y() == 0) {
58 if (fc.x() >= 0) {
59 dir = 0;
60 } else {
61 dir = MODULUS / 2;
62 }
63 return;
64 }
65 high = MODULUS;
66 do {
67 current = (high + low) / 2;
68 if (dirtab[current] * fc >= 0) {
69 low = current;
70 } else {
71 high = current;
72 }
73 } while (high - low > 1);
74 dir = low;
75}

Member Function Documentation

◆ get_dir()

int8_t tesseract::DIR128::get_dir ( ) const
inline

Definition at line 79 of file mod128.h.

79 { // access function
80 return dir;
81 }

◆ operator+()

DIR128 tesseract::DIR128::operator+ ( const DIR128 add) const
inline

Definition at line 66 of file mod128.h.

68 {
69 DIR128 result; // sum
70
71 result = dir + add.dir; // let = do the work
72 return result;
73 }

◆ operator+=()

DIR128 & tesseract::DIR128::operator+= ( const DIR128 add)
inline

Definition at line 74 of file mod128.h.

75 {
76 *this = dir + add.dir; // let = do the work
77 return *this;
78 }

◆ operator-()

int8_t tesseract::DIR128::operator- ( const DIR128 minus) const
inline

Definition at line 53 of file mod128.h.

55 {
56 // result
57 int16_t result = dir - minus.dir;
58
59 if (result > MODULUS / 2) {
60 result -= MODULUS; // get in range
61 } else if (result < -MODULUS / 2) {
62 result += MODULUS;
63 }
64 return static_cast<int8_t>(result);
65 }

◆ operator=()

DIR128 & tesseract::DIR128::operator= ( int16_t  value)
inline

Definition at line 44 of file mod128.h.

45 { // value to assign
46 value %= MODULUS; // modulo arithmetic
47 if (value < 0) {
48 value += MODULUS; // done properly
49 }
50 dir = static_cast<int8_t>(value);
51 return *this;
52 }

Member Data Documentation

◆ dir

int8_t tesseract::DIR128::dir

Definition at line 83 of file mod128.h.


The documentation for this class was generated from the following files: