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

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

◆ FCOORD() [3/3]

FCOORD::FCOORD ( ICOORD  icoord)
inline

Definition at line 200 of file points.h.

202  { //coords to set
203  xcoord = icoord.xcoord;
204  ycoord = icoord.ycoord;

Member Function Documentation

◆ angle()

float FCOORD::angle ( ) const
inline

find angle

Definition at line 246 of file points.h.

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

◆ angle_from_direction()

double FCOORD::angle_from_direction ( uint8_t  direction)
static

Definition at line 125 of file points.cpp.

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

◆ binary_angle_plus_pi()

uint8_t FCOORD::binary_angle_plus_pi ( double  angle)
static

Definition at line 120 of file points.cpp.

121  {
122  return Modulo(IntCastRounded((radians + M_PI) * 128.0 / M_PI), 256);

◆ from_direction()

void FCOORD::from_direction ( uint8_t  direction)

Definition at line 111 of file points.cpp.

112  {
113  double radians = angle_from_direction(direction);
114  xcoord = cos(radians);
115  ycoord = sin(radians);

◆ length()

float FCOORD::length ( ) const
inline

find length

Definition at line 227 of file points.h.

228  {
229  return std::sqrt(sqlength());

◆ nearest_pt_on_line()

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

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

◆ normalise()

bool FCOORD::normalise ( )

Convert to unit vec.

◆ operator!=()

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

test inequality

Definition at line 277 of file points.h.

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

◆ operator==()

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

test equality

Definition at line 273 of file points.h.

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

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 241 of file points.h.

242  {
243  return std::sqrt(pt_to_pt_sqdist(pt));

◆ pt_to_pt_sqdist()

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

sq dist between pts

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

◆ rotate()

void FCOORD::rotate ( const FCOORD  vec)
inline

rotate

Parameters
vecby vector

Definition at line 736 of file points.h.

749  {

◆ set_x()

void FCOORD::set_x ( float  xin)
inline

rewrite function

Definition at line 213 of file points.h.

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

◆ set_y()

void FCOORD::set_y ( float  yin)
inline

rewrite function

Definition at line 217 of file points.h.

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

◆ sqlength()

float FCOORD::sqlength ( ) const
inline

find sq length

Definition at line 222 of file points.h.

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

◆ to_direction()

uint8_t FCOORD::to_direction ( ) const

Definition at line 107 of file points.cpp.

108  {
109  return binary_angle_plus_pi(angle());

◆ unrotate()

void FCOORD::unrotate ( const FCOORD vec)
inline

Definition at line 745 of file points.h.

749  {

◆ x()

float FCOORD::x ( ) const
inline

Definition at line 206 of file points.h.

207  { //get coords
208  return xcoord;

◆ y()

float FCOORD::y ( ) const
inline

Definition at line 209 of file points.h.

210  {
211  return ycoord;

Friends And Related Function Documentation

◆ operator!

FCOORD operator! ( const FCOORD src)
friend

rotate 90 deg anti

Definition at line 538 of file points.h.

555  {

◆ operator%

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

scalar product

Definition at line 636 of file points.h.

643  {

◆ operator* [1/3]

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

cross product

Definition at line 648 of file points.h.

659  {

◆ operator* [2/3]

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

multiply

Definition at line 660 of file points.h.

672  {

◆ operator* [3/3]

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

multiply

Definition at line 671 of file points.h.

672  {
673  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
674 }
675 
676 
677 /**********************************************************************
678  * operator*
679  *
680  * Scalar multiply of an FCOORD.

◆ operator*=

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

multiply

Definition at line 689 of file points.h.

697  {

◆ operator+

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

add

Definition at line 572 of file points.h.

573  {
574  FCOORD result; //output
575 
576  result.xcoord = -src.xcoord;
577  result.ycoord = -src.ycoord;
578  return result;
579 }
580 

◆ operator+=

FCOORD& operator+= ( 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;

◆ operator- [1/2]

FCOORD operator- ( const FCOORD src)
friend

unary minus

Definition at line 555 of file points.h.

555  {
556  FCOORD result; //output
557 
558  result.xcoord = -src.ycoord;
559  result.ycoord = src.xcoord;
560  return result;
561 }
562 
563 

◆ operator- [2/2]

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

subtract

Definition at line 604 of file points.h.

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

◆ operator-=

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

subtract

Definition at line 621 of file points.h.

625  {
626  FCOORD sum; //result
627 

◆ operator/

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

divide

Definition at line 704 of file points.h.

715  {

◆ operator/=

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

divide

Definition at line 721 of file points.h.

731  {

The documentation for this class was generated from the following files:
FCOORD::angle
float angle() const
find angle
Definition: points.h:246
IntCastRounded
int IntCastRounded(double x)
Definition: helpers.h:173
FCOORD::angle_from_direction
static double angle_from_direction(uint8_t direction)
Definition: points.cpp:125
FCOORD
Definition: points.h:187
ICOORD::xcoord
int16_t xcoord
x value
Definition: points.h:156
ICOORD::ycoord
int16_t ycoord
y value
Definition: points.h:157
FCOORD::pt_to_pt_sqdist
float pt_to_pt_sqdist(const FCOORD &pt) const
sq dist between pts
Definition: points.h:232
FCOORD::binary_angle_plus_pi
static uint8_t binary_angle_plus_pi(double angle)
Definition: points.cpp:120
Modulo
int Modulo(int a, int b)
Definition: helpers.h:156
FCOORD::sqlength
float sqlength() const
find sq length
Definition: points.h:222