21 #ifndef MIA_2D_VECTOR_HH 22 #define MIA_2D_VECTOR_HH 30 #include <type_traits> 84 template <
typename In>
96 return T(x * x + y * y);
101 return T(sqrt(
norm2()));
137 if ( a.
x == 0.0 || a.
y == 0.0)
138 throw std::invalid_argument(
"T2DVector<T>::operator /=: division by zero not allowed");
146 throw std::invalid_argument(
"T2DVector<T>::operator /=: division by zero not allowed");
193 return (x == a.
x && y == a.
y);
198 return (! (*
this == a));
202 void print(std::ostream& os)
const {
219 is.clear(std::ios::badbit);
225 is.clear(std::ios::badbit);
235 is.clear(std::ios::badbit);
250 static const int vector_2d_bit = 0x20000;
253 return type & vector_2d_bit;
257 template <
typename T>
265 template <
typename T>
268 static const int size;
271 template <
typename T>
272 const int atomic_data<T2DVector<T> >
::size = 2;
276 template <
typename T>
279 template <
typename T>
289 template <
typename T>
290 std::ostream& operator << (std::ostream& os, const T2DVector<T>& a)
303 template <
typename T>
317 template <
typename T>
333 template <
typename T,
typename S>
346 template <
typename T>
362 template <
typename T>
378 template <
typename T>
394 template <
typename T>
397 return b.
x * a.
x + b.
y * a.
y;
409 template <
typename T>
424 template <
typename T>
439 template <
typename T>
452 template <
typename T,
typename S>
455 return a.
x < b.x && a.y < b.y;
458 template <
typename T,
template <
typename>
class Vector>
461 static return_type
apply(
const Vector<T>& a,
const Vector<T>& b) {
462 return a.x * b.y - a.y * b.x;
474 template <
typename T>
481 template <
typename T>
484 return a.
y < b.
y || (a.
y == b.
y && a.
x < b.
x);
size_t size() const
returns the size of this vector, always 2
T2DVector< T > operator/(const T2DVector< T > &a, const T2DVector< T > &b)
T value_type
typedef for generic access to the element type
T2DVector(const T2DVector< In > &in)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
#define DEBUG_ASSERT_RELEASE_THROW(cond, msg...)
T2DVector< T > operator+(const T2DVector< T > &a, const T2DVector< T > &b)
static const T2DVector< T > _0
a static for the value <0,0>.
void read(std::istream &is)
read the properly formatted 2D vector from a stream
T2DVector< unsigned int > C2DBounds
unsigned int valued 2D vector - used as 2D size parameter
bool operator==(const T2DVector &a) const
Equal operator.
T2DVector & operator+=(const T2DVector &a)
in place addition
T2DVector< T > operator*(const T2DVector< T > &a, const T2DVector< T > &b)
T cross(const T2DVector< T > &a, const T2DVector< T > &b)
bool operator!=(const T2DVector &a) const
not equal operator
T2DVector & operator/=(const T2DVector &a)
in place element wise division of two 2D vectors
void fill(T v)
fill all the elements with the given value
T2DVector operator-() const
T2DVector & operator-=(const T2DVector &a)
in place subtraction
T2DVector< float > C2DFVector
float valued 2D vector
static const T2DVector< T > _1
a static for the value <1,1>.
static bool is_vector2d(int type)
T dot(const T2DVector< T > &a, const T2DVector< T > &b)
std::istream & operator>>(std::istream &is, T2DVector< T > &a)
T2DVector< double > C2DDVector
double valued 2D vector
void print(std::ostream &os) const
print the vector to a stream with special formatting
static return_type apply(const Vector< T > &a, const Vector< T > &b)
T2DVector & operator*=(double a)
in place multiplication with a scalar
#define NS_MIA_END
conveniance define to end the mia namespace