21 #ifndef __MIA_3DVECTOR_HH 22 #define __MIA_3DVECTOR_HH 1 30 #include <type_traits> 81 x(T(org.x)),y(T(org.y)),z(T(org.z)){
87 x=org.
x; y=org.
y; z=org.
z;
93 return x * x + y * y + z *
z;
102 return sqrt(
norm2());
130 throw std::logic_error(
"Access to vectorelement out of range");
149 throw std::logic_error(
"Access to vectorelement out of range");
155 x+=a.
x; y+=a.
y; z+=a.
z;
161 x-=a.
x; y-=a.
y; z-=a.
z;
167 x = T(x * a); y = T(y * a); z = T(z * a);
173 x = T(x * a.
x); y = T(y * a.
y); z = T(z * a.
z);
181 x = T(x/ a); y =T (y / a); z = T(z / a);
191 os << x <<
"," << y <<
"," <<
z;
207 is.clear(std::ios::badbit);
213 is.clear(std::ios::badbit);
219 is.clear(std::ios::badbit);
230 is.clear(std::ios::badbit);
236 is.clear(std::ios::badbit);
289 static const int vector_3d_bit = 0x40000;
292 return type & vector_3d_bit;
296 template <
typename T>
303 template <
typename T>
306 static const int size;
309 template <
typename T>
310 const int atomic_data<T3DVector<T> >
::size = 3;
321 template <
typename T>
325 a.
y * b.
z - b.
y * a.
z,
326 a.
z * b.
x - b.
z * a.
x,
327 a.
x * b.
y - b.
x * a.
y 341 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z;
358 std::ostream& operator << (std::ostream& os, const T3DVector<T>& v)
389 template <
typename T,
typename S>
428 assert(b.
x != 0.0 && b.
y != 0.0 && b.
z != 0.0);
456 a.
z * b.
x - b.
z * a.
x,
457 a.
x * b.
y - b.
x * a.
y);
464 return (b.
x == a.
x && b.
y == a.
y && b.
z == a.
z);
477 return (a.x < b.x && a.y < b.y && a.z < b.z);
483 return (b.x <= a.x && b.y <= a.y && b.z <= a.z);
489 return (b.
x > a.
x && b.
y > a.
y && b.
z > a.
z);
495 return (b.
x >= a.
x && b.
y >= a.
y && b.
z >= a.
z);
497 template <
typename T >
500 template <
typename T >
503 template <
typename T>
508 (a.
y < b.
y || (a.
y == b.
y && a.
x < b.
x)));
const T3DVector< T > operator/(const T3DVector< T > &a, double f)
vector division by scalar
T3DVector< T > & operator=(const T3DVector< T > &other)=default
we provide the default copy mechanisms
const T operator[](size_t i) const
T3DVector< double > C3DDVector
A double 3D Vector.
void read(std::istream &is)
read the vector from a formatted string
const T3DVector< T > operator+(const T3DVector< T > &a, const T3DVector< T > &b)
vector addition
double norm2() const
square of Euclidian norm of the vector
const T3DVector< T > yxz() const
swizzle operator
bool operator==(const T3DVector< T > &a, const T3DVector< T > &b)
comparison operator equal
T3DVector< float > C3DFVector
A float 3D Vector.
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
T value_type
typedef for generic programming
double dot(const T3DVector< T > &a, const T3DVector< T > &b)
static T3DVector< T > _0
declare the vector (0,0,0)
T3DVector< T > & operator-=(const T3DVector< T > &a)
inplace subtraction
T3DVector< T > & operator/=(const double a)
inplace divisison by a scalar
T3DVector()
standart constructor
T3DVector< T > cross(const T3DVector< T > &a, const T3DVector< T > &b)
const T3DVector< T > & xyz() const
swizzle operator
const T3DVector< T > zxy() const
swizzle operator
std::istream & operator>>(std::istream &is, T3DVector< T > &v)
stream input operator for 3DVector
const T3DVector< T > operator*(const T3DVector< T > &a, const T3DVector< T > &b)
vector scalar product
T3DVector< T > & operator*=(const double a)
inplace multiplication
static T3DVector< T > _1
declare the vector (1,1,1)
bool operator>=(const T3DVector< T > &b, const T3DVector< T > &a)
comparison greater or equal, returns true if all components of a are greater or equal then those of b...
double fabs(const T3DVector< T > &t)
A way to get the norm of a T3DVector using faba syntax.
const T3DVector< T > operator^(const T3DVector< T > &a, const T3DVector< T > &b)
3D vector cross product
void fill(T v)
Fill the vector elements with value v.
T3DVector(const T3DVector< in > &org)
type casting copy constructor
static const unsigned int elements
the number of elements this vector holds (=3)
T3DVector(const T &x_, const T &y_, const T &z_)
constructor to construct vector from values
T3DVector(int dim)
create a zero-vector, dim must be 3
T3DVector< unsigned int > C3DBounds
A unsinged int 3D Vector (used for 3D field sizes)
const T3DVector< T > xzy() const
swizzle operator
T3DVector< T > & operator+=(const T3DVector< T > &a)
inplace addition
T3DVector operator-() const
const T3DVector< T > zyx() const
swizzle operator
const T3DVector< T > yzx() const
swizzle operator
bool operator>(const T3DVector< T > &b, const T3DVector< T > &a)
comparison greater, returns true if all components of a are greater then those of b ...
bool operator!=(const T3DVector< T > &a, const T3DVector< T > &b)
comparison operator not equal
void write(std::ostream &os) const
print out the formatted vector to the stream
static bool is_vector3d(int type)
#define NS_MIA_END
conveniance define to end the mia namespace