1 #ifndef _utl_SVector_h_
2 #define _utl_SVector_h_
4 #include <utl/AugerException.h>
5 #include <utl/ErrorLogger.h>
6 #include <utl/ListAssignmentProxy.h>
7 #include <utl/IteratorRange.h>
9 #include <boost/lambda/lambda.hpp>
32 template<std::
size_t n,
typename T =
double>
41 static std::size_t
GetSize() {
return n; }
49 explicit SVector(
const T& init) { Clear(init); }
62 for (std::size_t i = 0; i < n; ++i)
89 Clear(
const T& value = T())
91 for (std::size_t i = 0; i < n; ++i)
103 if (i < 0 || i >= n) {
104 std::ostringstream err;
105 err <<
"Index " << i <<
" out of bounds (" << n <<
')';
115 if (i < 0 || i >= n) {
116 std::ostringstream err;
117 err <<
"Index " << i <<
" out of bounds (" << n <<
')';
124 template<std::
size_t i>
128 template<std::
size_t i>
147 for (std::size_t i = 0; i < n; ++i)
161 transform(this->
Begin(), this->
End(), result.
Begin(), std::negate<T>());
169 for (std::size_t i = 0; i < n; ++i)
178 for (std::size_t i = 0; i < n; ++i)
187 for (std::size_t i = 0; i < n; ++i)
196 for (std::size_t i = 0; i < n; ++i)
201 template<std::
size_t nn,
typename U>
208 for (std::size_t i = 0; i < n; ++i)
214 template<std::
size_t nn,
typename U>
225 template<std::
size_t n,
typename T,
typename U>
227 typename boost::lambda::return_type_2<
228 boost::lambda::arithmetic_action<boost::lambda::multiply_action>,
234 typedef typename boost::lambda::return_type_2<
235 boost::lambda::arithmetic_action<boost::lambda::multiply_action>, T,
U
236 >::type DotProductType;
238 DotProductType sum = a[0] * b[0];
239 for (std::size_t i = 1; i < n; ++i)
247 template<
typename T,
typename U>
251 typename boost::lambda::return_type_2<
252 boost::lambda::arithmetic_action<boost::lambda::multiply_action>, T,
U
259 typename boost::lambda::return_type_2<
260 boost::lambda::arithmetic_action<boost::lambda::multiply_action>, T,
U
265 ret[0] = a[1]*b[2] - a[2]*b[1];
266 ret[1] = a[2]*b[0] - a[0]*b[2];
267 ret[2] = a[0]*b[1] - a[1]*b[0];
272 template<
typename T,
typename U>
277 const double magnitudeA = l.
GetMag();
278 const double magnitudeB = r.
GetMag();
279 return (magnitudeA && magnitudeB) ?
280 (l * r) / (magnitudeA * magnitudeB) : 1;
284 template<
typename T,
typename U>
293 right *= 1/right.
GetMag();
296 const double d2 = diff.GetMag2();
298 return 2 * std::asin(0.5 *
std::sqrt(d2));
300 return 2 * std::acos(0.5 * left.
GetMag());
304 #define UTL_SVECTOR_ARITHMETIC_ACTION(ACTION, OPERATOR) \
305 template<std::size_t n, typename T, typename U> \
307 typename boost::lambda::return_type_2< \
308 boost::lambda::arithmetic_action<boost::lambda::ACTION>, \
312 operator OPERATOR(const SVector<n, T>& a, const SVector<n, U>& b) \
314 typedef typename boost::lambda::return_type_2< \
315 boost::lambda::arithmetic_action<boost::lambda::ACTION>, T, U \
316 >::type ActionType; \
318 SVector<n, ActionType> r; \
320 for (std::size_t i = 0; i < n; ++i) \
321 r[i] = a[i] OPERATOR b[i]; \
329 #undef UTL_SVECTOR_ARITHMETIC_ACTION
332 template<std::
size_t n,
typename T>
334 operator<<(std::ostream& os, const SVector<n, T>& v)
338 for (std::size_t i = 1; i < n; ++i)
344 template<std::
size_t n,
typename T>
348 for (std::size_t i = 0; i < n; ++i)
361 template<std::
size_t n,
typename T,
typename U>
362 class plain_return_type_2<
363 arithmetic_action<multiply_action>,
371 arithmetic_action<multiply_action>,
380 #define UTL_SVECTOR_BINARY_RETURN_TYPE_SPECIALIZATION(ACTION) \
381 template<std::size_t n, typename T, typename U> \
382 class plain_return_type_2< \
383 arithmetic_action<ACTION>, \
384 utl::SVector<n, T>, \
390 arithmetic_action<ACTION>, T, U \
394 typedef utl::SVector<n, res_type> type; \
400 #undef UTL_SVECTOR_BINARY_RETURN_TYPE_SPECIALIZATION
407 #include <utl/SMatrixSVectorOp.h>
SVector & operator-=(const SVector< n, U > &v)
AxialVector Cross(const Vector &l, const Vector &r)
SVector & operator+=(const SVector< n, U > &v)
std::istream & operator>>(std::istream &is, SVector< n, T > &v)
T & At(const int i)
Element access with bound checking.
ListVectorAssignmentProxy< SVector > operator=(const T &e)
#define UTL_SVECTOR_ARITHMETIC_ACTION(ACTION, OPERATOR)
#define OFFLINE_MAKE_BOTH_FRIEND_RANGES(_Iterator_, _ConstIterator_, _Class_)
bool is(const double a, const double b)
double pow(const double x, const unsigned int i)
SVector()=default
Default constructor does not initialize data!
Exception for reporting variable out of valid range.
SVector & operator/=(const U &div)
Static (small and dense) vector class.
double abs(const SVector< n, T > &v)
static std::size_t GetSize()
T & operator[](const std::size_t i)
Vector operator*(const double d, const Vector &v)
const T & operator[](const std::size_t i) const
bool operator==(const SVector< nn, U > &v) const
SVector & operator=(const V &v)
SVector & operator*=(const U &fact)
return_type_2< arithmetic_action< multiply_action >, T, U >::type res_type
#define UTL_SVECTOR_BINARY_RETURN_TYPE_SPECIALIZATION(ACTION)
bool operator!=(const SVector< nn, U > &v) const
double Angle(const Vector &left, const Vector &right)
double CosAngle(const Vector &l, const Vector &r)
ConstIterator Begin() const
ConstIterator End() const
SVector operator-() const
const T & Get() const
static getter