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>
129 T EuclideanNorm()
const;
137 extended_type SquaredEuclideanNorm()
const;
160 double Angle()
const;
175 const std::string Format()
const;
181 extended_type Cross(
const VECTOR2<T>& aVector )
const;
187 extended_type Dot(
const VECTOR2<T>& aVector )
const;
211 VECTOR2<T> operator-(
const T& aScalar )
const;
223 extended_type operator*(
const VECTOR2<T>& aVector )
const;
226 VECTOR2<T> operator*(
const T& aFactor )
const;
229 VECTOR2<T> operator/(
const T& aFactor )
const;
232 bool operator==(
const VECTOR2<T>& aVector )
const;
235 bool operator!=(
const VECTOR2<T>& aVector )
const;
238 bool operator<( const VECTOR2<T>& aVector )
const;
239 bool operator<=( const VECTOR2<T>& aVector )
const;
242 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 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 )
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 );
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 );
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_ extended_type Cross(const VECTOR2< T > &aVector) const
Function Cross() computes cross product of self with aVector.
Definition: vector2d.h:471
Class VECTOR2_TRAITS traits class for VECTOR2.
Definition: vector2d.h:48
VECTOR2< T > operator+(const VECTOR2< T > &aVector) const
Vector addition operator.
Definition: vector2d.h:405
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
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition: vector2d.h:293
VECTOR2< CastedType > operator()() const
Casts a vector to another specialized subclass.
Definition: vector2d.h:115
bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition: vector2d.h:522
VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition: vector2d.h:315
T extended_type
extended range/precision types used by operations involving multiple multiplications to prevent overf...
Definition: vector2d.h:52
extended_type operator*(const VECTOR2< T > &aVector) const
Scalar product operator.
Definition: vector2d.h:440
VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition: vector2d.h:254
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
bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition: vector2d.h:515
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:300
GAL_LAYER_ID operator+(const GAL_LAYER_ID &a, int b)
Used for via types.
Definition: layers_id_colors_and_visibility.h:214
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:379
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:364
VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:342
VECTOR2< T > operator/(const T &aFactor) const
Division with a factor.
Definition: vector2d.h:455
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:479
VECTOR2< T > operator-()
Negate Vector operator.
Definition: vector2d.h:433
VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization.
Definition: vector2d.h:106
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:286
VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:324
bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition: vector2d.h:501