tesseract 4.1.1
Loading...
Searching...
No Matches
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
 

Detailed Description

Definition at line 29 of file mod128.h.

Constructor & Destructor Documentation

◆ DIR128() [1/3]

DIR128::DIR128 ( )
default

◆ DIR128() [2/3]

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 dir = static_cast<int8_t>(value);
40 }
#define MODULUS
Definition: mod128.h:25

◆ DIR128() [3/3]

DIR128::DIR128 ( const FCOORD  fc)

Definition at line 64 of file mod128.cpp.

66 {
67 int high, low, current; //binary search
68
69 low = 0;
70 if (fc.y () == 0) {
71 if (fc.x () >= 0)
72 dir = 0;
73 else
74 dir = MODULUS / 2;
75 return;
76 }
77 high = MODULUS;
78 do {
79 current = (high + low) / 2;
80 if (dirtab[current] * fc >= 0)
81 low = current;
82 else
83 high = current;
84 }
85 while (high - low > 1);
86 dir = low;
87}
float y() const
Definition: points.h:210
float x() const
Definition: points.h:207

Member Function Documentation

◆ get_dir()

int8_t DIR128::get_dir ( ) const
inline

Definition at line 76 of file mod128.h.

76 { //access function
77 return dir;
78 }

◆ operator+()

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

Definition at line 63 of file mod128.h.

65 {
66 DIR128 result; //sum
67
68 result = dir + add.dir; //let = do the work
69 return result;
70 }
Definition: mod128.h:30

◆ operator+=()

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

Definition at line 71 of file mod128.h.

72 {
73 *this = dir + add.dir; //let = do the work
74 return *this;
75 }

◆ operator-()

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

Definition at line 51 of file mod128.h.

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 }

◆ operator=()

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

Definition at line 43 of file mod128.h.

44 { //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 }

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