tesseract  4.0.0-1-g2a2b
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
 
int16_t 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_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 32 of file points.h.

Constructor & Destructor Documentation

◆ ICOORD() [1/2]

ICOORD::ICOORD ( )
inline

empty constructor

Definition at line 38 of file points.h.

38  {
39  xcoord = ycoord = 0; //default zero
40  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ ICOORD() [2/2]

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

constructor

Parameters
xinx value
yiny value

Definition at line 44 of file points.h.

45  {
46  xcoord = xin;
47  ycoord = yin;
48  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ ~ICOORD()

ICOORD::~ICOORD ( )
default

destructor

Member Function Documentation

◆ angle()

float ICOORD::angle ( ) const
inline

find angle

Definition at line 98 of file points.h.

98  {
99  return (float) atan2 ((double) ycoord, (double) xcoord);
100  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ DeSerialize()

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

Definition at line 69 of file points.cpp.

69  {
70  if (!tesseract::DeSerialize(fp, &xcoord)) return false;
71  if (!tesseract::DeSerialize(fp, &ycoord)) return false;
72  if (swap) {
73  ReverseN(&xcoord, sizeof(xcoord));
74  ReverseN(&ycoord, sizeof(ycoord));
75  }
76  return true;
77 }
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:178
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159
bool DeSerialize(FILE *fp, char *data, size_t n)
Definition: serialis.cpp:27

◆ length()

float ICOORD::length ( ) const
inline

find length

Definition at line 79 of file points.h.

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

◆ operator!=()

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

test inequality

Definition at line 107 of file points.h.

107  {
108  return xcoord != other.xcoord || ycoord != other.ycoord;
109  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator==()

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

test equality

Definition at line 103 of file points.h.

103  {
104  return xcoord == other.xcoord && ycoord == other.ycoord;
105  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 93 of file points.h.

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

◆ pt_to_pt_sqdist()

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

sq dist between pts

Definition at line 84 of file points.h.

84  {
85  ICOORD gap;
86 
87  gap.xcoord = xcoord - pt.xcoord;
88  gap.ycoord = ycoord - pt.ycoord;
89  return gap.sqlength ();
90  }
integer coordinate
Definition: points.h:32
float sqlength() const
find sq length
Definition: points.h:74
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ rotate()

void ICOORD::rotate ( const FCOORD vec)
inline

rotate

Parameters
vecby vector

Definition at line 537 of file points.h.

538  {
539  int16_t tmp;
540 
541  tmp = (int16_t) floor (xcoord * vec.x () - ycoord * vec.y () + 0.5);
542  ycoord = (int16_t) floor (ycoord * vec.x () + xcoord * vec.y () + 0.5);
543  xcoord = tmp;
544 }
int16_t xcoord
Definition: points.h:158
float x() const
Definition: points.h:208
int16_t ycoord
Definition: points.h:159
float y() const
Definition: points.h:211

◆ Serialize()

bool ICOORD::Serialize ( FILE *  fp) const

Definition at line 63 of file points.cpp.

63  {
64  return tesseract::Serialize(fp, &xcoord) &&
66 }
bool Serialize(FILE *fp, const char *data, size_t n)
Definition: serialis.cpp:59
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ 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 = std::max(abs(x), abs(y));
47  if (max_extent > INT16_MAX)
48  factor = max_extent / INT16_MAX + 1;
49  xcoord = x / factor;
50  ycoord = y / factor;
51 }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ set_x()

void ICOORD::set_x ( int16_t  xin)
inline

rewrite function

Definition at line 62 of file points.h.

62  {
63  xcoord = xin; //write new value
64  }
int16_t xcoord
Definition: points.h:158

◆ set_y()

void ICOORD::set_y ( int16_t  yin)
inline

rewrite function

Definition at line 66 of file points.h.

66  { //value to set
67  ycoord = yin;
68  }
int16_t ycoord
Definition: points.h:159

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

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

◆ sqlength()

float ICOORD::sqlength ( ) const
inline

find sq length

Definition at line 74 of file points.h.

74  {
75  return (float) (xcoord * xcoord + ycoord * ycoord);
76  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ x()

int16_t ICOORD::x ( ) const
inline

access function

Definition at line 53 of file points.h.

53  {
54  return xcoord;
55  }
int16_t xcoord
Definition: points.h:158

◆ y()

int16_t ICOORD::y ( ) const
inline

access_function

Definition at line 57 of file points.h.

57  {
58  return ycoord;
59  }
int16_t ycoord
Definition: points.h:159

Friends And Related Function Documentation

◆ FCOORD

friend class FCOORD
friend

Definition at line 34 of file points.h.

◆ operator!

ICOORD operator! ( const ICOORD src)
friend

rotate 90 deg anti

Definition at line 328 of file points.h.

330  {
331  ICOORD result; //output
332 
333  result.xcoord = -src.ycoord;
334  result.ycoord = src.xcoord;
335  return result;
336 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator%

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

scalar product

Definition at line 432 of file points.h.

434  {
435  return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
436 }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator* [1/3]

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

cross product

Definition at line 445 of file points.h.

447  {
448  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
449 }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator* [2/3]

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

multiply

Definition at line 458 of file points.h.

460  {
461  ICOORD result; //output
462 
463  result.xcoord = op1.xcoord * scale;
464  result.ycoord = op1.ycoord * scale;
465  return result;
466 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator* [3/3]

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

multiply

Definition at line 469 of file points.h.

472  {
473  ICOORD result; //output
474 
475  result.xcoord = op1.xcoord * scale;
476  result.ycoord = op1.ycoord * scale;
477  return result;
478 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator*=

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

multiply

Definition at line 488 of file points.h.

490  {
491  op1.xcoord *= scale;
492  op1.ycoord *= scale;
493  return op1;
494 }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator+

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

add

Definition at line 364 of file points.h.

366  {
367  ICOORD sum; //result
368 
369  sum.xcoord = op1.xcoord + op2.xcoord;
370  sum.ycoord = op1.ycoord + op2.ycoord;
371  return sum;
372 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator+=

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

add

Definition at line 382 of file points.h.

384  {
385  op1.xcoord += op2.xcoord;
386  op1.ycoord += op2.ycoord;
387  return op1;
388 }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator- [1/2]

ICOORD operator- ( const ICOORD src)
friend

unary minus

Definition at line 346 of file points.h.

348  {
349  ICOORD result; //output
350 
351  result.xcoord = -src.xcoord;
352  result.ycoord = -src.ycoord;
353  return result;
354 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator- [2/2]

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

subtract

Definition at line 398 of file points.h.

400  {
401  ICOORD sum; //result
402 
403  sum.xcoord = op1.xcoord - op2.xcoord;
404  sum.ycoord = op1.ycoord - op2.ycoord;
405  return sum;
406 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator-=

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

subtract

Definition at line 416 of file points.h.

418  {
419  op1.xcoord -= op2.xcoord;
420  op1.ycoord -= op2.ycoord;
421  return op1;
422 }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator/

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

divide

Definition at line 504 of file points.h.

506  {
507  ICOORD result; //output
508 
509  result.xcoord = op1.xcoord / scale;
510  result.ycoord = op1.ycoord / scale;
511  return result;
512 }
integer coordinate
Definition: points.h:32
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

◆ operator/=

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

divide

Definition at line 522 of file points.h.

524  {
525  op1.xcoord /= scale;
526  op1.ycoord /= scale;
527  return op1;
528 }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

Member Data Documentation

◆ xcoord

int16_t ICOORD::xcoord
protected

Definition at line 158 of file points.h.

◆ ycoord

int16_t ICOORD::ycoord
protected

Definition at line 159 of file points.h.


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