37 #include <math/math_util.h>
39 #ifdef WX_COMPATIBILITY
40 #include <wx/gdicmn.h>
65 std::ostream& operator<<( std::ostream& aStream,
const VECTOR2<T>& aVector );
75 template <
class T =
int>
82 static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max();
83 static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min();
92 #ifdef WX_COMPATIBILITY
93 VECTOR2(
const wxPoint& aPoint );
105 template <
typename CastingType>
114 template <
typename CastedType>
160 double Angle()
const;
175 const std::string
Format()
const;
239 bool operator<=(
const VECTOR2<T>& aVector )
const;
243 bool operator>=(
const VECTOR2<T>& aVector )
const;
245 friend std::ostream & operator<< <T> ( std::ostream & stream,
const VECTOR2<T> &vector );
260 #ifdef WX_COMPATIBILITY
288 return sqrt( (extended_type) x * x + (extended_type) y * y );
295 return (extended_type) x * x + (extended_type) y * y;
302 return atan2( (
double) y, (
double) x );
310 return perpendicular;
370 double sa = sin( aAngle );
371 double ca = cos( aAngle );
373 return VECTOR2<T> ( T( (
double) x * ca - (
double) y * sa ),
374 T( (
double) x * sa + (
double) y * ca ) );
381 if( x == 0 && y == 0 )
384 extended_type l_sq_current = (extended_type) x * x + (extended_type) y * y;
385 extended_type l_sq_new = (extended_type) aNewLength * aNewLength;
388 ( x < 0 ? -1 : 1 ) * sqrt( rescale( l_sq_new, (extended_type) x * x, l_sq_current ) ),
389 ( y < 0 ? -1 : 1 ) * sqrt( rescale( l_sq_new, (extended_type) y * y, l_sq_current ) ) ) * sign( aNewLength );
396 std::stringstream ss;
398 ss <<
"( xy " << x <<
" " << y <<
" )";
407 return VECTOR2<T> ( x + aVector.x, y + aVector.y );
414 return VECTOR2<T> ( x + aScalar, y + aScalar );
421 return VECTOR2<T> ( x - aVector.x, y - aVector.y );
428 return VECTOR2<T> ( x - aScalar, y - aScalar );
442 return (extended_type)aVector.x * x + (extended_type)aVector.y * y;
449 VECTOR2<T> vector( x * aFactor, y * aFactor );
457 VECTOR2<T> vector( x / aFactor, y / aFactor );
465 VECTOR2<T> vector( aVector.x * aFactor, aVector.y * aFactor );
473 return (extended_type) x * (extended_type) aVector.y -
474 (extended_type) y * (extended_type) aVector.x;
481 return (extended_type) x * (extended_type) aVector.x +
482 (extended_type) y * (extended_type) aVector.y;
489 return ( *
this * *
this ) < ( aVector * aVector );
496 return ( *
this * *
this ) <= ( aVector * aVector );
503 return ( *
this * *
this ) > ( aVector * aVector );
510 return ( *
this * *
this ) >= ( aVector * aVector );
517 return ( aVector.x == x ) && ( aVector.y == y );
524 return ( aVector.x != x ) || ( aVector.y != y );
533 else if( aA.x == aB.x && aA.y > aB.y )
545 else if( aA.x == aB.x && aA.y < aB.y )
557 else if( aA.x > aB.x )
563 else if( aA.y > aB.y )
572 std::ostream& operator<<( std::ostream& aStream,
const VECTOR2<T>& aVector )
574 aStream <<
"[ " << aVector.x <<
" | " << aVector.y <<
" ]";
589 #endif // VECTOR2D_H_
bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition: vector2d.h:522
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:293
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:364
bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition: vector2d.h:501
VECTOR2< CastedType > operator()() const
Casts a vector to another specialized subclass.
Definition: vector2d.h:115
const std::string Format() const
Function Format returns the vector formatted as a string.
Definition: vector2d.h:394
bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
Definition: vector2d.h:487
VECTOR2< T > Perpendicular() const
Function Perpendicular computes the perpendicular vector.
Definition: vector2d.h:307
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:63
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:286
T extended_type
extended range/precision types used by operations involving multiple multiplications to prevent overf...
Definition: vector2d.h:52
VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition: vector2d.h:254
VECTOR2< T > operator/(const T &aFactor) const
Division with a factor.
Definition: vector2d.h:455
extended_type Cross(const VECTOR2< T > &aVector) const
Function Cross() computes cross product of self with aVector.
Definition: vector2d.h:471
bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition: vector2d.h:515
VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization.
Definition: vector2d.h:106
VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:324
Class VECTOR2_TRAITS traits class for VECTOR2.
Definition: vector2d.h:48
zip_int64_t int64_t
zip_int64_t typedef.
Definition: zip.hpp:103
VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition: vector2d.h:315
VECTOR2< T > operator+(const VECTOR2< T > &aVector) const
Vector addition operator.
Definition: vector2d.h:405
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:379
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:300
extended_type operator*(const VECTOR2< T > &aVector) const
Scalar product operator.
Definition: vector2d.h:440
VECTOR2< T > operator-()
Negate Vector operator.
Definition: vector2d.h:433
VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:342
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:479