tesseract  4.0.0-1-g2a2b
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 189 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 197 of file points.h.

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

◆ FCOORD() [3/3]

FCOORD::FCOORD ( ICOORD  icoord)
inline

Definition at line 202 of file points.h.

203  { //coords to set
204  xcoord = icoord.xcoord;
205  ycoord = icoord.ycoord;
206  }
int16_t xcoord
Definition: points.h:158
int16_t ycoord
Definition: points.h:159

Member Function Documentation

◆ angle()

float FCOORD::angle ( ) const
inline

find angle

Definition at line 248 of file points.h.

248  {
249  return (float) atan2 (ycoord, xcoord);
250  }

◆ angle_from_direction()

double FCOORD::angle_from_direction ( uint8_t  direction)
static

Definition at line 128 of file points.cpp.

128  {
129  return direction * M_PI / 128.0 - M_PI;
130 }
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43

◆ binary_angle_plus_pi()

uint8_t FCOORD::binary_angle_plus_pi ( double  angle)
static

Definition at line 123 of file points.cpp.

123  {
124  return Modulo(IntCastRounded((radians + M_PI) * 128.0 / M_PI), 256);
125 }
int Modulo(int a, int b)
Definition: helpers.h:153
int IntCastRounded(double x)
Definition: helpers.h:168

◆ from_direction()

void FCOORD::from_direction ( uint8_t  direction)

Definition at line 114 of file points.cpp.

114  {
115  double radians = angle_from_direction(direction);
116  xcoord = cos(radians);
117  ycoord = sin(radians);
118 }
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43
static double angle_from_direction(uint8_t direction)
Definition: points.cpp:128

◆ length()

float FCOORD::length ( ) const
inline

find length

Definition at line 229 of file points.h.

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

◆ nearest_pt_on_line()

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

Definition at line 135 of file points.cpp.

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

◆ normalise()

bool FCOORD::normalise ( )

Convert to unit vec.

◆ operator!=()

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

test inequality

Definition at line 279 of file points.h.

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

◆ operator==()

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

test equality

Definition at line 275 of file points.h.

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

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 243 of file points.h.

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

◆ pt_to_pt_sqdist()

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

sq dist between pts

Definition at line 234 of file points.h.

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

◆ rotate()

void FCOORD::rotate ( const FCOORD  vec)
inline

rotate

Parameters
vecby vector

Definition at line 764 of file points.h.

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

◆ set_x()

void FCOORD::set_x ( float  xin)
inline

rewrite function

Definition at line 215 of file points.h.

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

◆ set_y()

void FCOORD::set_y ( float  yin)
inline

rewrite function

Definition at line 219 of file points.h.

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

◆ sqlength()

float FCOORD::sqlength ( ) const
inline

find sq length

Definition at line 224 of file points.h.

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

◆ to_direction()

uint8_t FCOORD::to_direction ( ) const

Definition at line 110 of file points.cpp.

110  {
111  return binary_angle_plus_pi(angle());
112 }
float angle() const
find angle
Definition: points.h:248
static uint8_t binary_angle_plus_pi(double angle)
Definition: points.cpp:123

◆ unrotate()

void FCOORD::unrotate ( const FCOORD vec)
inline

Definition at line 773 of file points.h.

773  {
774  rotate(FCOORD(vec.x(), -vec.y()));
775 }
void rotate(const FCOORD vec)
Definition: points.h:764
FCOORD()=default
empty constructor
float x() const
Definition: points.h:208
float y() const
Definition: points.h:211

◆ x()

float FCOORD::x ( ) const
inline

Definition at line 208 of file points.h.

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

◆ y()

float FCOORD::y ( ) const
inline

Definition at line 211 of file points.h.

211  {
212  return ycoord;
213  }

Friends And Related Function Documentation

◆ operator!

FCOORD operator! ( const FCOORD src)
friend

rotate 90 deg anti

Definition at line 554 of file points.h.

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

◆ operator%

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

scalar product

Definition at line 658 of file points.h.

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

◆ operator* [1/3]

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

cross product

Definition at line 671 of file points.h.

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

◆ operator* [2/3]

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

multiply

Definition at line 684 of file points.h.

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

◆ operator* [3/3]

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

multiply

Definition at line 695 of file points.h.

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

◆ operator*=

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

multiply

Definition at line 714 of file points.h.

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

◆ operator+

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

add

Definition at line 590 of file points.h.

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

◆ operator+=

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

add

Definition at line 608 of file points.h.

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

◆ operator- [1/2]

FCOORD operator- ( const FCOORD src)
friend

unary minus

Definition at line 572 of file points.h.

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

◆ operator- [2/2]

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

subtract

Definition at line 624 of file points.h.

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

◆ operator-=

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

subtract

Definition at line 642 of file points.h.

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

◆ operator/

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

divide

Definition at line 730 of file points.h.

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

◆ operator/=

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

divide

Definition at line 748 of file points.h.

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

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