Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions
vector.h File Reference

Contains Vector class. More...

#include "helpers.h"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <type_traits>
#include <assert.h>

Go to the source code of this file.

Classes

struct  Vector< t_Type, t_Size >
 Vector class. More...

Macros

#define VECTOR_H
#define RESULT_TYPE(ee)   typename std::decay< decltype( ee ) >::type
 Finds the type of ee, and removes reference, const and volatile.
#define VECTOR_VECTOR_ASSIGNMENT_OPERATOR(op)
 Generates code for the assignment operator op (=,+=,*=,etc) taking a Vector argument.
#define VECTOR_SCALAR_ASSIGNMENT_OPERATOR(op)
 Generates code for the assignment operator op (=,+=,*=,etc) taking a scalar argument.
#define VECTOR_OPERATOR(op)
 Generates code for the unary operator op (-,~).
#define VECTOR_VECTOR_OPERATOR(op)
 Generates code for the binary operator op (+,*,<<,etc) taking two Vector arguments.
#define VECTOR_SCALAR_OPERATOR(op)
 Generates code for the binary operator op (+,*,<<,etc) taking a Vector argument on the left, and scalar on the right.
#define SCALAR_VECTOR_OPERATOR(op)
 Generates code for the binary operator op (+,*,<<,etc) taking a scalar argument on the left, and Vector on the right.
#define VECTOR_COMPARISON_OPERATOR(op)
 Generates code for the binary comparison operator op (==,<,etc) taking two Vector arguments. The resulting code simply calls the Compare() function, which orders lexicographically.
#define VECTOR_FUNCTION(fun)
 Generates code for the unary function fun taking a Vector argument. The resulting code simply calls the scalar version of fun for each element.
#define VECTOR_VECTOR_FUNCTION(fun)
 Generates code for the binary function fun taking two Vector arguments. The resulting code simply calls the scalar version of fun for each element.
#define VECTOR_SCALAR_FUNCTION(fun)
 Generates code for the binary function fun taking a Vector argument on the left, and scalar on the right. The resulting code simply calls the scalar version of fun for each element.
#define SCALAR_VECTOR_FUNCTION(fun)
 Generates code for the binary function fun taking a scalar argument on the left, and Vector on the right. The resulting code simply calls the scalar version of fun for each element.

Functions

template<typename t_Type , size_t t_Size>
 RESULT_TYPE (std::sqrt(*static_cast< t_Type const * >(NULL))) Vector< t_Type
template<typename t_LeftType , typename t_RightType , size_t t_Size>
int Compare (Vector< t_LeftType, t_Size > const &left, Vector< t_RightType, t_Size > const &right)
 Compares its arguments lexicographically, returning -1 if left is smaller than right, 1 if it is larger, and 0 if they are equal.
template<typename t_LeftType , typename t_RightType , size_t t_Size>
auto Dot (Vector< t_LeftType, t_Size > const &left, Vector< t_RightType, t_Size > const &right)-> RESULT_TYPE(left.data[0]*right.data[0])
 Returns the dot product of its arguments.
template<typename t_LeftType , typename t_RightType >
auto Cross (Vector< t_LeftType, 3 > const &left, Vector< t_RightType, 3 > const &right)-> Vector< RESULT_TYPE(left.data[0]*right.data[0])
 Returns the cross product of its (3D) arguments.
size_t t_Size std::ostream & operator<< (std::ostream &out, Vector< t_Type, t_Size > const &vector)

Detailed Description

Contains Vector class.

In addition to the Vector class itself, this file also defines a large number of operators and functions acting on vectors.

Definition in file vector.h.

Macro Definition Documentation

#define SCALAR_VECTOR_FUNCTION (   fun)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline auto fun( t_LeftType const& left, Vector< t_RightType, t_Size > const& right ) -> Vector< RESULT_TYPE( fun( left, right.data[ 0 ] ) ), t_Size > { \
Vector< RESULT_TYPE( fun( left, right.data[ 0 ] ) ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = fun( left, right.data[ ii ] ); \
return result; \
}

Generates code for the binary function fun taking a scalar argument on the left, and Vector on the right. The resulting code simply calls the scalar version of fun for each element.

Definition at line 461 of file vector.h.

#define SCALAR_VECTOR_OPERATOR (   op)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline auto operator op ( t_LeftType const& left, Vector< t_RightType, t_Size > const& right ) -> Vector< RESULT_TYPE( left op right.data[ 0 ] ), t_Size > { \
Vector< RESULT_TYPE( left op right.data[ 0 ] ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = ( left op right.data[ ii ] ); \
return result; \
}

Generates code for the binary operator op (+,*,<<,etc) taking a scalar argument on the left, and Vector on the right.

Definition at line 356 of file vector.h.

