KiCad PCB EDA Suite
numEval::VECTOR2< T > Class Template Reference

Class VECTOR2 defines a general 2D-vector/point. More...

Public Types

typedef VECTOR2_TRAITS< T >::extended_type extended_type
 
typedef T coord_type
 

Public Member Functions

 VECTOR2 ()
 Construct a 2D-vector with x, y = 0. More...
 
 VECTOR2 (T x, T y)
 Construct a vector with given components x, y. More...
 
template<typename CastingType >
 VECTOR2 (const VECTOR2< CastingType > &aVec)
 Initializes a vector from another specialization. More...
 
template<typename CastedType >
VECTOR2< CastedType > operator() () const
 Casts a vector to another specialized subclass. More...
 
 operator wxPoint () const
 (wxPoint) implements the cast to wxPoint. More...
 
EuclideanNorm () const
 Destructor. More...
 
extended_type SquaredEuclideanNorm () const
 Function Squared Euclidean Norm computes the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2). More...
 
VECTOR2< T > Perpendicular () const
 Function Perpendicular computes the perpendicular vector. More...
 
VECTOR2< T > Resize (T aNewLength) const
 Function Resize returns a vector of the same direction, but length specified in aNewLength. More...
 
double Angle () const
 Function Angle computes the angle of the vector. More...
 
VECTOR2< T > Rotate (double aAngle) const
 Function Rotate rotates the vector by a given angle. More...
 
const std::string Format () const
 Function Format returns the vector formatted as a string. More...
 
extended_type Cross (const VECTOR2< T > &aVector) const
 Function Cross() computes cross product of self with aVector. More...
 
extended_type Dot (const VECTOR2< T > &aVector) const
 Function Dot() computes dot product of self with aVector. More...
 
VECTOR2< T > & operator= (const VECTOR2< T > &aVector)
 Assignment operator. More...
 
VECTOR2< T > operator+ (const VECTOR2< T > &aVector) const
 Vector addition operator. More...
 
VECTOR2< T > operator+ (const T &aScalar) const
 Scalar addition operator. More...
 
VECTOR2< T > & operator+= (const VECTOR2< T > &aVector)
 Compound assignment operator. More...
 
VECTOR2< T > & operator+= (const T &aScalar)
 Compound assignment operator. More...
 
VECTOR2< T > operator- (const VECTOR2< T > &aVector) const
 Vector subtraction operator. More...
 
VECTOR2< T > operator- (const T &aScalar) const
 Scalar subtraction operator. More...
 
VECTOR2< T > & operator-= (const VECTOR2< T > &aVector)
 Compound assignment operator. More...
 
VECTOR2< T > & operator-= (const T &aScalar)
 Compound assignment operator. More...
 
VECTOR2< T > operator- ()
 Negate Vector operator. More...
 
extended_type operator* (const VECTOR2< T > &aVector) const
 Scalar product operator. More...
 
VECTOR2< T > operator* (const T &aFactor) const
 Multiplication with a factor. More...
 
VECTOR2< T > operator/ (const T &aFactor) const
 Division with a factor. More...
 
bool operator== (const VECTOR2< T > &aVector) const
 Equality operator. More...
 
bool operator!= (const VECTOR2< T > &aVector) const
 Not equality operator. More...
 
bool operator< (const VECTOR2< T > &aVector) const
 Smaller than operator. More...
 
bool operator<= (const VECTOR2< T > &aVector) const
 
bool operator> (const VECTOR2< T > &aVector) const
 Greater than operator. More...
 
bool operator>= (const VECTOR2< T > &aVector) const
 

Public Attributes

x
 
y
 

Static Public Attributes

static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max()
 
static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min()
 

Detailed Description

template<class T = int>
class numEval::VECTOR2< T >

Class VECTOR2 defines a general 2D-vector/point.

This class uses templates to be universal. Several operators are provided to help easy implementing of linear algebra equations.

Definition at line 61 of file numeric_evaluator.cpp.

Member Typedef Documentation

template<class T = int>
typedef T numEval::VECTOR2< T >::coord_type

Definition at line 78 of file numeric_evaluator.cpp.

template<class T = int>
typedef VECTOR2_TRAITS<T>::extended_type numEval::VECTOR2< T >::extended_type

Definition at line 77 of file numeric_evaluator.cpp.

Constructor & Destructor Documentation

template<class T >
VECTOR2< T >::VECTOR2 ( )

Construct a 2D-vector with x, y = 0.

Definition at line 260 of file numeric_evaluator.cpp.

