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

◆ DIR128() [3/3]

DIR128::DIR128 ( const FCOORD  fc)

Definition at line 65 of file mod128.cpp.

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

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:29

◆ 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 (int8_t) result;
62  }
#define MODULUS
Definition: mod128.h:25

◆ 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 = (int8_t) value;
49  return *this;
50  }
#define MODULUS
Definition: mod128.h:25

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