tesseract  5.0.0
tesseract::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]

tesseract::FCOORD::FCOORD ( )
default

empty constructor

◆ FCOORD() [2/3]

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

constructor

Parameters
xvaluex value
yvaluey value

Definition at line 196 of file points.h.

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

◆ FCOORD() [3/3]

tesseract::FCOORD::FCOORD ( ICOORD  icoord)
inline

Definition at line 200 of file points.h.

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

Member Function Documentation

◆ angle()

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

find angle

Definition at line 246 of file points.h.

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

◆ angle_from_direction()

double tesseract::FCOORD::angle_from_direction ( uint8_t  direction)
static

Definition at line 141 of file points.cpp.

141  {
142  return direction * M_PI / 128.0 - M_PI;
143 }

◆ binary_angle_plus_pi()

uint8_t tesseract::FCOORD::binary_angle_plus_pi ( double  angle)
static

Definition at line 136 of file points.cpp.

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

◆ from_direction()

void tesseract::FCOORD::from_direction ( uint8_t  direction)

Definition at line 127 of file points.cpp.

127  {
128  double radians = angle_from_direction(direction);
129  xcoord = cos(radians);
130  ycoord = sin(radians);
131 }
static double angle_from_direction(uint8_t direction)
Definition: points.cpp:141

◆ length()

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

find length

Definition at line 227 of file points.h.

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

◆ nearest_pt_on_line()

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

Definition at line 148 of file points.cpp.

148  {
149  FCOORD point_vector(*this - line_point);
150  // The dot product (%) is |dir_vector||point_vector|cos theta, so dividing by
151  // the square of the length of dir_vector gives us the fraction of dir_vector
152  // to add to line1 to get the appropriate point, so
153  // result = line1 + lambda dir_vector.
154  double lambda = point_vector % dir_vector / dir_vector.sqlength();
155  return line_point + (dir_vector * lambda);
156 }
FCOORD()=default
empty constructor

◆ normalise()

bool tesseract::FCOORD::normalise ( )

Convert to unit vec.

Definition at line 32 of file points.cpp.

32  { // Convert to unit vec
33  float len = length();
34 
35  if (len < 0.0000000001) {
36  return false;
37  }
38  xcoord /= len;
39  ycoord /= len;
40  return true;
41 }
float length() const
find length
Definition: points.h:227

◆ operator!=()

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

test inequality

Definition at line 276 of file points.h.

276  {
277  return xcoord != other.xcoord || ycoord != other.ycoord;
278  }

◆ operator==()

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

test equality

Definition at line 272 of file points.h.

272  {
273  return xcoord == other.xcoord && ycoord == other.ycoord;
274  }

◆ pt_to_pt_dist()

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

Distance between pts.

Definition at line 241 of file points.h.

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

◆ pt_to_pt_sqdist()

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

sq dist between pts

Definition at line 232 of file points.h.

232  {
233  FCOORD gap;
234 
235  gap.xcoord = xcoord - pt.xcoord;
236  gap.ycoord = ycoord - pt.ycoord;
237  return gap.sqlength();
238  }

◆ rotate()

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

rotate

Parameters
vecby vector

Definition at line 712 of file points.h.

713  {
714  float tmp;
715 
716  tmp = xcoord * vec.x() - ycoord * vec.y();
717  ycoord = ycoord * vec.x() + xcoord * vec.y();
718  xcoord = tmp;
719 }

◆ set_x()

void tesseract::FCOORD::set_x ( float  xin)
inline

rewrite function

Definition at line 213 of file points.h.

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

◆ set_y()

void tesseract::FCOORD::set_y ( float  yin)
inline

rewrite function

Definition at line 217 of file points.h.

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

◆ sqlength()

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

find sq length

Definition at line 222 of file points.h.

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

◆ to_direction()

uint8_t tesseract::FCOORD::to_direction ( ) const

Definition at line 123 of file points.cpp.

