tesseract  4.00.00dev
ICOORD Class Reference

integer coordinate More...

#include <points.h>

Inheritance diagram for ICOORD:
ICOORDELT

Public Member Functions

 ICOORD ()
 empty constructor More...
 
 ICOORD (inT16 xin, inT16 yin)
 
 ~ICOORD ()
 destructor More...
 
inT16 x () const
 access function More...
 
inT16 y () const
 access_function More...
 
void set_x (inT16 xin)
 rewrite function More...
 
void set_y (inT16 yin)
 rewrite function More...
 
void set_with_shrink (int x, int y)
 Set from the given x,y, shrinking the vector to fit if needed. More...
 
float sqlength () const
 find sq length More...
 
float length () const
 find length More...
 
float pt_to_pt_sqdist (const ICOORD &pt) const
 sq dist between pts More...
 
float pt_to_pt_dist (const ICOORD &pt) const
 Distance between pts. More...
 
float angle () const
 find angle More...
 
BOOL8 operator== (const ICOORD &other) const
 test equality More...
 
BOOL8 operator!= (const ICOORD &other) const
 test inequality More...
 
void rotate (const FCOORD &vec)
 
void setup_render (ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 

Protected Attributes

inT16 xcoord
 
inT16 ycoord
 

Friends

class FCOORD
 
ICOORD operator! (const ICOORD &)
 rotate 90 deg anti More...
 
ICOORD operator- (const ICOORD &)
 unary minus More...
 
ICOORD operator+ (const ICOORD &, const ICOORD &)
 add More...
 
ICOORDoperator+= (ICOORD &, const ICOORD &)
 add More...
 
ICOORD operator- (const ICOORD &, const ICOORD &)
 subtract More...
 
ICOORDoperator-= (ICOORD &, const ICOORD &)
 subtract More...
 
inT32 operator% (const ICOORD &, const ICOORD &)
 scalar product More...
 
inT32 operator* (const ICOORD &, const ICOORD &)
 cross product More...
 
ICOORD operator* (const ICOORD &, inT16)
 multiply More...
 
ICOORD operator* (inT16, const ICOORD &)
 multiply More...
 
ICOORDoperator*= (ICOORD &, inT16)
 multiply More...
 
ICOORD operator/ (const ICOORD &, inT16)
 divide More...
 
ICOORDoperator/= (ICOORD &, inT16)
 divide More...
 

Detailed Description

integer coordinate

Definition at line 30 of file points.h.

Constructor & Destructor Documentation

◆ ICOORD() [1/2]

ICOORD::ICOORD ( )
inline

empty constructor

Definition at line 36 of file points.h.

36  {
37  xcoord = ycoord = 0; //default zero
38  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ ICOORD() [2/2]

ICOORD::ICOORD ( inT16  xin,
inT16  yin 
)
inline

constructor

Parameters
xinx value
yiny value

Definition at line 42 of file points.h.

43  {
44  xcoord = xin;
45  ycoord = yin;
46  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ ~ICOORD()

ICOORD::~ICOORD ( )
inline

destructor

Definition at line 48 of file points.h.

48  {
49  }

Member Function Documentation

◆ angle()

float ICOORD::angle ( ) const
inline

find angle

Definition at line 97 of file points.h.

97  {
98  return (float) atan2 ((double) ycoord, (double) xcoord);
99  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ DeSerialize()

bool ICOORD::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 70 of file points.cpp.

70  {
71  if (fread(&xcoord, sizeof(xcoord), 1, fp) != 1) return false;
72  if (fread(&ycoord, sizeof(ycoord), 1, fp) != 1) return false;
73  if (swap) {
74  ReverseN(&xcoord, sizeof(xcoord));
75  ReverseN(&ycoord, sizeof(ycoord));
76  }
77  return true;
78 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:184

◆ length()

float ICOORD::length ( ) const
inline

find length

Definition at line 78 of file points.h.

78  {
79  return (float) sqrt (sqlength ());
80  }
float sqlength() const
find sq length
Definition: points.h:73

◆ operator!=()

BOOL8 ICOORD::operator!= ( const ICOORD other) const
inline

test inequality

Definition at line 106 of file points.h.

106  {
107  return xcoord != other.xcoord || ycoord != other.ycoord;
108  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ operator==()

BOOL8 ICOORD::operator== ( const ICOORD other) const
inline

test equality

Definition at line 102 of file points.h.

102  {
103  return xcoord == other.xcoord && ycoord == other.ycoord;
104  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ pt_to_pt_dist()

float ICOORD::pt_to_pt_dist ( const ICOORD pt) const
inline

Distance between pts.

Definition at line 92 of file points.h.

92  {
93  return (float) sqrt (pt_to_pt_sqdist (pt));
94  }
float pt_to_pt_sqdist(const ICOORD &pt) const
sq dist between pts
Definition: points.h:83

◆ pt_to_pt_sqdist()

float ICOORD::pt_to_pt_sqdist ( const ICOORD pt) const
inline

sq dist between pts

Definition at line 83 of file points.h.

83  {
84  ICOORD gap;
85 
86  gap.xcoord = xcoord - pt.xcoord;
87  gap.ycoord = ycoord - pt.ycoord;
88  return gap.sqlength ();
89  }
float sqlength() const
find sq length
Definition: points.h:73
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ rotate()

void ICOORD::rotate ( const FCOORD vec)
inline

rotate

Parameters
vecby vector

Definition at line 241 of file ipoints.h.

242  {
243  inT16 tmp;
244 
245  tmp = (inT16) floor (xcoord * vec.x () - ycoord * vec.y () + 0.5);
246  ycoord = (inT16) floor (ycoord * vec.x () + xcoord * vec.y () + 0.5);
247  xcoord = tmp;
248 }
inT16 ycoord
Definition: points.h:158
int16_t inT16
Definition: host.h:36
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
inT16 xcoord
Definition: points.h:157

◆ Serialize()

bool ICOORD::Serialize ( FILE *  fp) const

Definition at line 63 of file points.cpp.

63  {
64  if (fwrite(&xcoord, sizeof(xcoord), 1, fp) != 1) return false;
65  if (fwrite(&ycoord, sizeof(ycoord), 1, fp) != 1) return false;
66  return true;
67 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ set_with_shrink()

void ICOORD::set_with_shrink ( int  x,
int  y 
)

Set from the given x,y, shrinking the vector to fit if needed.

Definition at line 43 of file points.cpp.

43  {
44  // Fit the vector into an ICOORD, which is 16 bit.
45  int factor = 1;
46  int max_extent = MAX(abs(x), abs(y));
47  if (max_extent > MAX_INT16)
48  factor = max_extent / MAX_INT16 + 1;
49  xcoord = x / factor;
50  ycoord = y / factor;
51 }
#define MAX_INT16
Definition: host.h:61
inT16 x() const
access function
Definition: points.h:52
inT16 ycoord
Definition: points.h:158
inT16 y() const
access_function
Definition: points.h:56
#define MAX(x, y)
Definition: ndminx.h:24
inT16 xcoord
Definition: points.h:157

◆ set_x()

void ICOORD::set_x ( inT16  xin)
inline

rewrite function

Definition at line 61 of file points.h.

61  {
62  xcoord = xin; //write new value
63  }
inT16 xcoord
Definition: points.h:157

◆ set_y()

void ICOORD::set_y ( inT16  yin)
inline

rewrite function

Definition at line 65 of file points.h.

65  { //value to set
66  ycoord = yin;
67  }
inT16 ycoord
Definition: points.h:158

◆ setup_render()

void ICOORD::setup_render ( ICOORD major_step,
ICOORD minor_step,
int major,
int minor 
) const

Setup for iterating over the pixels in a vector by the well-known Bresenham rendering algorithm. Starting with major/2 in the accumulator, on each step move by major_step, and then add minor to the accumulator. When accumulator >= major subtract major and also move by minor_step.

Definition at line 86 of file points.cpp.

87  {
88  int abs_x = abs(xcoord);
89  int abs_y = abs(ycoord);
90  if (abs_x >= abs_y) {
91  // X-direction is major.
92  major_step->xcoord = sign(xcoord);
93  major_step->ycoord = 0;
94  minor_step->xcoord = 0;
95  minor_step->ycoord = sign(ycoord);
96  *major = abs_x;
97  *minor = abs_y;
98  } else {
99  // Y-direction is major.
100  major_step->xcoord = 0;
101  major_step->ycoord = sign(ycoord);
102  minor_step->xcoord = sign(xcoord);
103  minor_step->ycoord = 0;
104  *major = abs_y;
105  *minor = abs_x;
106  }
107 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ sqlength()

float ICOORD::sqlength ( ) const
inline

find sq length

Definition at line 73 of file points.h.

73  {
74  return (float) (xcoord * xcoord + ycoord * ycoord);
75  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ x()

inT16 ICOORD::x ( ) const
inline

access function

Definition at line 52 of file points.h.

52  {
53  return xcoord;
54  }
inT16 xcoord
Definition: points.h:157

◆ y()

inT16 ICOORD::y ( ) const
inline

access_function

Definition at line 56 of file points.h.

56  {
57  return ycoord;
58  }
inT16 ycoord
Definition: points.h:158

Friends And Related Function Documentation

◆ FCOORD

friend class FCOORD
friend

Definition at line 32 of file points.h.

◆ operator!

ICOORD operator! ( const ICOORD src)
friend

rotate 90 deg anti

Definition at line 32 of file ipoints.h.

34  {
35  ICOORD result; //output
36 
37  result.xcoord = -src.ycoord;
38  result.ycoord = src.xcoord;
39  return result;
40 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator%

inT32 operator% ( const ICOORD op1,
const ICOORD op2 
)
friend

scalar product

Definition at line 136 of file ipoints.h.

138  {
139  return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
140 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ operator* [1/3]

inT32 operator* ( const ICOORD op1,
const ICOORD op2 
)
friend

cross product

Definition at line 149 of file ipoints.h.

151  {
152  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
153 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ operator* [2/3]

ICOORD operator* ( const ICOORD op1,
inT16  scale 
)
friend

multiply

Definition at line 162 of file ipoints.h.

164  {
165  ICOORD result; //output
166 
167  result.xcoord = op1.xcoord * scale;
168  result.ycoord = op1.ycoord * scale;
169  return result;
170 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator* [3/3]

ICOORD operator* ( inT16  scale,
const ICOORD op1 
)
friend

multiply

Definition at line 173 of file ipoints.h.

176  {
177  ICOORD result; //output
178 
179  result.xcoord = op1.xcoord * scale;
180  result.ycoord = op1.ycoord * scale;
181  return result;
182 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator*=

ICOORD& operator*= ( ICOORD op1,
inT16  scale 
)
friend

multiply

Definition at line 192 of file ipoints.h.

194  {
195  op1.xcoord *= scale;
196  op1.ycoord *= scale;
197  return op1;
198 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ operator+

ICOORD operator+ ( const ICOORD op1,
const ICOORD op2 
)
friend

add

Definition at line 68 of file ipoints.h.

70  {
71  ICOORD sum; //result
72 
73  sum.xcoord = op1.xcoord + op2.xcoord;
74  sum.ycoord = op1.ycoord + op2.ycoord;
75  return sum;
76 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator+=

ICOORD& operator+= ( ICOORD op1,
const ICOORD op2 
)
friend

add

Definition at line 86 of file ipoints.h.

88  {
89  op1.xcoord += op2.xcoord;
90  op1.ycoord += op2.ycoord;
91  return op1;
92 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ operator- [1/2]

ICOORD operator- ( const ICOORD src)
friend

unary minus

Definition at line 50 of file ipoints.h.

52  {
53  ICOORD result; //output
54 
55  result.xcoord = -src.xcoord;
56  result.ycoord = -src.ycoord;
57  return result;
58 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator- [2/2]

ICOORD operator- ( const ICOORD op1,
const ICOORD op2 
)
friend

subtract

Definition at line 102 of file ipoints.h.

104  {
105  ICOORD sum; //result
106 
107  sum.xcoord = op1.xcoord - op2.xcoord;
108  sum.ycoord = op1.ycoord - op2.ycoord;
109  return sum;
110 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator-=

ICOORD& operator-= ( ICOORD op1,
const ICOORD op2 
)
friend

subtract

Definition at line 120 of file ipoints.h.

122  {
123  op1.xcoord -= op2.xcoord;
124  op1.ycoord -= op2.ycoord;
125  return op1;
126 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

◆ operator/

ICOORD operator/ ( const ICOORD op1,
inT16  scale 
)
friend

divide

Definition at line 208 of file ipoints.h.

210  {
211  ICOORD result; //output
212 
213  result.xcoord = op1.xcoord / scale;
214  result.ycoord = op1.ycoord / scale;
215  return result;
216 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157
integer coordinate
Definition: points.h:30

◆ operator/=

ICOORD& operator/= ( ICOORD op1,
inT16  scale 
)
friend

divide

Definition at line 226 of file ipoints.h.

228  {
229  op1.xcoord /= scale;
230  op1.ycoord /= scale;
231  return op1;
232 }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

Member Data Documentation

◆ xcoord

inT16 ICOORD::xcoord
protected

Definition at line 157 of file points.h.

◆ ycoord

inT16 ICOORD::ycoord
protected

Definition at line 158 of file points.h.


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