KiCad PCB EDA Suite
vector2d.h File Reference
#include <limits>
#include <iostream>
#include <sstream>
#include <type_traits>
#include <math/util.h>

Go to the source code of this file.

Classes

struct  VECTOR2_TRAITS< T >
 Traits class for VECTOR2. More...
 
struct  VECTOR2_TRAITS< int >
 
class  VECTOR2< T >
 Define a general 2D-vector/point. More...
 
struct  std::hash< VECTOR2I >
 
struct  std::less< VECTOR2I >
 

Namespaces

namespace  std
 

Typedefs

typedef VECTOR2< double > VECTOR2D
 
typedef VECTOR2< int > VECTOR2I
 
typedef VECTOR2< unsigned int > VECTOR2U
 

Functions

template<class T >
std::ostream & operator<< (std::ostream &aStream, const VECTOR2< T > &aVector)
 
template<class T >
VECTOR2< T > operator* (const T &aFactor, const VECTOR2< T > &aVector)
 
template<class T >
const VECTOR2< T > LexicographicalMax (const VECTOR2< T > &aA, const VECTOR2< T > &aB)
 
template<class T >
const VECTOR2< T > LexicographicalMin (const VECTOR2< T > &aA, const VECTOR2< T > &aB)
 
template<class T >
const int LexicographicalCompare (const VECTOR2< T > &aA, const VECTOR2< T > &aB)
 
template<class T >
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type equals (VECTOR2< T > const &aFirst, VECTOR2< T > const &aSecond, T aEpsilon=std::numeric_limits< T >::epsilon())
 Template to compare two VECTOR2<T> values for equality within a required epsilon. More...
 

Typedef Documentation

◆ VECTOR2D

typedef VECTOR2<double> VECTOR2D

Definition at line 617 of file vector2d.h.

◆ VECTOR2I

typedef VECTOR2<int> VECTOR2I

Definition at line 618 of file vector2d.h.

◆ VECTOR2U

typedef VECTOR2<unsigned int> VECTOR2U

Definition at line 619 of file vector2d.h.

Function Documentation

◆ equals()

template<class T >
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type equals ( VECTOR2< T > const &  aFirst,
VECTOR2< T > const &  aSecond,
aEpsilon = std::numeric_limits<T>::epsilon() 
)

Template to compare two VECTOR2<T> values for equality within a required epsilon.

Parameters
aFirstvalue to compare.
aSecondvalue to compare.
aEpsilonallowed error.
Returns
true if the values considered equal within the specified epsilon, otherwise false.

Definition at line 597 of file vector2d.h.

599{
600 if( !equals( aFirst.x, aSecond.x, aEpsilon ) )
601 {
602 return false;
603 }
604
605 return equals( aFirst.y, aSecond.y, aEpsilon );
606}
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type equals(VECTOR2< T > const &aFirst, VECTOR2< T > const &aSecond, T aEpsilon=std::numeric_limits< T >::epsilon())
Template to compare two VECTOR2<T> values for equality within a required epsilon.
Definition: vector2d.h:597

References equals(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by equals().

◆ LexicographicalCompare()

template<class T >
const int LexicographicalCompare ( const VECTOR2< T > &  aA,
const VECTOR2< T > &  aB 
)

Definition at line 569 of file vector2d.h.

570{
571 if( aA.x < aB.x )
572 return -1;
573 else if( aA.x > aB.x )
574 return 1;
575 else // aA.x == aB.x
576 {
577 if( aA.y < aB.y )
578 return -1;
579 else if( aA.y > aB.y )
580 return 1;
581 else
582 return 0;
583 }
584}

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins().

◆ LexicographicalMax()

template<class T >
const VECTOR2< T > LexicographicalMax ( const VECTOR2< T > &  aA,
const VECTOR2< T > &  aB 
)

Definition at line 545 of file vector2d.h.

546{
547 if( aA.x > aB.x )
548 return aA;
549 else if( aA.x == aB.x && aA.y > aB.y )
550 return aA;
551
552 return aB;
553}

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ LexicographicalMin()

template<class T >
const VECTOR2< T > LexicographicalMin ( const VECTOR2< T > &  aA,
const VECTOR2< T > &  aB 
)

Definition at line 557 of file vector2d.h.

558{
559 if( aA.x < aB.x )
560 return aA;
561 else if( aA.x == aB.x && aA.y < aB.y )
562 return aA;
563
564 return aB;
565}

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ operator*()

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

Definition at line 479 of file vector2d.h.

480{
481 VECTOR2<T> vector( aVector.x * aFactor, aVector.y * aFactor );
482 return vector;
483}
Define a general 2D-vector/point.
Definition: vector2d.h:74

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ operator<<()

template<class T >
std::ostream & operator<< ( std::ostream &  aStream,
const VECTOR2< T > &  aVector 
)

Definition at line 610 of file vector2d.h.

611{
612 aStream << "[ " << aVector.x << " | " << aVector.y << " ]";
613 return aStream;
614}

References VECTOR2< T >::x, and VECTOR2< T >::y.