271  {
template<class T>
VECTOR2< T >::VECTOR2 ( x,
y 
)

Construct a vector with given components x, y.

Definition at line 284 of file numeric_evaluator.cpp.

template<class T = int>
template<typename CastingType >
numEval::VECTOR2< T >::VECTOR2 ( const VECTOR2< CastingType > &  aVec)
inline

Initializes a vector from another specialization.

Beware of rouding issues.

Definition at line 104 of file numeric_evaluator.cpp.

106 {
107  snprintf( m_token.token, m_token.OutLen, "%.10g", val );
108 }

Member Function Documentation

template<class T >
double VECTOR2< T >::Angle ( ) const

Function Angle computes the angle of the vector.

Returns
vector angle, in radians

Definition at line 306 of file numeric_evaluator.cpp.

306  :retval.value.dValue = 1.0 / 25.4; break;
307  case Unit::Invalid :break;
308  }
309  }
template<class T>
VECTOR2< T >::extended_type VECTOR2< T >::Cross ( const VECTOR2< T > &  aVector) const

Function Cross() computes cross product of self with aVector.

Definition at line 477 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T >::extended_type VECTOR2< T >::Dot ( const VECTOR2< T > &  aVector) const

Function Dot() computes dot product of self with aVector.

Definition at line 485 of file numeric_evaluator.cpp.

template<class T >
T VECTOR2< T >::EuclideanNorm ( ) const

Destructor.

Function Euclidean Norm computes the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2). It is used to calculate the length of the vector.

Returns
Scalar, the euclidean norm

Definition at line 292 of file numeric_evaluator.cpp.

