7 #ifndef CAFU_MATH_VECTOR2_HPP_INCLUDED
8 #define CAFU_MATH_VECTOR2_HPP_INCLUDED
37 template<
class C>
explicit Vector2T(
const C Values[]) : x(T(Values[0])), y(T(Values[1])) { }
79 assert(
typeid(T)!=
typeid(
float));
89 assert(
typeid(T)!=
typeid(
double));
109 return (*
this-B).GetLengthSqr() <= Epsilon*Epsilon;
189 return x*B.
x + y*B.
y;
255 return A.
x*B.
x + A.
y*B.
y;
259 template<
class T>
inline T length(
const Vector2T<T>& A)
261 return sqrt(dot(A, A));
267 return sqrtf(dot(A, A));
274 const T Length=length(A);
285 const T Length=length(A);
287 return (Length>Epsilon) ? scale(A, T(1.0)/Length) :
Vector2T<T>(0, 0, 0);
290 template<
class T>
inline std::string convertToString(
const Vector2T<T>& A)
295 const int sigdigits=std::numeric_limits<T>::digits10 + 3;
297 std::ostringstream out;
299 out << std::setprecision(sigdigits) <<
"(" << A.
x <<
", " << A.
y <<
")";
305 template<
class T>
inline std::ostream& operator << (std::ostream& os, const Vector2T<T>& A)
307 return os <<
"(" << A.
x <<
", " << A.
y <<
")";
Vector2T< T > GetScaled(const T s) const
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this...
Definition: Vector2.hpp:115
Vector2T(const C Values[])
This constructor initializes the components from an array of (at least) two Ts.
Definition: Vector2.hpp:37
T dot(const Vector2T< T > &B) const
Returns the dot product (Skalarprodukt) of this vector and B.
Definition: Vector2.hpp:187
Vector2T< T > operator*(const T s) const
Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this...
Definition: Vector2.hpp:174
Vector2T< T > & operator-=(const Vector2T< T > &B)
Subtracts B from this vector.
Definition: Vector2.hpp:209
Vector2T< T > operator/(const T s) const
Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of thi...
Definition: Vector2.hpp:180
Vector2T< T > operator-() const
The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1).
Definition: Vector2.hpp:166
Vector2T< T > operator+(const Vector2T< T > &B) const
Returns the sum of this Vector2T<T> and B.
Definition: Vector2.hpp:154
This class represents a 2-dimensional vector.
Definition: Vector2.hpp:21
Vector2T(T x_, T y_)
This constructor initializes the components from x_ and y_ respectively.
Definition: Vector2.hpp:34
Vector2T< double > AsVectorOfDouble() const
Gets this Vector2T<T> as a Vector2T<double>, so that the cast is explicitly visible in user code...
Definition: Vector2.hpp:86
Vector2T< float > AsVectorOfFloat() const
Gets this Vector2T<T> as a Vector2T<float>, so that the cast is explicitly visible in user code...
Definition: Vector2.hpp:76
bool IsEqual(const Vector2T< T > &B, const T Epsilon) const
Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrica...
Definition: Vector2.hpp:107
Invalid operation (invalid use of method, etc.).
Definition: Errors.hpp:33
bool IsValid() const
Returns true if the vector is valid, that is, all components are non-NANs.
Definition: Vector2.hpp:42
Vector2T< T > & operator*=(const T s)
Scales this vector by s.
Definition: Vector2.hpp:218
Vector2T< T > & operator+=(const Vector2T< T > &B)
Adds B to this vector.
Definition: Vector2.hpp:200
T GetLengthSqr() const
Returns the square of the length of this vector.
Definition: Vector2.hpp:101
bool operator==(const Vector2T< T > &B) const
Returns whether this vector and B are truly (bit-wise) identical.
Definition: Vector2.hpp:137
T & operator[](unsigned int Index)
Component access by index number (0 to 1) rather than by name.
Definition: Vector2.hpp:50
T y
The y-component of this vector.
Definition: Vector2.hpp:26
Vector2T< T > & operator/=(const T s)
Divides this vector by s. Assumes that s is not 0.
Definition: Vector2.hpp:227
T x
The x-component of this vector.
Definition: Vector2.hpp:25
bool operator!=(const Vector2T< T > &B) const
Returns whether this vector and B are not equal (bit-wise).
Definition: Vector2.hpp:147
Vector2T()
The default constructor. It initializes all components to zero.
Definition: Vector2.hpp:31
Division by zero error.
Definition: Errors.hpp:24
Vector2T< T > GetScaled(const Vector2T< T > &S) const
Returns a copy of this vector non-uniformely scaled by S.
Definition: Vector2.hpp:121