61std::ostream& operator<<( std::ostream& aStream,
const VECTOR2<T>& aVector );
70template <
class T =
int>
77 static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max();
78 static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min();
95 template <
typename CastingType>
110 template <
typename CastedType>
244 bool operator<=(
const VECTOR2<T>& aVector )
const;
248 bool operator>=(
const VECTOR2<T>& aVector )
const;
289 return sqrt( (extended_type) x * x + (extended_type) y * y );
296 return (extended_type) x * x + (extended_type) y * y;
303 return atan2( (
double) y, (
double) x );
311 return perpendicular;
368 if( aAngle == 0.0 || aAngle == 2 * M_PI )
371 if( aAngle == M_PI_2 )
377 if( aAngle == 3 * M_PI_2 )
380 double sa = sin( aAngle );
381 double ca = cos( aAngle );
383 if( std::is_integral<T>::value )
385 return VECTOR2<T> ( KiROUND( (
double) x * ca - (
double) y * sa ),
386 KiROUND( (
double) x * sa + (
double) y * ca ) );
391 return VECTOR2<T> ( T( (
double) x * ca - (
double) y * sa ),
392 T( (
double) x * sa + (
double) y * ca ) );
400 if( x == 0 && y == 0 )
403 extended_type l_sq_current = (extended_type) x * x + (extended_type) y * y;
404 extended_type l_sq_new = (extended_type) aNewLength * aNewLength;
406 if( std::is_integral<T>::value )
410 KiROUND( std::sqrt( rescale( l_sq_new, (extended_type) x * x, l_sq_current ) ) ),
412 KiROUND( std::sqrt( rescale( l_sq_new, (extended_type) y * y, l_sq_current ) ) ) )
413 * sign( aNewLength );
419 std::sqrt( rescale( l_sq_new, (extended_type) x * x, l_sq_current ) ),
421 std::sqrt( rescale( l_sq_new, (extended_type) y * y, l_sq_current ) ) )
422 * sign( aNewLength );
430 std::stringstream ss;
432 ss <<
"( xy " << x <<
" " << y <<
" )";
441 return VECTOR2<T> ( x + aVector.x, y + aVector.y );
448 return VECTOR2<T> ( x + aScalar, y + aScalar );
455 return VECTOR2<T> ( x - aVector.x, y - aVector.y );
462 return VECTOR2<T> ( x - aScalar, y - aScalar );
476 return (extended_type)aVector.x * x + (extended_type)aVector.y * y;
483 VECTOR2<T> vector( x * aFactor, y * aFactor );
491 if( std::is_integral<T>::value )
492 return VECTOR2<T>( KiROUND( x / aFactor ), KiROUND( y / aFactor ) );
494 return VECTOR2<T>( x / aFactor, y / aFactor );
501 VECTOR2<T> vector( aVector.x * aFactor, aVector.y * aFactor );
509 return (extended_type) x * (extended_type) aVector.y -
510 (extended_type) y * (extended_type) aVector.x;
517 return (extended_type) x * (extended_type) aVector.x +
518 (extended_type) y * (extended_type) aVector.y;
525 return ( *
this * *
this ) < ( aVector * aVector );
532 return ( *
this * *
this ) <= ( aVector * aVector );
539 return ( *
this * *
this ) > ( aVector * aVector );
546 return ( *
this * *
this ) >= ( aVector * aVector );
553 return ( aVector.x == x ) && ( aVector.y == y );
560 return ( aVector.x != x ) || ( aVector.y != y );
569 else if( aA.x == aB.x && aA.y > aB.y )
581 else if( aA.x == aB.x && aA.y < aB.y )
593 else if( aA.x > aB.x )
599 else if( aA.y > aB.y )
608std::ostream& operator<<( std::ostream& aStream,
const VECTOR2<T>& aVector )
610 aStream <<
"[ " << aVector.x <<
" | " << aVector.y <<
" ]";
626 size_t operator()(
const VECTOR2I& k )
const;
Define a general 2D-vector/point.
Definition vector2d.h:72
VECTOR2< T > operator-(const T &aScalar) const
Scalar subtraction operator.
Definition vector2d.h:460
VECTOR2< T > & operator+=(const T &aScalar)
Compound assignment operator.
Definition vector2d.h:334
VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization. Beware of rounding issues.
Definition vector2d.h:96
VECTOR2(const wxPoint &aPoint)
Constructor with a wxPoint as argument.
Definition vector2d.h:264
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition vector2d.h:294
const std::string Format() const
Return the vector formatted as a string.
Definition vector2d.h:428
VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition vector2d.h:257
VECTOR2(T x, T y)
Construct a vector with given components x, y.
Definition vector2d.h:279
VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition vector2d.h:325
VECTOR2(const VECTOR2< T > &aVec)
Copy a vector.
Definition vector2d.h:103
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition vector2d.h:365
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:287
bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition vector2d.h:551
VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition vector2d.h:308
VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition vector2d.h:316
VECTOR2< T > & operator-=(const T &aScalar)
Compound assignment operator.
Definition vector2d.h:352
bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition vector2d.h:558
double Angle() const
Compute the angle of the vector.
Definition vector2d.h:301
extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition vector2d.h:507
VECTOR2< CastedType > operator()() const
Cast a vector to another specialized subclass. Beware of rounding issues.
Definition vector2d.h:111
bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition vector2d.h:537
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition vector2d.h:515
extended_type operator*(const VECTOR2< T > &aVector) const
Scalar product operator.
Definition vector2d.h:474
VECTOR2< T > operator+(const VECTOR2< T > &aVector) const
Vector addition operator.
Definition vector2d.h:439
VECTOR2< T > operator-(const VECTOR2< T > &aVector) const
Vector subtraction operator.
Definition vector2d.h:453
VECTOR2(const wxSize &aSize)
Constructor with a wxSize as argument.
Definition vector2d.h:272
VECTOR2< T > operator*(const T &aFactor) const
Multiplication with a factor.
Definition vector2d.h:481
VECTOR2< T > operator+(const T &aScalar) const
Scalar addition operator.
Definition vector2d.h:446
VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition vector2d.h:343
bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
Definition vector2d.h:523
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:398
VECTOR2< T > operator-()
Negate Vector operator.
Definition vector2d.h:467
VECTOR2< T > operator/(const T &aFactor) const
Division with a factor.
Definition vector2d.h:489
Definition wx_compat.h:40
Definition wx_compat.h:64
Traits class for VECTOR2.
Definition vector2d.h:45
T extended_type
< extended range/precision types used by operations involving multiple multiplications to prevent ove...
Definition vector2d.h:48