tesseract  4.1.1
ICOORD Class Reference

integer coordinate More...

#include <points.h>

Inheritance diagram for ICOORD:
ICOORDELT

Public Member Functions

 ICOORD ()
 empty constructor More...
 
 ICOORD (int16_t xin, int16_t yin)
 
 ~ICOORD ()=default
 destructor More...
 
int16_t x () const
 access function More...
 
int16_t y () const
 access_function More...
 
void set_x (int16_t xin)
 rewrite function More...
 
void set_y (int16_t 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...
 
bool operator== (const ICOORD &other) const
 test equality More...
 
bool 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_t xcoord
 x value More...
 
int16_t ycoord
 y value More...
 

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_t operator% (const ICOORD &, const ICOORD &)
 scalar product More...
 
int32_t operator* (const ICOORD &, const ICOORD &)
 cross product More...
 
ICOORD operator* (const ICOORD &, int16_t)
 multiply More...
 
ICOORD operator* (int16_t, const ICOORD &)
 multiply More...
 
ICOORDoperator*= (ICOORD &, int16_t)
 multiply More...
 
ICOORD operator/ (const ICOORD &, int16_t)
 divide More...
 
ICOORDoperator/= (ICOORD &, int16_t)
 divide More...
 

Detailed Description

integer coordinate

Definition at line 31 of file points.h.

Constructor & Destructor Documentation

◆ ICOORD() [1/2]

ICOORD::ICOORD ( )
inline

empty constructor

Definition at line 37 of file points.h.

37  {
38  xcoord = ycoord = 0; //default zero
39  }

◆ ICOORD() [2/2]

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

constructor

Parameters
xinx value
yiny value

Definition at line 43 of file points.h.

44  {
45  xcoord = xin;
46  ycoord = yin;
47  }

◆ ~ICOORD()

ICOORD::~ICOORD ( )
default

destructor

Member Function Documentation

◆ angle()

float ICOORD::angle ( ) const
inline

find angle

Definition at line 97 of file points.h.

97  {
98  return std::atan2(ycoord, xcoord);
99  }

◆ DeSerialize()

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

Definition at line 67 of file points.cpp.

67  {
68  if (!tesseract::DeSerialize(fp, &xcoord)) return false;
69  if (!tesseract::DeSerialize(fp, &ycoord)) return false;
70  if (swap) {
71  ReverseN(&xcoord, sizeof(xcoord));
72  ReverseN(&ycoord, sizeof(ycoord));
73  }
74  return true;
75 }

◆ length()

float ICOORD::length ( ) const
inline

find length

Definition at line 78 of file points.h.

78  {
79  return std::sqrt(sqlength());
80  }

◆ operator!=()

bool 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  }

◆ operator==()

bool 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  }

◆ 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 std::sqrt(pt_to_pt_sqdist(pt));
94  }

◆ 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  }

◆ rotate()

void ICOORD::rotate ( const FCOORD vec)
inline

rotate

Parameters
vecby vector

Definition at line 536 of file points.h.

537  {
538  auto tmp = static_cast<int16_t>(std::floor(xcoord * vec.x() -
539  ycoord * vec.y() + 0.5f));
540  ycoord = static_cast<int16_t>(std::floor(ycoord * vec.x() +
541  xcoord * vec.y() + 0.5f));
542  xcoord = tmp;
543 }

◆ Serialize()

bool ICOORD::Serialize ( FILE *  fp) const

Definition at line 61 of file points.cpp.

61  {
62  return tesseract::Serialize(fp, &xcoord) &&
64 }

◆ 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 41 of file points.cpp.

41  {
42  // Fit the vector into an ICOORD, which is 16 bit.
43  int factor = 1;
44  int max_extent = std::max(abs(x), abs(y));
45  if (max_extent > INT16_MAX)
46  factor = max_extent / INT16_MAX + 1;
47  xcoord = x / factor;
48  ycoord = y / factor;
49 }

◆ set_x()

void ICOORD::set_x ( int16_t  xin)
inline

rewrite function

Definition at line 61 of file points.h.

61  {
62  xcoord = xin; //write new value
63  }

◆ set_y()

void ICOORD::set_y ( int16_t  yin)
inline

rewrite function

Definition at line 65 of file points.h.

65  { //value to set
66  ycoord = yin;
67  }

◆ 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 83 of file points.cpp.

84  {
85  int abs_x = abs(xcoord);
86  int abs_y = abs(ycoord);
87  if (abs_x >= abs_y) {
88  // X-direction is major.
89  major_step->xcoord = sign(xcoord);
90  major_step->ycoord = 0;
91  minor_step->xcoord = 0;
92  minor_step->ycoord = sign(ycoord);
93  *major = abs_x;
94  *minor = abs_y;
95  } else {
96  // Y-direction is major.
97  major_step->xcoord = 0;
98  major_step->ycoord = sign(ycoord);
99  minor_step->xcoord = sign(xcoord);
100  minor_step->ycoord = 0;
101  *major = abs_y;
102  *minor = abs_x;
103  }
104 }