293  {
294  case Unit::Inch :retval.value.dValue = 25.4; break;
295  case Unit::Mil :retval.value.dValue = 25.4 / 1000.0; break;
template<class T >
const std::string VECTOR2< T >::Format ( ) const

Function Format returns the vector formatted as a string.

Returns
the formatted string

Definition at line 400 of file numeric_evaluator.cpp.

template<class T = int>
numEval::VECTOR2< T >::operator wxPoint ( ) const
inlineexplicit

(wxPoint) implements the cast to wxPoint.

Returns
wxPoint - the vector cast to wxPoint.

Definition at line 123 of file numeric_evaluator.cpp.

127  {
template<class T>
bool VECTOR2< T >::operator!= ( const VECTOR2< T > &  aVector) const

Not equality operator.

Definition at line 528 of file numeric_evaluator.cpp.

template<class T = int>
template<typename CastedType >
VECTOR2<CastedType> numEval::VECTOR2< T >::operator() ( ) const
inline

Casts a vector to another specialized subclass.

Beware of rouding issues.

Definition at line 113 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T >::extended_type VECTOR2< T >::operator* ( const VECTOR2< T > &  aVector) const

Scalar product operator.

Definition at line 446 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > VECTOR2< T >::operator* ( const T &  aFactor) const

Multiplication with a factor.

Definition at line 453 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > VECTOR2< T >::operator+ ( const VECTOR2< T > &  aVector) const

Vector addition operator.

Definition at line 411 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > VECTOR2< T >::operator+ ( const T &  aScalar) const

Scalar addition operator.

Definition at line 418 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > & VECTOR2< T >::operator+= ( const VECTOR2< T > &  aVector)

Compound assignment operator.

Definition at line 330 of file numeric_evaluator.cpp.

341  {
template<class T>
VECTOR2< T > & VECTOR2< T >::operator+= ( const T &  aScalar)

Compound assignment operator.

Definition at line 339 of file numeric_evaluator.cpp.

341  {
342  // Single char tokens
343  switch( ch )
344  {
template<class T>
VECTOR2< T > VECTOR2< T >::operator- ( const VECTOR2< T > &  aVector) const

Vector subtraction operator.

Definition at line 425 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > VECTOR2< T >::operator- ( const T &  aScalar) const

Scalar subtraction operator.

Definition at line 432 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > VECTOR2< T >::operator- ( )

Negate Vector operator.

Definition at line 439 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > & VECTOR2< T >::operator-= ( const VECTOR2< T > &  aVector)

Compound assignment operator.

Definition at line 348 of file numeric_evaluator.cpp.

348  :retval.token = DIVIDE; break;
349  case '(' :retval.token = PARENL; break;
350  case ')' :retval.token = PARENR; break;
351  case '=' :retval.token = ASSIGN; break;
352  case ';' :retval.token = SEMCOL; break;
353  default :m_parseError = true; break; /* invalid character */
#define ASSIGN
#define PARENR
#define SEMCOL
#define PARENL
#define DIVIDE
template<class T>
VECTOR2< T > & VECTOR2< T >::operator-= ( const T &  aScalar)

Compound assignment operator.

Definition at line 357 of file numeric_evaluator.cpp.

362 {
template<class T>
VECTOR2< T > VECTOR2< T >::operator/ ( const T &  aFactor) const

Division with a factor.

Definition at line 461 of file numeric_evaluator.cpp.

template<class T>
bool VECTOR2< T >::operator< ( const VECTOR2< T > &  aVector) const

Smaller than operator.

Definition at line 493 of file numeric_evaluator.cpp.

template<class T>
bool VECTOR2< T >::operator<= ( const VECTOR2< T > &  aVector) const

Definition at line 500 of file numeric_evaluator.cpp.

template<class T>
VECTOR2< T > & VECTOR2< T >::operator= ( const VECTOR2< T > &  aVector)

Assignment operator.

Definition at line 321 of file numeric_evaluator.cpp.

References numEval::NUMERIC_EVALUATOR::TokenStat::input, numEval::NUMERIC_EVALUATOR::m_token, and numEval::NUMERIC_EVALUATOR::TokenStat::pos.

322  {
323  // VAR
324  const char* cptr = &m_token.input[ m_token.pos ];
325  cptr++;
326 
template<class T>
bool VECTOR2< T >::operator== ( const VECTOR2< T > &  aVector) const

Equality operator.

Definition at line 521 of file numeric_evaluator.cpp.

template<class T>
bool VECTOR2< T >::operator> ( const VECTOR2< T > &  aVector) const

Greater than operator.

Definition at line 507 of file numeric_evaluator.cpp.

template<class T>
bool VECTOR2< T >::operator>= ( const VECTOR2< T > &  aVector) const

Definition at line 514 of file numeric_evaluator.cpp.

template<class T >
VECTOR2< T > VECTOR2< T >::Perpendicular ( ) const

Function Perpendicular computes the perpendicular vector.

Returns
Perpendicular vector

Definition at line 313 of file numeric_evaluator.cpp.

References numEval::NUMERIC_EVALUATOR::Inch, numEval::NUMERIC_EVALUATOR::Invalid, numEval::NUMERIC_EVALUATOR::Metric, and numEval::NUMERIC_EVALUATOR::Mil.

313  {
314  case Unit::Inch :retval.value.dValue = 1.0 * 1000.0; break;
315  case Unit::Mil :retval.value.dValue = 1.0; break;
316  case Unit::Metric :retval.value.dValue = 1000.0 / 25.4; break;
317  case Unit::Invalid :break;
template<class T>
VECTOR2< T > VECTOR2< T >::Resize ( aNewLength) const

Function Resize returns a vector of the same direction, but length specified in aNewLength.

Parameters
aNewLengthlength of the rescaled vector
Returns
rescaled vector

Definition at line 385 of file numeric_evaluator.cpp.

template<class T >
VECTOR2< T > VECTOR2< T >::Rotate ( double  aAngle) const

Function Rotate rotates the vector by a given angle.

Rotate a VECTOR2 by aAngle.

Parameters
aAnglerotation angle in radians
Returns
rotated vector
Parameters
aAngle= rotation angle in radians

Definition at line 370 of file numeric_evaluator.cpp.

template<class T >
VECTOR2< T >::extended_type VECTOR2< T >::SquaredEuclideanNorm ( ) const

Function Squared Euclidean Norm computes the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).

It is used to calculate the length of the vector.

Returns
Scalar, the euclidean norm

Definition at line 299 of file numeric_evaluator.cpp.

References numEval::NUMERIC_EVALUATOR::Inch, and numEval::NUMERIC_EVALUATOR::Mil.

301  {
302  switch( convertFrom )

Member Data Documentation

template<class T = int>
constexpr extended_type numEval::VECTOR2< T >::ECOORD_MAX = std::numeric_limits<extended_type>::max()
static

Definition at line 80 of file numeric_evaluator.cpp.

template<class T = int>
constexpr extended_type numEval::VECTOR2< T >::ECOORD_MIN = std::numeric_limits<extended_type>::min()
static

Definition at line 81 of file numeric_evaluator.cpp.

template<class T = int>
T numEval::VECTOR2< T >::x

Definition at line 83 of file numeric_evaluator.cpp.

template<class T = int>
T numEval::VECTOR2< T >::y

Definition at line 83 of file numeric_evaluator.cpp.


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