38#ifdef WX_COMPATIBILITY
72template <
class T =
int>
87#ifdef WX_COMPATIBILITY
89 VECTOR2(
const wxPoint& aPoint );
99 template <
typename CastingType>
114 template <
typename CastedType>
125 explicit operator wxPoint()
const
127 return wxPoint(
x,
y );
135 explicit operator wxSize()
const
137 return wxSize(
x,
y );
267#ifdef WX_COMPATIBILITY
310 return perpendicular;
380 if( x == 0 && y == 0 )
386 if( std::is_integral<T>::value )
393 *
sign( aNewLength );
402 *
sign( aNewLength );
410 std::stringstream ss;
412 ss <<
"( xy " << x <<
" " << y <<
" )";
428 return VECTOR2<T> ( x + aScalar, y + aScalar );
442 return VECTOR2<T> ( x - aScalar, y - aScalar );
463 VECTOR2<T> vector( x * aFactor, y * aFactor );
471 if( std::is_integral<T>::value )
474 return VECTOR2<T>( x / aFactor, y / aFactor );
481 VECTOR2<T> vector( aVector.
x * aFactor, aVector.
y * aFactor );
505 return ( *
this * *
this ) < ( aVector * aVector );
512 return ( *
this * *
this ) <= ( aVector * aVector );
519 return ( *
this * *
this ) > ( aVector * aVector );
526 return ( *
this * *
this ) >= ( aVector * aVector );
533 return ( aVector.
x == x ) && ( aVector.
y == y );
540 return ( aVector.
x != x ) || ( aVector.
y != y );
549 else if( aA.
x == aB.
x && aA.
y > aB.
y )
561 else if( aA.
x == aB.
x && aA.
y < aB.
y )
573 else if( aA.
x > aB.
x )
579 else if( aA.
y > aB.
y )
596typename std::enable_if<!std::numeric_limits<T>::is_integer,
bool>::type
598 T aEpsilon = std::numeric_limits<T>::epsilon() )
600 if( !
equals( aFirst.
x, aSecond.
x, aEpsilon ) )
605 return equals( aFirst.
y, aSecond.
y, aEpsilon );
612 aStream <<
"[ " << aVector.
x <<
" | " << aVector.
y <<
" ]";
Define a general 2D-vector/point.
VECTOR2< T > operator-(const T &aScalar) const
Scalar subtraction operator.
VECTOR2< T > & operator+=(const T &aScalar)
Compound assignment operator.
VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization. Beware of rounding issues.
VECTOR2< T > & operator*=(const T &aScalar)
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
VECTOR2< T > & operator*=(const VECTOR2< T > &aVector)
Compound assignment operator.
const std::string Format() const
Return the vector formatted as a string.
VECTOR2()
Construct a 2D-vector with x, y = 0.
VECTOR2(T x, T y)
Construct a vector with given components x, y.
bool operator>=(const VECTOR2< T > &aVector) const
static constexpr extended_type ECOORD_MAX
VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
VECTOR2(const VECTOR2< T > &aVec)
Copy a vector.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
VECTOR2_TRAITS< T >::extended_type extended_type
bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
bool operator<=(const VECTOR2< T > &aVector) const
VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
VECTOR2< T > & operator-=(const T &aScalar)
Compound assignment operator.
bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
static constexpr extended_type ECOORD_MIN
extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
VECTOR2< CastedType > operator()() const
Cast a vector to another specialized subclass. Beware of rounding issues.
bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
extended_type operator*(const VECTOR2< T > &aVector) const
Scalar product operator.
VECTOR2< T > operator+(const VECTOR2< T > &aVector) const
Vector addition operator.
VECTOR2< T > operator-(const VECTOR2< T > &aVector) const
Vector subtraction operator.
VECTOR2< T > operator*(const T &aFactor) const
Multiplication with a factor.
VECTOR2< T > operator+(const T &aScalar) const
Scalar addition operator.
VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
VECTOR2< T > operator-()
Negate Vector operator.
VECTOR2< T > operator/(const T &aFactor) const
Division with a factor.
Traits class for VECTOR2.
T extended_type
< extended range/precision types used by operations involving multiple multiplications to prevent ove...
size_t operator()(const VECTOR2I &k) const =delete
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
VECTOR2< double > VECTOR2D
const int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
std::ostream & operator<<(std::ostream &aStream, const VECTOR2< T > &aVector)
const VECTOR2< T > LexicographicalMax(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
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.
VECTOR2< unsigned int > VECTOR2U
const VECTOR2< T > LexicographicalMin(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
VECTOR2< T > operator*(const T &aFactor, const VECTOR2< T > &aVector)