All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FCOORD Class Reference

#include <points.h>

Public Member Functions

 FCOORD ()
 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 to_direction () const
 
void from_direction (uinT8 direction)
 
FCOORD nearest_pt_on_line (const FCOORD &line_point, const FCOORD &dir_vector) const
 
bool normalise ()
 Convert to unit vec. More...
 
BOOL8 operator== (const FCOORD &other)
 test equality More...
 
BOOL8 operator!= (const FCOORD &other)
 test inequality More...
 
void rotate (const FCOORD vec)
 
void unrotate (const FCOORD &vec)
 

Static Public Member Functions

static uinT8 binary_angle_plus_pi (double angle)
 
static double angle_from_direction (uinT8 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::FCOORD ( )
inline

empty constructor

Definition at line 193 of file points.h.

193  {
194  }
FCOORD::FCOORD ( float  xvalue,
float  yvalue 
)
inline

constructor

Parameters
xvaluex value
yvaluey value

Definition at line 198 of file points.h.

199  {
200  xcoord = xvalue; //set coords
201  ycoord = yvalue;
202  }
FCOORD::FCOORD ( ICOORD  icoord)
inline

Definition at line 203 of file points.h.

204  { //coords to set
205  xcoord = icoord.xcoord;
206  ycoord = icoord.ycoord;
207  }
inT16 ycoord
Definition: points.h:158
inT16 xcoord
Definition: points.h:157

Member Function Documentation

float FCOORD::angle ( ) const
inline

find angle

Definition at line 249 of file points.h.

249  {
250  return (float) atan2 (ycoord, xcoord);
251  }
double FCOORD::angle_from_direction ( uinT8  direction)
static

Definition at line 129 of file points.cpp.

129  {
130  return direction * M_PI / 128.0 - M_PI;
131 }
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43
uinT8 FCOORD::binary_angle_plus_pi ( double  angle)
static

Definition at line 124 of file points.cpp.

124  {
125  return Modulo(IntCastRounded((radians + M_PI) * 128.0 / M_PI), 256);
126 }
int Modulo(int a, int b)
Definition: helpers.h:157
int IntCastRounded(double x)
Definition: helpers.h:172
void FCOORD::from_direction ( uinT8  direction)

Definition at line 115 of file points.cpp.

115  {
116  double radians = angle_from_direction(direction);
117  xcoord = cos(radians);
118  ycoord = sin(radians);
119 }
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43
static double angle_from_direction(uinT8 direction)
Definition: points.cpp:129
float FCOORD::length ( ) const
inline

find length

Definition at line 230 of file points.h.

230  {
231  return (float) sqrt (sqlength ());
232  }
float sqlength() const
find sq length
Definition: points.h:225
FCOORD FCOORD::nearest_pt_on_line ( const FCOORD line_point,
const FCOORD dir_vector 
) const

Definition at line 136 of file points.cpp.

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

Convert to unit vec.

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

test inequality

Definition at line 280 of file points.h.

280  {
281  return xcoord != other.xcoord || ycoord != other.ycoord;
282  }
BOOL8 FCOORD::operator== ( const FCOORD other)
inline

test equality

Definition at line 276 of file points.h.

276  {
277  return xcoord == other.xcoord && ycoord == other.ycoord;
278  }
float FCOORD::pt_to_pt_dist ( const FCOORD pt) const
inline

Distance between pts.

Definition at line 244 of file points.h.

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

sq dist between pts

Definition at line 235 of file points.h.

235  {
236  FCOORD gap;
237 
238  gap.xcoord = xcoord - pt.xcoord;
239  gap.ycoord = ycoord - pt.ycoord;
240  return gap.sqlength ();
241  }
float sqlength() const
find sq length
Definition: points.h:225
Definition: points.h:189
void FCOORD::rotate ( const FCOORD  vec)
inline

rotate

Parameters
vecby vector

Definition at line 471 of file ipoints.h.

472  {
473  float tmp;
474 
475  tmp = xcoord * vec.x () - ycoord * vec.y ();
476  ycoord = ycoord * vec.x () + xcoord * vec.y ();
477  xcoord = tmp;
478 }
float x() const
Definition: points.h:209
float y() const
Definition: points.h:212
void FCOORD::set_x ( float  xin)
inline

rewrite function

Definition at line 216 of file points.h.

216  {
217  xcoord = xin; //write new value
218  }
void FCOORD::set_y ( float  yin)
inline

rewrite function

Definition at line 220 of file points.h.

220  { //value to set
221  ycoord = yin;
222  }
float FCOORD::sqlength ( ) const
inline

find sq length

Definition at line 225 of file points.h.

225  {
226  return xcoord * xcoord + ycoord * ycoord;
227  }
uinT8 FCOORD::to_direction ( ) const

Definition at line 111 of file points.cpp.

111  {
112  return binary_angle_plus_pi(angle());
113 }
float angle() const
find angle
Definition: points.h:249
static uinT8 binary_angle_plus_pi(double angle)
Definition: points.cpp:124
void FCOORD::unrotate ( const FCOORD vec)
inline

Definition at line 480 of file ipoints.h.

480  {
481  rotate(FCOORD(vec.x(), -vec.y()));
482 }
float x() const
Definition: points.h:209
void rotate(const FCOORD vec)
Definition: ipoints.h:471
FCOORD()
empty constructor
Definition: points.h:193
float y() const
Definition: points.h:212
float FCOORD::x ( ) const
inline

Definition at line 209 of file points.h.

209  { //get coords
210  return xcoord;
211  }
float FCOORD::y ( ) const
inline

Definition at line 212 of file points.h.

212  {
213  return ycoord;
214  }

Friends And Related Function Documentation

FCOORD operator! ( const FCOORD src)
friend

rotate 90 deg anti

Definition at line 258 of file ipoints.h.

260  {
261  FCOORD result; //output
262 
263  result.xcoord = -src.ycoord;
264  result.ycoord = src.xcoord;
265  return result;
266 }
Definition: points.h:189
float operator% ( const FCOORD op1,
const FCOORD op2 
)
friend

scalar product

Definition at line 362 of file ipoints.h.

364  {
365  return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;
366 }
float operator* ( const FCOORD op1,
const FCOORD op2 
)
friend

cross product

Definition at line 375 of file ipoints.h.

377  {
378  return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;
379 }
FCOORD operator* ( const FCOORD op1,
float  scale 
)
friend

multiply

Definition at line 388 of file ipoints.h.

390  {
391  FCOORD result; //output
392 
393  result.xcoord = op1.xcoord * scale;
394  result.ycoord = op1.ycoord * scale;
395  return result;
396 }
Definition: points.h:189
FCOORD operator* ( float  scale,
const FCOORD op1 
)
friend

multiply

Definition at line 399 of file ipoints.h.

402  {
403  FCOORD result; //output
404 
405  result.xcoord = op1.xcoord * scale;
406  result.ycoord = op1.ycoord * scale;
407  return result;
408 }
Definition: points.h:189
FCOORD& operator*= ( FCOORD op1,
float  scale 
)
friend

multiply

Definition at line 418 of file ipoints.h.

420  {
421  op1.xcoord *= scale;
422  op1.ycoord *= scale;
423  return op1;
424 }
FCOORD operator+ ( const FCOORD op1,
const FCOORD op2 
)
friend

add

Definition at line 294 of file ipoints.h.

296  {
297  FCOORD sum; //result
298 
299  sum.xcoord = op1.xcoord + op2.xcoord;
300  sum.ycoord = op1.ycoord + op2.ycoord;
301  return sum;
302 }
Definition: points.h:189
FCOORD& operator+= ( FCOORD op1,
const FCOORD op2 
)
friend

add

Definition at line 312 of file ipoints.h.

314  {
315  op1.xcoord += op2.xcoord;
316  op1.ycoord += op2.ycoord;
317  return op1;
318 }
FCOORD operator- ( const FCOORD src)
friend

unary minus

Definition at line 276 of file ipoints.h.

278  {
279  FCOORD result; //output
280 
281  result.xcoord = -src.xcoord;
282  result.ycoord = -src.ycoord;
283  return result;
284 }
Definition: points.h:189
FCOORD operator- ( const FCOORD op1,
const FCOORD op2 
)
friend

subtract

Definition at line 328 of file ipoints.h.

330  {
331  FCOORD sum; //result
332 
333  sum.xcoord = op1.xcoord - op2.xcoord;
334  sum.ycoord = op1.ycoord - op2.ycoord;
335  return sum;
336 }
Definition: points.h:189
FCOORD& operator-= ( FCOORD op1,
const FCOORD op2 
)
friend

subtract

Definition at line 346 of file ipoints.h.

348  {
349  op1.xcoord -= op2.xcoord;
350  op1.ycoord -= op2.ycoord;
351  return op1;
352 }
FCOORD operator/ ( const FCOORD op1,
float  scale 
)
friend

divide

Definition at line 434 of file ipoints.h.

436  {
437  FCOORD result; //output
438 
439  if (scale != 0) {
440  result.xcoord = op1.xcoord / scale;
441  result.ycoord = op1.ycoord / scale;
442  }
443  return result;
444 }
Definition: points.h:189
FCOORD& operator/= ( FCOORD op1,
float  scale 
)
friend

divide

Definition at line 454 of file ipoints.h.

456  {
457  if (scale != 0) {
458  op1.xcoord /= scale;
459  op1.ycoord /= scale;
460  }
461  return op1;
462 }

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