123  {
124  return binary_angle_plus_pi(angle());
125 }
float angle() const
find angle
Definition: points.h:246
static uint8_t binary_angle_plus_pi(double angle)
Definition: points.cpp:136

◆ unrotate()

void tesseract::FCOORD::unrotate ( const FCOORD vec)
inline

Definition at line 721 of file points.h.

721  {
722  rotate(FCOORD(vec.x(), -vec.y()));
723 }
void rotate(const FCOORD vec)
Definition: points.h:712

◆ x()

float tesseract::FCOORD::x ( ) const
inline

Definition at line 206 of file points.h.

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

◆ y()

float tesseract::FCOORD::y ( ) const
inline

Definition at line 209 of file points.h.

209  {
210  return ycoord;
211  }

Friends And Related Function Documentation

◆ operator!

FCOORD operator! ( const FCOORD src)
friend

rotate 90 deg anti

Definition at line 524 of file points.h.

526  {
527  FCOORD result; // output
528 
529  result.xcoord = -src.ycoord;
530  result.ycoord = src.xcoord;
531  return result;
532 }

◆ operator%

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

scalar product

Definition at line 616 of file points.h.

618  {
619  return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
620 }

◆ operator* [1/3]

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

cross product

Definition at line 628 of file points.h.

630  {
631  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
632 }

◆ operator* [2/3]

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

multiply

Definition at line 640 of file points.h.

642  {
643  FCOORD result; // output
644 
645  result.xcoord = op1.xcoord * scale;
646  result.ycoord = op1.ycoord * scale;
647  return result;
648 }

◆ operator* [3/3]

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

multiply

Definition at line 650 of file points.h.

653  {
654  FCOORD result; // output
655 
656  result.xcoord = op1.xcoord * scale;
657  result.ycoord = op1.ycoord * scale;
658  return result;
659 }

◆ operator*=

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

multiply

Definition at line 667 of file points.h.

669  {
670  op1.xcoord *= scale;
671  op1.ycoord *= scale;
672  return op1;
673 }

◆ operator+

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

add

Definition at line 556 of file points.h.

558  {
559  FCOORD sum; // result
560 
561  sum.xcoord = op1.xcoord + op2.xcoord;
562  sum.ycoord = op1.ycoord + op2.ycoord;
563  return sum;
564 }

◆ operator+=

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

add

Definition at line 572 of file points.h.

574  {
575  op1.xcoord += op2.xcoord;
576  op1.ycoord += op2.ycoord;
577  return op1;
578 }

◆ operator- [1/2]

FCOORD operator- ( const FCOORD src)
friend

unary minus

Definition at line 540 of file points.h.

542  {
543  FCOORD result; // output
544 
545  result.xcoord = -src.xcoord;
546  result.ycoord = -src.ycoord;
547  return result;
548 }

◆ operator- [2/2]

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

subtract

Definition at line 586 of file points.h.

588  {
589  FCOORD sum; // result
590 
591  sum.xcoord = op1.xcoord - op2.xcoord;
592  sum.ycoord = op1.ycoord - op2.ycoord;
593  return sum;
594 }

◆ operator-=

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

subtract

Definition at line 602 of file points.h.

604  {
605  op1.xcoord -= op2.xcoord;
606  op1.ycoord -= op2.ycoord;
607  return op1;
608 }

◆ operator/

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

divide

Definition at line 681 of file points.h.

683  {
684  FCOORD result; // output
685  ASSERT_HOST(scale != 0.0f);
686  result.xcoord = op1.xcoord / scale;
687  result.ycoord = op1.ycoord / scale;
688  return result;
689 }
#define ASSERT_HOST(x)
Definition: errcode.h:59

◆ operator/=

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

divide

Definition at line 697 of file points.h.

699  {
700  ASSERT_HOST(scale != 0.0f);
701  op1.xcoord /= scale;
702  op1.ycoord /= scale;
703  return op1;
704 }

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