35 #include <math/math_util.h>
38 #ifdef WX_COMPATIBILITY
39 #include <wx/gdicmn.h>
64 std::ostream& operator<<( std::ostream& aStream,
const VECTOR2<T>& aVector );
74 template <
class T =
int>
81 static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max();
82 static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min();
91 #ifdef WX_COMPATIBILITY
92 VECTOR2(
const wxPoint& aPoint );
104 template <
typename CastingType>
113 template <
typename CastedType>
238 bool operator<=(
const VECTOR2<T>& aVector )
const;
242 bool operator>=(
const VECTOR2<T>& aVector )
const;
257 #ifdef WX_COMPATIBILITY
285 return sqrt( (extended_type) x * x + (extended_type) y * y );
292 return (extended_type) x * x + (extended_type) y * y;
299 return atan2( (
double) y, (
double) x );
307 return perpendicular;
367 double sa = sin( aAngle );
368 double ca = cos( aAngle );
370 return VECTOR2<T> ( T( (
double) x * ca - (
double) y * sa ),
371 T( (
double) x * sa + (
double) y * ca ) );
378 if( x == 0 && y == 0 )
381 extended_type l_sq_current = (extended_type) x * x + (extended_type) y * y;
382 extended_type l_sq_new = (extended_type) aNewLength * aNewLength;
385 ( x < 0 ? -1 : 1 ) * sqrt( rescale( l_sq_new, (extended_type) x * x, l_sq_current ) ),
386 ( y < 0 ? -1 : 1 ) * sqrt( rescale( l_sq_new, (extended_type) y * y, l_sq_current ) ) ) * sign( aNewLength );
393 std::stringstream ss;
395 ss <<
"( xy " << x <<
" " << y <<
" )";
404 return VECTOR2<T> ( x + aVector.x, y + aVector.y );
411 return VECTOR2<T> ( x + aScalar, y + aScalar );
418 return VECTOR2<T> ( x - aVector.x, y - aVector.y );
425 return VECTOR2<T> ( x - aScalar, y - aScalar );
439 return (extended_type)aVector.x * x + (extended_type)aVector.y * y;
446 VECTOR2<T> vector( x * aFactor, y * aFactor );
454 VECTOR2<T> vector( x / aFactor, y / aFactor );
462 VECTOR2<T> vector( aVector.x * aFactor, aVector.y * aFactor );
470 return (extended_type) x * (extended_type) aVector.y -
471 (extended_type) y * (extended_type) aVector.x;
478 return (extended_type) x * (extended_type) aVector.x +
479 (extended_type) y * (extended_type) aVector.y;
486 return ( *
this * *
this ) < ( aVector * aVector );
493 return ( *
this * *
this ) <= ( aVector * aVector );
500 return ( *
this * *
this ) > ( aVector * aVector );
507 return ( *
this * *
this ) >= ( aVector * aVector );
514 return ( aVector.x == x ) && ( aVector.y == y );
521 return ( aVector.x != x ) || ( aVector.y != y );
530 else if( aA.x == aB.x && aA.y > aB.y )
542 else if( aA.x == aB.x && aA.y < aB.y )
554 else if( aA.x > aB.x )
560 else if( aA.y > aB.y )
569 std::ostream& operator<<( std::ostream& aStream,
const VECTOR2<T>& aVector )
571 aStream <<
"[ " << aVector.x <<
" | " << aVector.y <<
" ]";
586 #endif // VECTOR2D_H_
bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition: vector2d.h:519
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:290
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:361
bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition: vector2d.h:498
VECTOR2< CastedType > operator()() const
Casts a vector to another specialized subclass.
Definition: vector2d.h:114
VECTOR2< T > operator-(const T &aScalar) const
Scalar subtraction operator.
Definition: vector2d.h:423
const std::string Format() const
Function Format returns the vector formatted as a string.
Definition: vector2d.h:391
bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
Definition: vector2d.h:484
VECTOR2< T > & operator+=(const T &aScalar)
Compound assignment operator.
Definition: vector2d.h:330
VECTOR2< T > Perpendicular() const
Function Perpendicular computes the perpendicular vector.
Definition: vector2d.h:304
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:76
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:283
VECTOR2< T > & operator-=(const T &aScalar)
Compound assignment operator.
Definition: vector2d.h:348
T extended_type
extended range/precision types used by operations involving multiple multiplications to prevent overf...
Definition: vector2d.h:51
VECTOR2(T x, T y)
Construct a vector with given components x, y.
Definition: vector2d.h:275
zip_int64_t int64_t
zip_int64_t typedef.
Definition: zip.hpp:103
VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition: vector2d.h:251
VECTOR2< T > operator+(const T &aScalar) const
Scalar addition operator.
Definition: vector2d.h:409
VECTOR2< T > operator/(const T &aFactor) const
Division with a factor.
Definition: vector2d.h:452
extended_type Cross(const VECTOR2< T > &aVector) const
Function Cross() computes cross product of self with aVector.
Definition: vector2d.h:468
bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition: vector2d.h:512
VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization.
Definition: vector2d.h:105
VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:321
Class VECTOR2_TRAITS traits class for VECTOR2.
Definition: vector2d.h:48
VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition: vector2d.h:312
VECTOR2< T > operator+(const VECTOR2< T > &aVector) const
Vector addition operator.
Definition: vector2d.h:402
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:376
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:297
extended_type operator*(const VECTOR2< T > &aVector) const
Scalar product operator.
Definition: vector2d.h:437
VECTOR2< T > operator-(const VECTOR2< T > &aVector) const
Vector subtraction operator.
Definition: vector2d.h:416
VECTOR2< T > operator-()
Negate Vector operator.
Definition: vector2d.h:430
VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:339
VECTOR2< T > operator*(const T &aFactor) const
Multiplication with a factor.
Definition: vector2d.h:444
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:476