#define VECTOR_COMPARISON_OPERATOR (   op)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline bool operator op ( Vector< t_LeftType, t_Size > const& left, Vector< t_RightType, t_Size > const& right ) { \
return( Compare( left, right ) op 0 ); \
}

Generates code for the binary comparison operator op (==,<,etc) taking two Vector arguments. The resulting code simply calls the Compare() function, which orders lexicographically.

Definition at line 366 of file vector.h.

#define VECTOR_FUNCTION (   fun)
Value:
template< typename t_Type, size_t t_Size > \
inline auto fun( Vector< t_Type, t_Size > const& vector ) -> Vector< RESULT_TYPE( fun( vector.data[ 0 ] ) ), t_Size > { \
Vector< RESULT_TYPE( fun( vector.data[ 0 ] ) ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = fun( vector.data[ ii ] ); \
return result; \
}

Generates code for the unary function fun taking a Vector argument. The resulting code simply calls the scalar version of fun for each element.

Definition at line 431 of file vector.h.

#define VECTOR_OPERATOR (   op)
Value:
template< typename t_Type, size_t t_Size > \
inline Vector< t_Type, t_Size > operator op ( Vector< t_Type, t_Size > const& vector ) { \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = ( op vector.data[ ii ] ); \
return result; \
}

Generates code for the unary operator op (-,~).

Definition at line 326 of file vector.h.

#define VECTOR_SCALAR_ASSIGNMENT_OPERATOR (   op)
Value:
template< typename t_OtherType > \
inline Vector const& operator op ( t_OtherType const& other ) { \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
data[ ii ] op other; \
return *this; \
}

Generates code for the assignment operator op (=,+=,*=,etc) taking a scalar argument.

Definition at line 55 of file vector.h.

#define VECTOR_SCALAR_FUNCTION (   fun)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline auto fun( Vector< t_LeftType, t_Size > const& left, t_RightType const& right ) -> Vector< RESULT_TYPE( fun( left.data[ 0 ], right ) ), t_Size > { \
Vector< RESULT_TYPE( fun( left.data[ 0 ], right ) ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = fun( left.data[ ii ], right ); \
return result; \
}

Generates code for the binary function fun taking a Vector argument on the left, and scalar on the right. The resulting code simply calls the scalar version of fun for each element.

Definition at line 451 of file vector.h.

#define VECTOR_SCALAR_OPERATOR (   op)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline auto operator op ( Vector< t_LeftType, t_Size > const& left, t_RightType const& right ) -> Vector< RESULT_TYPE( left.data[ 0 ] op right ), t_Size > { \
Vector< RESULT_TYPE( left.data[ 0 ] op right ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = ( left.data[ ii ] op right ); \
return result; \
}

Generates code for the binary operator op (+,*,<<,etc) taking a Vector argument on the left, and scalar on the right.

Definition at line 346 of file vector.h.

#define VECTOR_VECTOR_ASSIGNMENT_OPERATOR (   op)
Value:
template< typename t_OtherType > \
inline Vector const& operator op ( Vector< t_OtherType, t_Size > const& other ) { \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
data[ ii ] op other.data[ ii ]; \
return *this; \
}

Generates code for the assignment operator op (=,+=,*=,etc) taking a Vector argument.

Definition at line 46 of file vector.h.

#define VECTOR_VECTOR_FUNCTION (   fun)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline auto fun( Vector< t_LeftType, t_Size > const& left, Vector< t_RightType, t_Size > const& right ) -> Vector< RESULT_TYPE( fun( left.data[ 0 ], right.data[ 0 ] ) ), t_Size > { \
Vector< RESULT_TYPE( fun( left.data[ 0 ], right.data[ 0 ] ) ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = fun( left.data[ ii ], right.data[ ii ] ); \
return result; \
}

Generates code for the binary function fun taking two Vector arguments. The resulting code simply calls the scalar version of fun for each element.

Definition at line 441 of file vector.h.

#define VECTOR_VECTOR_OPERATOR (   op)
Value:
template< typename t_LeftType, typename t_RightType, size_t t_Size > \
inline auto operator op ( Vector< t_LeftType, t_Size > const& left, Vector< t_RightType, t_Size > const& right ) -> Vector< RESULT_TYPE( left.data[ 0 ] op right.data[ 0 ] ), t_Size > { \
Vector< RESULT_TYPE( left.data[ 0 ] op right.data[ 0 ] ), t_Size > result; \
for ( size_t ii = 0; ii < t_Size; ++ii ) \
result.data[ ii ] = ( left.data[ ii ] op right.data[ ii ] ); \
return result; \
}

Generates code for the binary operator op (+,*,<<,etc) taking two Vector arguments.

Definition at line 336 of file vector.h.