tesseract  5.0.0-alpha-619-ge9db
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 30 of file points.h.

Constructor & Destructor Documentation

◆ ICOORD() [1/2]

ICOORD::ICOORD ( )
inline

empty constructor

Definition at line 36 of file points.h.

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

◆ ICOORD() [2/2]

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

constructor

Parameters
xinx value
yiny value

Definition at line 42 of file points.h.

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

◆ ~ICOORD()

ICOORD::~ICOORD ( )
default

destructor

Member Function Documentation

◆ angle()

float ICOORD::angle ( ) const
inline

find angle

Definition at line 96 of file points.h.

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

◆ DeSerialize()

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

Definition at line 66 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;

◆ length()

float ICOORD::length ( ) const
inline

find length

Definition at line 77 of file points.h.

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

◆ operator!=()

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

test inequality

Definition at line 105 of file points.h.

106  {
107  return xcoord != other.xcoord || ycoord != other.ycoord;

◆ operator==()

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

test equality

Definition at line 101 of file points.h.

102  {
103  return xcoord == other.xcoord && ycoord == other.ycoord;

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 91 of file points.h.

92  {
93  return std::sqrt(pt_to_pt_sqdist(pt));

◆ pt_to_pt_sqdist()

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

sq dist between pts

Definition at line 82 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 ();

◆ rotate()

void ICOORD::rotate ( const FCOORD vec)
inline

rotate

Parameters
vecby vector

Definition at line 522 of file points.h.

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

◆ Serialize()

bool ICOORD::Serialize ( FILE *  fp) const

Definition at line 60 of file points.cpp.

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

◆ 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 40 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;

◆ set_x()

void ICOORD::set_x ( int16_t  xin)
inline

rewrite function

Definition at line 60 of file points.h.

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

◆ set_y()

void ICOORD::set_y ( int16_t  yin)
inline

rewrite function

Definition at line 64 of file points.h.

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

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

◆ sqlength()

float ICOORD::sqlength ( ) const
inline

find sq length

Definition at line 72 of file points.h.

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

◆ x()

int16_t ICOORD::x ( ) const
inline

access function

Definition at line 51 of file points.h.

52  {
53  return xcoord;

◆ y()

int16_t ICOORD::y ( ) const
inline

access_function

Definition at line 55 of file points.h.

56  {
57  return ycoord;

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 325 of file points.h.

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

◆ operator%

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

scalar product

Definition at line 423 of file points.h.

433  {

◆ operator* [1/3]

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

cross product

Definition at line 435 of file points.h.

446  {

◆ operator* [2/3]

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

multiply

Definition at line 447 of file points.h.

459  {

◆ operator* [3/3]

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

multiply

Definition at line 458 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 }
466 
467 

◆ operator*=

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

multiply

Definition at line 476 of file points.h.

489  {

◆ operator+

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

add

Definition at line 359 of file points.h.

365  {
366  ICOORD sum; //result
367 

◆ operator+=

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

add

Definition at line 376 of file points.h.

383  {

◆ operator- [1/2]

ICOORD operator- ( const ICOORD src)
friend

unary minus

Definition at line 342 of file points.h.

347  {
348  ICOORD result; //output
349 
350  result.xcoord = -src.xcoord;

◆ operator- [2/2]

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

subtract

Definition at line 391 of file points.h.

399  {

◆ operator-=

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

subtract

Definition at line 408 of file points.h.

417  {

◆ operator/

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

divide

Definition at line 491 of file points.h.

505  {

◆ operator/=

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

divide

Definition at line 508 of file points.h.

523  {

Member Data Documentation

◆ xcoord

int16_t ICOORD::xcoord
protected

x value

Definition at line 156 of file points.h.

◆ ycoord

int16_t ICOORD::ycoord
protected

y value

Definition at line 157 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:72
ICOORD
integer coordinate
Definition: points.h:30
ICOORD::x
int16_t x() const
access function
Definition: points.h:51
ICOORD::pt_to_pt_sqdist
float pt_to_pt_sqdist(const ICOORD &pt) const
sq dist between pts
Definition: points.h:82
ICOORD::xcoord
int16_t xcoord
x value
Definition: points.h:156
ICOORD::ycoord
int16_t ycoord
y value
Definition: points.h:157
ReverseN
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:183
tesseract::DeSerialize
bool DeSerialize(FILE *fp, char *data, size_t n=1)
Definition: serialis.cpp:41
tesseract::Serialize
bool Serialize(FILE *fp, const char *data, size_t n=1)
Definition: serialis.cpp:73
ICOORD::y
int16_t y() const
access_function
Definition: points.h:55