tesseract  4.1.1
FCOORD Class Reference

#include <points.h>

Public Member Functions

 FCOORD ()=default
 empty constructor More...
 
 FCOORD (float xvalue, float yvalue)
 
 FCOORD (ICOORD icoord)
 
float x () const
 
float y () const
 
void set_x (float xin)
 rewrite function More...
 
void set_y (float yin)
 rewrite function More...
 
float sqlength () const
 find sq length More...
 
float length () const
 find length More...
 
float pt_to_pt_sqdist (const FCOORD &pt) const
 sq dist between pts More...
 
float pt_to_pt_dist (const FCOORD &pt) const
 Distance between pts. More...
 
float angle () const
 find angle More...
 
uint8_t to_direction () const
 
void from_direction (uint8_t direction)
 
FCOORD nearest_pt_on_line (const FCOORD &line_point, const FCOORD &dir_vector) const
 
bool normalise ()
 Convert to unit vec. More...
 
bool operator== (const FCOORD &other)
 test equality More...
 
bool operator!= (const FCOORD &other)
 test inequality More...
 
void rotate (const FCOORD vec)
 
void unrotate (const FCOORD &vec)
 

Static Public Member Functions

static uint8_t binary_angle_plus_pi (double angle)
 
static double angle_from_direction (uint8_t direction)
 

Friends

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

Detailed Description

Definition at line 188 of file points.h.

Constructor & Destructor Documentation

◆ FCOORD() [1/3]

FCOORD::FCOORD ( )
default

empty constructor

◆ FCOORD() [2/3]

FCOORD::FCOORD ( float  xvalue,
float  yvalue 
)
inline

constructor

Parameters
xvaluex value
yvaluey value

Definition at line 196 of file points.h.

197  {
198  xcoord = xvalue; //set coords
199  ycoord = yvalue;
200  }

◆ FCOORD() [3/3]

FCOORD::FCOORD ( ICOORD  icoord)
inline

Definition at line 201 of file points.h.

202  { //coords to set
203  xcoord = icoord.xcoord;
204  ycoord = icoord.ycoord;
205  }
int16_t xcoord
x value
Definition: points.h:157
int16_t ycoord
y value
Definition: points.h:158

Member Function Documentation

◆ angle()

float FCOORD::angle ( ) const
inline

find angle

Definition at line 247 of file points.h.

247  {
248  return std::atan2(ycoord, xcoord);
249  }

◆ angle_from_direction()

double FCOORD::angle_from_direction ( uint8_t  direction)
static

Definition at line 126 of file points.cpp.

126  {
127  return direction * M_PI / 128.0 - M_PI;
128 }

◆ binary_angle_plus_pi()

uint8_t FCOORD::binary_angle_plus_pi ( double  angle)
static

Definition at line 121 of file points.cpp.

121  {
122  return Modulo(IntCastRounded((radians + M_PI) * 128.0 / M_PI), 256);
123 }
int Modulo(int a, int b)
Definition: helpers.h:158
int IntCastRounded(double x)
Definition: helpers.h:175

◆ from_direction()

void FCOORD::from_direction ( uint8_t  direction)

Definition at line 112 of file points.cpp.

112  {
113  double radians = angle_from_direction(direction);
114  xcoord = cos(radians);
115  ycoord = sin(radians);
116 }
static double angle_from_direction(uint8_t direction)
Definition: points.cpp:126

◆ length()

float FCOORD::length ( ) const
inline

find length

Definition at line 228 of file points.h.

228  {
229  return std::sqrt(sqlength());
230  }
float sqlength() const
find sq length
Definition: points.h:223

◆ nearest_pt_on_line()

FCOORD FCOORD::nearest_pt_on_line ( const FCOORD line_point,
const FCOORD dir_vector 
) const

Definition at line 133 of file points.cpp.

134  {
135  FCOORD point_vector(*this - line_point);
136  // The dot product (%) is |dir_vector||point_vector|cos theta, so dividing by
137  // the square of the length of dir_vector gives us the fraction of dir_vector
138  // to add to line1 to get the appropriate point, so
139  // result = line1 + lambda dir_vector.
140  double lambda = point_vector % dir_vector / dir_vector.sqlength();
141  return line_point + (dir_vector * lambda);
142 }
Definition: points.h:188
float sqlength() const
find sq length
Definition: points.h:223

◆ normalise()

bool FCOORD::normalise ( )

Convert to unit vec.

◆ operator!=()

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

test inequality

Definition at line 278 of file points.h.

278  {
279  return xcoord != other.xcoord || ycoord != other.ycoord;
280  }

◆ operator==()

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

test equality

Definition at line 274 of file points.h.

274  {
275  return xcoord == other.xcoord && ycoord == other.ycoord;
276  }

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 242 of file points.h.

242  {
243  return std::sqrt(pt_to_pt_sqdist(pt));
244  }
float pt_to_pt_sqdist(const FCOORD &pt) const
sq dist between pts
Definition: points.h:233

◆ pt_to_pt_sqdist()

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

sq dist between pts

Definition at line 233 of file points.h.

233  {
234  FCOORD gap;
235 
236  gap.xcoord = xcoord - pt.xcoord;
237  gap.ycoord = ycoord - pt.ycoord;
238  return gap.sqlength ();
239  }
Definition: points.h:188
float sqlength() const
find sq length
Definition: points.h:223

◆ rotate()

void FCOORD::rotate ( const FCOORD  vec)
inline

rotate

Parameters
vecby vector

Definition at line 763 of file points.h.

