37 #include <math/math_util.h> 39 #ifdef WX_COMPATIBILITY 40 #include <wx/gdicmn.h> 59 static const extended_type ECOORD_MAX = 0x7fffffffffffffffULL;
60 static const extended_type ECOORD_MIN = 0x8000000000000000ULL;
67 std::ostream& operator<<( std::ostream& aStream, const VECTOR2<T>& aVector );
77 template <
class T =
int>
91 #ifdef WX_COMPATIBILITY 92 VECTOR2(
const wxPoint& aPoint );
104 template <
typename CastingType>
113 template <
typename CastedType>
128 T EuclideanNorm()
const;
136 extended_type SquaredEuclideanNorm()
const;
159 double Angle()
const;
174 const std::string Format()
const;
180 extended_type Cross(
const VECTOR2<T>& aVector )
const;
186 extended_type Dot(
const VECTOR2<T>& aVector )
const;
210 VECTOR2<T> operator-(
const T& aScalar )
const;
222 extended_type operator*(
const VECTOR2<T>& aVector )
const;
225 VECTOR2<T> operator*(
const T& aFactor )
const;
228 VECTOR2<T> operator/(
const T& aFactor )
const;
231 bool operator==(
const VECTOR2<T>& aVector )
const;
234 bool operator!=(
const VECTOR2<T>& aVector )
const;
237 bool operator<( const VECTOR2<T>& aVector )
const;
238 bool operator<=( const VECTOR2<T>& aVector )
const;
241 bool operator>(
const VECTOR2<T>& aVector )
const;
242 bool operator>=(
const VECTOR2<T>& aVector )
const;
244 friend std::ostream & operator<< <T> ( std::ostream & stream,
const VECTOR2<T> &vector );
259 #ifdef WX_COMPATIBILITY 287 return sqrt( (extended_type) x * x + (extended_type) y * y );
301 return atan2( (
double) y, (
double) x );
309 return perpendicular;
369 double sa = sin( aAngle );
370 double ca = cos( aAngle );
372 return VECTOR2<T> ( T( (
double) x * ca - (
double) y * sa ),
373 T( (
double) x * sa + (
double) y * ca ) );
380 if( x == 0 && y == 0 )
383 extended_type l_sq_current = (
extended_type) x * x + (extended_type) y * y;
384 extended_type l_sq_new = (
extended_type) aNewLength * aNewLength;
387 ( x < 0 ? -1 : 1 ) * sqrt( rescale( l_sq_new, (extended_type) x * x, l_sq_current ) ),
388 ( y < 0 ? -1 : 1 ) * sqrt( rescale( l_sq_new, (extended_type) y * y, l_sq_current ) ) ) * sign( aNewLength );
395 std::stringstream ss;
397 ss <<
"( xy " << x <<
" " << y <<
" )";
406 return VECTOR2<T> ( x + aVector.x, y + aVector.y );
413 return VECTOR2<T> ( x + aScalar, y + aScalar );
420 return VECTOR2<T> ( x - aVector.x, y - aVector.y );
427 return VECTOR2<T> ( x - aScalar, y - aScalar );
441 return aVector.x * x + aVector.y * y;
448 VECTOR2<T> vector( x * aFactor, y * aFactor );
456 VECTOR2<T> vector( x / aFactor, y / aFactor );
464 VECTOR2<T> vector( aVector.x * aFactor, aVector.y * aFactor );
488 return ( *
this * *
this ) < ( aVector * aVector );
495 return ( *
this * *
this ) <= ( aVector * aVector );
502 return ( *
this * *
this ) > ( aVector * aVector );
509 return ( *
this * *
this ) >= ( aVector * aVector );
516 return ( aVector.x == x ) && ( aVector.y == y );
523 return ( aVector.x != x ) || ( aVector.y != y );
532 else if( aA.x == aB.x && aA.y > aB.y )
544 else if( aA.x == aB.x && aA.y < aB.y )
556 else if( aA.x > aB.x )
562 else if( aA.y > aB.y )
571 std::ostream& operator<<( std::ostream& aStream, const VECTOR2<T>& aVector )
573 aStream <<
"[ " << aVector.x <<
" | " << aVector.y <<
" ]";
588 #endif // VECTOR2D_H_ extended_type Cross(const VECTOR2< T > &aVector) const
Function Cross() computes cross product of self with aVector.
Definition: vector2d.h:470
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:404
VECTOR2< T > Perpendicular() const
Function Perpendicular computes the perpendicular vector.
Definition: vector2d.h:306
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
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:292
VECTOR2< CastedType > operator()() const
Casts a vector to another specialized subclass.
Definition: vector2d.h:114
bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition: vector2d.h:521
VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition: vector2d.h:314
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:439
VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition: vector2d.h:253
const std::string Format() const
Function Format returns the vector formatted as a string.
Definition: vector2d.h:393
bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
Definition: vector2d.h:486
bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition: vector2d.h:514
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:299
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:378
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:363
VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:341
VECTOR2< T > operator/(const T &aFactor) const
Division with a factor.
Definition: vector2d.h:454
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:478
VECTOR2< T > operator-()
Negate Vector operator.
Definition: vector2d.h:432
VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization.
Definition: vector2d.h:105
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:285
VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:323
bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition: vector2d.h:500