tesseract v5.3.3.20231005
tesseract::ICOORD Class Reference

integer coordinate More...

#include <points.h>

Inheritance diagram for tesseract::ICOORD:
tesseract::ICOORDELT

Public Member Functions

 ICOORD ()
 empty constructor More...
 
 ICOORD (TDimension xin, TDimension yin)
 
 ~ICOORD ()=default
 destructor More...
 
bool DeSerialize (TFile *f)
 
bool Serialize (TFile *f) const
 
TDimension x () const
 access function More...
 
TDimension y () const
 access_function More...
 
void set_x (TDimension xin)
 rewrite function More...
 
void set_y (TDimension 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

TDimension xcoord
 x value More...
 
TDimension 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 &, TDimension)
 multiply More...
 
ICOORD operator* (TDimension, const ICOORD &)
 multiply More...
 
ICOORDoperator*= (ICOORD &, TDimension)
 multiply More...
 
ICOORD operator/ (const ICOORD &, TDimension)
 divide More...
 
ICOORDoperator/= (ICOORD &, TDimension)
 divide More...
 

Detailed Description

integer coordinate

Definition at line 36 of file points.h.

Constructor & Destructor Documentation

◆ ICOORD() [1/2]

tesseract::ICOORD::ICOORD ( )
inline

empty constructor

Definition at line 41 of file points.h.

41 {
42 xcoord = ycoord = 0; // default zero
43 }
TDimension ycoord
y value
Definition: points.h:160
TDimension xcoord
x value
Definition: points.h:159

◆ ICOORD() [2/2]

tesseract::ICOORD::ICOORD ( TDimension  xin,
TDimension  yin 
)
inline

constructor

Parameters
xinx value
yiny value

Definition at line 47 of file points.h.

47 {
48 xcoord = xin;
49 ycoord = yin;
50 }

◆ ~ICOORD()

tesseract::ICOORD::~ICOORD ( )
default

destructor

Member Function Documentation

◆ angle()

float tesseract::ICOORD::angle ( ) const
inline

find angle

Definition at line 103 of file points.h.

103 {
104 return (float)std::atan2(ycoord, xcoord);
105 }

◆ DeSerialize() [1/2]

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

Definition at line 79 of file points.cpp.

79 {
80 if (!tesseract::DeSerialize(fp, &xcoord)) {
81 return false;
82 }
83 if (!tesseract::DeSerialize(fp, &ycoord)) {
84 return false;
85 }
86 if (swap) {
87 ReverseN(&xcoord, sizeof(xcoord));
88 ReverseN(&ycoord, sizeof(ycoord));
89 }
90 return true;
91}
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:184
bool DeSerialize(bool swap, FILE *fp, std::vector< T > &data)
Definition: helpers.h:205

◆ DeSerialize() [2/2]

bool tesseract::ICOORD::DeSerialize ( TFile f)

Definition at line 43 of file points.cpp.

43 {
44 return f->DeSerialize(&xcoord) && f->DeSerialize(&ycoord);
45}

◆ length()

float tesseract::ICOORD::length ( ) const
inline

find length

Definition at line 84 of file points.h.

84 {
85 return std::sqrt(sqlength());
86 }
float sqlength() const
find sq length
Definition: points.h:79

◆ operator!=()

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

test inequality

Definition at line 112 of file points.h.

112 {
113 return xcoord != other.xcoord || ycoord != other.ycoord;
114 }

◆ operator==()

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

test equality

Definition at line 108 of file points.h.

108 {
109 return xcoord == other.xcoord && ycoord == other.ycoord;
110 }

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 98 of file points.h.

98 {
99 return std::sqrt(pt_to_pt_sqdist(pt));
100 }
float pt_to_pt_sqdist(const ICOORD &pt) const
sq dist between pts
Definition: points.h:89

◆ pt_to_pt_sqdist()

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

sq dist between pts

Definition at line 89 of file points.h.

89 {
90 ICOORD gap;
91
92 gap.xcoord = xcoord - pt.xcoord;
93 gap.ycoord = ycoord - pt.ycoord;
94 return gap.sqlength();
95 }
ICOORD()
empty constructor
Definition: points.h:41

◆ rotate()

void tesseract::ICOORD::rotate ( const FCOORD vec)
inline

rotate

Parameters
vecby vector

Definition at line 511 of file points.h.

512 {
513 auto tmp = static_cast<TDimension>(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f));
514 ycoord = static_cast<TDimension>(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f));
515 xcoord = tmp;
516}
int16_t TDimension
Definition: tesstypes.h:32

◆ Serialize() [1/2]

bool tesseract::ICOORD::Serialize ( FILE *  fp) const

Definition at line 74 of file points.cpp.

74 {
76}
bool Serialize(FILE *fp, const std::vector< T > &data)
Definition: helpers.h:236

◆ Serialize() [2/2]

bool tesseract::ICOORD::Serialize ( TFile f) const

Definition at line 47 of file points.cpp.

47 {
48 return f->Serialize(&xcoord) && f->Serialize(&ycoord);
49}

◆ set_with_shrink()

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

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

Definition at line 52 of file points.cpp.