◆ sqlength()

float ICOORD::sqlength ( ) const
inline

find sq length

Definition at line 73 of file points.h.

73  {
74  return xcoord * xcoord + ycoord * ycoord;
75  }

◆ x()

int16_t ICOORD::x ( ) const
inline

access function

Definition at line 52 of file points.h.

52  {
53  return xcoord;
54  }

◆ y()

int16_t ICOORD::y ( ) const
inline

access_function

Definition at line 56 of file points.h.

56  {
57  return ycoord;
58  }

Friends And Related Function Documentation

◆ FCOORD

friend class FCOORD
friend

Definition at line 33 of file points.h.

◆ operator!

ICOORD operator! ( const ICOORD src)
friend

rotate 90 deg anti

Definition at line 327 of file points.h.

329  {
330  ICOORD result; //output
331 
332  result.xcoord = -src.ycoord;
333  result.ycoord = src.xcoord;
334  return result;
335 }

◆ operator%

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

scalar product

Definition at line 431 of file points.h.

433  {
434  return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
435 }

◆ operator* [1/3]

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

cross product

Definition at line 444 of file points.h.

446  {
447  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
448 }

◆ operator* [2/3]

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

multiply

Definition at line 457 of file points.h.

459  {
460  ICOORD result; //output
461 
462  result.xcoord = op1.xcoord * scale;
463  result.ycoord = op1.ycoord * scale;
464  return result;
465 }

◆ operator* [3/3]

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

multiply

Definition at line 468 of file points.h.

471  {
472  ICOORD result; //output
473 
474  result.xcoord = op1.xcoord * scale;
475  result.ycoord = op1.ycoord * scale;
476  return result;
477 }

◆ operator*=

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

multiply

Definition at line 487 of file points.h.

489  {
490  op1.xcoord *= scale;
491  op1.ycoord *= scale;
492  return op1;
493 }

◆ operator+

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

add

Definition at line 363 of file points.h.

365  {
366  ICOORD sum; //result
367 
368  sum.xcoord = op1.xcoord + op2.xcoord;
369  sum.ycoord = op1.ycoord + op2.ycoord;
370  return sum;
371 }

◆ operator+=

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

add

Definition at line 381 of file points.h.

383  {
384  op1.xcoord += op2.xcoord;
385  op1.ycoord += op2.ycoord;
386  return op1;
387 }

◆ operator- [1/2]

ICOORD operator- ( const ICOORD src)
friend

unary minus

Definition at line 345 of file points.h.

347  {
348  ICOORD result; //output
349 
350  result.xcoord = -src.xcoord;
351  result.ycoord = -src.ycoord;
352  return result;
353 }

◆ operator- [2/2]

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

subtract

Definition at line 397 of file points.h.

399  {
400  ICOORD sum; //result
401 
402  sum.xcoord = op1.xcoord - op2.xcoord;
403  sum.ycoord = op1.ycoord - op2.ycoord;
404  return sum;
405 }

◆ operator-=

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

subtract

Definition at line 415 of file points.h.

417  {
418  op1.xcoord -= op2.xcoord;
419  op1.ycoord -= op2.ycoord;
420  return op1;
421 }

◆ operator/

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

divide

Definition at line 503 of file points.h.

505  {
506  ICOORD result; //output
507 
508  result.xcoord = op1.xcoord / scale;
509  result.ycoord = op1.ycoord / scale;
510  return result;
511 }

◆ operator/=

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

divide

Definition at line 521 of file points.h.

523  {
524  op1.xcoord /= scale;
525  op1.ycoord /= scale;
526  return op1;
527 }

Member Data Documentation

◆ xcoord

int16_t ICOORD::xcoord
protected

x value

Definition at line 157 of file points.h.

◆ ycoord

int16_t ICOORD::ycoord
protected

y value

Definition at line 158 of file points.h.


The documentation for this class was generated from the following files:
ICOORD::sqlength
float sqlength() const
find sq length
Definition: points.h:73
ICOORD::y
int16_t y() const
access_function
Definition: points.h:56
ICOORD::ycoord
int16_t ycoord
y value
Definition: points.h:158
ICOORD
integer coordinate
Definition: points.h:32
FCOORD::x
float x() const
Definition: points.h:207
tesseract::Serialize
bool Serialize(FILE *fp, const char *data, size_t n)
Definition: serialis.cpp:77
FCOORD::y
float y() const
Definition: points.h:210
ICOORD::xcoord
int16_t xcoord
x value
Definition: points.h:157
tesseract::DeSerialize
bool DeSerialize(FILE *fp, char *data, size_t n)
Definition: serialis.cpp:45
ReverseN
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:185
ICOORD::pt_to_pt_sqdist
float pt_to_pt_sqdist(const ICOORD &pt) const
sq dist between pts
Definition: points.h:83
ICOORD::x
int16_t x() const
access function
Definition: points.h:52