764  {
765  float tmp;
766 
767  tmp = xcoord * vec.x () - ycoord * vec.y ();
768  ycoord = ycoord * vec.x () + xcoord * vec.y ();
769  xcoord = tmp;
770 }
float y() const
Definition: points.h:210
float x() const
Definition: points.h:207

◆ set_x()

void FCOORD::set_x ( float  xin)
inline

rewrite function

Definition at line 214 of file points.h.

214  {
215  xcoord = xin; //write new value
216  }

◆ set_y()

void FCOORD::set_y ( float  yin)
inline

rewrite function

Definition at line 218 of file points.h.

218  { //value to set
219  ycoord = yin;
220  }

◆ sqlength()

float FCOORD::sqlength ( ) const
inline

find sq length

Definition at line 223 of file points.h.

223  {
224  return xcoord * xcoord + ycoord * ycoord;
225  }

◆ to_direction()

uint8_t FCOORD::to_direction ( ) const

Definition at line 108 of file points.cpp.

108  {
109  return binary_angle_plus_pi(angle());
110 }
static uint8_t binary_angle_plus_pi(double angle)
Definition: points.cpp:121
float angle() const
find angle
Definition: points.h:247

◆ unrotate()

void FCOORD::unrotate ( const FCOORD vec)
inline

Definition at line 772 of file points.h.

772  {
773  rotate(FCOORD(vec.x(), -vec.y()));
774 }
float y() const
Definition: points.h:210
float x() const
Definition: points.h:207
void rotate(const FCOORD vec)
Definition: points.h:763
FCOORD()=default
empty constructor

◆ x()

float FCOORD::x ( ) const
inline

Definition at line 207 of file points.h.

207  { //get coords
208  return xcoord;
209  }

◆ y()

float FCOORD::y ( ) const
inline

Definition at line 210 of file points.h.

210  {
211  return ycoord;
212  }

Friends And Related Function Documentation

◆ operator!

FCOORD operator! ( const FCOORD src)
friend

rotate 90 deg anti

Definition at line 553 of file points.h.

555  {
556  FCOORD result; //output
557 
558  result.xcoord = -src.ycoord;
559  result.ycoord = src.xcoord;
560  return result;
561 }
Definition: points.h:188

◆ operator%

float operator% ( const FCOORD op1,
const FCOORD op2 
)
friend

scalar product

Definition at line 657 of file points.h.

659  {
660  return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
661 }

◆ operator* [1/3]

float operator* ( const FCOORD op1,
const FCOORD op2 
)
friend

cross product

Definition at line 670 of file points.h.

672  {
673  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
674 }

◆ operator* [2/3]

FCOORD operator* ( const FCOORD op1,
float  scale 
)
friend

multiply

Definition at line 683 of file points.h.

685  {
686  FCOORD result; //output
687 
688  result.xcoord = op1.xcoord * scale;
689  result.ycoord = op1.ycoord * scale;
690  return result;
691 }
Definition: points.h:188

◆ operator* [3/3]

FCOORD operator* ( float  scale,
const FCOORD op1 
)
friend

multiply

Definition at line 694 of file points.h.

697  {
698  FCOORD result; //output
699 
700  result.xcoord = op1.xcoord * scale;
701  result.ycoord = op1.ycoord * scale;
702  return result;
703 }
Definition: points.h:188

◆ operator*=

FCOORD& operator*= ( FCOORD op1,
float  scale 
)
friend

multiply

Definition at line 713 of file points.h.

715  {
716  op1.xcoord *= scale;
717  op1.ycoord *= scale;
718  return op1;
719 }

◆ operator+

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

add

Definition at line 589 of file points.h.

591  {
592  FCOORD sum; //result
593 
594  sum.xcoord = op1.xcoord + op2.xcoord;
595  sum.ycoord = op1.ycoord + op2.ycoord;
596  return sum;
597 }
Definition: points.h:188

◆ operator+=

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

add

Definition at line 607 of file points.h.

609  {
610  op1.xcoord += op2.xcoord;
611  op1.ycoord += op2.ycoord;
612  return op1;
613 }

◆ operator- [1/2]

FCOORD operator- ( const FCOORD src)
friend

unary minus

Definition at line 571 of file points.h.

573  {
574  FCOORD result; //output
575 
576  result.xcoord = -src.xcoord;
577  result.ycoord = -src.ycoord;
578  return result;
579 }
Definition: points.h:188

◆ operator- [2/2]

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

subtract

Definition at line 623 of file points.h.

625  {
626  FCOORD sum; //result
627 
628  sum.xcoord = op1.xcoord - op2.xcoord;
629  sum.ycoord = op1.ycoord - op2.ycoord;
630  return sum;
631 }
Definition: points.h:188

◆ operator-=

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

subtract

Definition at line 641 of file points.h.

643  {
644  op1.xcoord -= op2.xcoord;
645  op1.ycoord -= op2.ycoord;
646  return op1;
647 }

◆ operator/

FCOORD operator/ ( const FCOORD op1,
float  scale 
)
friend

divide

Definition at line 729 of file points.h.

731  {
732  FCOORD result; //output
733  ASSERT_HOST(scale != 0.0f);
734  result.xcoord = op1.xcoord / scale;
735  result.ycoord = op1.ycoord / scale;
736  return result;
737 }
Definition: points.h:188
#define ASSERT_HOST(x)
Definition: errcode.h:88

◆ operator/=

FCOORD& operator/= ( FCOORD op1,
float  scale 
)
friend

divide

Definition at line 747 of file points.h.

749  {
750  ASSERT_HOST(scale != 0.0f);
751  op1.xcoord /= scale;
752  op1.ycoord /= scale;
753  return op1;
754 }
#define ASSERT_HOST(x)
Definition: errcode.h:88

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