52 {
53 // Fit the vector into an ICOORD, which is 16 bit.
54 int factor = 1;
55 int max_extent = std::max(abs(x), abs(y));
56 if (max_extent > INT16_MAX) {
57 factor = max_extent / INT16_MAX + 1;
58 }
59 xcoord = x / factor;
60 ycoord = y / factor;
61}
TDimension y() const
access_function
Definition: points.h:62
TDimension x() const
access function
Definition: points.h:58

◆ set_x()

void tesseract::ICOORD::set_x ( TDimension  xin)
inline

rewrite function

Definition at line 67 of file points.h.

67 {
68 xcoord = xin; // write new value
69 }

◆ set_y()

void tesseract::ICOORD::set_y ( TDimension  yin)
inline

rewrite function

Definition at line 71 of file points.h.

71 { // value to set
72 ycoord = yin;
73 }

◆ setup_render()

void tesseract::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 99 of file points.cpp.

99 {
100 int abs_x = abs(xcoord);
101 int abs_y = abs(ycoord);
102 if (abs_x >= abs_y) {
103 // X-direction is major.
104 major_step->xcoord = sign(xcoord);
105 major_step->ycoord = 0;
106 minor_step->xcoord = 0;
107 minor_step->ycoord = sign(ycoord);
108 *major = abs_x;
109 *minor = abs_y;
110 } else {
111 // Y-direction is major.
112 major_step->xcoord = 0;
113 major_step->ycoord = sign(ycoord);
114 minor_step->xcoord = sign(xcoord);
115 minor_step->ycoord = 0;
116 *major = abs_y;
117 *minor = abs_x;
118 }
119}

◆ sqlength()

float tesseract::ICOORD::sqlength ( ) const
inline

find sq length

Definition at line 79 of file points.h.

79 {
80 return (float)(xcoord * xcoord + ycoord * ycoord);
81 }

◆ x()

TDimension tesseract::ICOORD::x ( ) const
inline

access function

Definition at line 58 of file points.h.

58 {
59 return xcoord;
60 }

◆ y()

TDimension tesseract::ICOORD::y ( ) const
inline

access_function

Definition at line 62 of file points.h.

62 {
63 return ycoord;
64 }

Friends And Related Function Documentation

◆ FCOORD

friend class FCOORD
friend

Definition at line 37 of file points.h.

◆ operator!

ICOORD operator! ( const ICOORD src)
friend

rotate 90 deg anti

Definition at line 324 of file points.h.

326 {
327 ICOORD result; // output
328
329 result.xcoord = -src.ycoord;
330 result.ycoord = src.xcoord;
331 return result;
332}

◆ operator%

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

scalar product

Definition at line 416 of file points.h.

418 {
419 return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
420}

◆ operator* [1/3]

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

cross product

Definition at line 428 of file points.h.

430 {
431 return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
432}

◆ operator* [2/3]

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

multiply

Definition at line 440 of file points.h.

442 {
443 ICOORD result; // output
444
445 result.xcoord = op1.xcoord * scale;
446 result.ycoord = op1.ycoord * scale;
447 return result;
448}

◆ operator* [3/3]

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

multiply

Definition at line 450 of file points.h.

453 {
454 ICOORD result; // output
455
456 result.xcoord = op1.xcoord * scale;
457 result.ycoord = op1.ycoord * scale;
458 return result;
459}

◆ operator*=

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

multiply

Definition at line 467 of file points.h.

469 {
470 op1.xcoord *= scale;
471 op1.ycoord *= scale;
472 return op1;
473}

◆ operator+

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

add

Definition at line 356 of file points.h.

358 {
359 ICOORD sum; // result
360
361 sum.xcoord = op1.xcoord + op2.xcoord;
362 sum.ycoord = op1.ycoord + op2.ycoord;
363 return sum;
364}

◆ operator+=

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

add

Definition at line 372 of file points.h.

374 {
375 op1.xcoord += op2.xcoord;
376 op1.ycoord += op2.ycoord;
377 return op1;
378}

◆ operator- [1/2]

ICOORD operator- ( const ICOORD src)
friend

unary minus

Definition at line 340 of file points.h.

342 {
343 ICOORD result; // output
344
345 result.xcoord = -src.xcoord;
346 result.ycoord = -src.ycoord;
347 return result;
348}

◆ operator- [2/2]

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

subtract

Definition at line 386 of file points.h.

388 {
389 ICOORD sum; // result
390
391 sum.xcoord = op1.xcoord - op2.xcoord;
392 sum.ycoord = op1.ycoord - op2.ycoord;
393 return sum;
394}

◆ operator-=

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

subtract

Definition at line 402 of file points.h.

404 {
405 op1.xcoord -= op2.xcoord;
406 op1.ycoord -= op2.ycoord;
407 return op1;
408}

◆ operator/

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

divide

Definition at line 481 of file points.h.

483 {
484 ICOORD result; // output
485
486 result.xcoord = op1.xcoord / scale;
487 result.ycoord = op1.ycoord / scale;
488 return result;
489}

◆ operator/=

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

divide

Definition at line 497 of file points.h.

499 {
500 op1.xcoord /= scale;
501 op1.ycoord /= scale;
502 return op1;
503}

Member Data Documentation

◆ xcoord

TDimension tesseract::ICOORD::xcoord
protected

x value

Definition at line 159 of file points.h.

◆ ycoord

TDimension tesseract::ICOORD::ycoord
protected

y value

Definition at line 160 of file points.h.


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