45#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_VECTOR_4D_INL
46#define LASS_GUARDIAN_OF_INCLUSION_PRIM_VECTOR_4D_INL
61template<
typename T>
inline
62Vector4D<T>::Vector4D() :
72template<
typename T>
inline
73Vector4D<T>::Vector4D(TParam x, TParam y, TParam z, TParam w) :
85Vector4D<T>::Vector4D(
const Vector4D<U>& other):
86 x(static_cast<TValue>(other.x)),
87 y(static_cast<TValue>(other.y)),
88 z(static_cast<TValue>(other.z)),
89 w(static_cast<TValue>(other.w))
97Vector4D<T>::Vector4D(
const U& x,
const U& y,
const U& z,
const U& w):
98 x(static_cast<TValue>(x)),
99 y(static_cast<TValue>(y)),
100 z(static_cast<TValue>(z)),
101 w(static_cast<TValue>(w))
107template<
typename T>
inline
108typename Vector4D<T>::TConstReference Vector4D<T>::operator[](
size_t index)
const
110 LASS_ASSERT(index < dimension);
111 return *(&x + index);
116template<
typename T>
inline
117typename Vector4D<T>::TReference Vector4D<T>::operator[](
size_t index)
119 LASS_ASSERT(index < dimension);
120 return *(&x + index);
127template<
typename T>
inline
130 return *(&x + num::mod(index, dimension));
137template<
typename T>
inline
140 return *(&x + num::mod(index, dimension));
147template<
typename T>
inline
155template<
typename T>
inline
165template<
typename T>
inline
179template<
typename T>
inline
193template<
typename T>
inline
207template<
typename T>
inline
221template<
typename T>
inline
235template<
typename T>
inline
249template<
typename T>
inline
263template<
typename T>
inline
277template<
typename T>
inline
280 return x == TNumTraits::zero && y == TNumTraits::zero &&
281 z == TNumTraits::zero && w == TNumTraits::zero;
288template<
typename T>
inline
291 return num::isNaN(x) || num::isNaN(y) || num::isNaN(z) || num::isNaN(w);
298template<
typename T>
inline
301 return dot(*
this, *
this);
308template<
typename T>
inline
325 Vector4D<T> result(*
this);
337 Vector4D<T> result(*
this);
338 result *=
dot(other, *
this);
347template<
typename T>
inline
355template<
typename T>
inline
358 return 2 *
project(other) - other;
368 return Vector4D<T>(iOperator(x), iOperator(y), iOperator(z), iOperator(w));
375template<
typename T>
inline
386template<
typename T>
inline
387typename Vector4D<T>::TValue
dot(
const Vector4D<T>& a,
const Vector4D<T>& b)
389 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
396template<
typename T>
inline
399 return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
406template<
typename T>
inline
407bool operator!=(
const Vector4D<T>& a,
const Vector4D<T>& b)
417template<
typename T>
inline
418Vector4D<T>
operator+(
const Vector4D<T>& a,
const Vector4D<T>& b)
420 Vector4D<T> result(a);
430template<
typename T>
inline
431Vector4D<T>
operator-(
const Vector4D<T>& a,
const Vector4D<T>& b)
433 Vector4D<T> result(a);
443template<
typename T>
inline
444Vector4D<T>
operator*(
const Vector4D<T>& a,
const Vector4D<T>& b)
446 Vector4D<T> result(a);
456template<
typename T>
inline
457Vector4D<T>
operator/(
const Vector4D<T>& a,
const Vector4D<T>& b)
459 Vector4D<T> result(a);
469template<
typename T>
inline
470Vector4D<T>
operator+(
const Vector4D<T>& a,
typename Vector4D<T>::TParam b)
472 Vector4D<T> result(a);
482template<
typename T>
inline
483Vector4D<T>
operator-(
const Vector4D<T>& a,
typename Vector4D<T>::TParam b)
485 Vector4D<T> result(a);
495template<
typename T>
inline
496Vector4D<T>
operator*(
const Vector4D<T>& a,
typename Vector4D<T>::TParam b)
498 Vector4D<T> result(a);
508template<
typename T>
inline
509Vector4D<T>
operator/(
const Vector4D<T>& a,
typename Vector4D<T>::TParam b)
511 Vector4D<T> result(a);
521template<
typename T>
inline
522Vector4D<T>
operator+(
typename Vector4D<T>::TParam a,
const Vector4D<T>& b)
524 Vector4D<T> result(b);
534template<
typename T>
inline
535Vector4D<T>
operator-(
typename Vector4D<T>::TParam a,
const Vector4D<T>& b)
537 Vector4D<T> result(-b);
547template<
typename T>
inline
548Vector4D<T>
operator*(
typename Vector4D<T>::TParam a,
const Vector4D<T>& b)
550 Vector4D<T> result(b);
560template<
typename T>
inline
563 return Vector4D<T>(std::min(a.x, b.x), std::min(a.y, b.y),
564 std::min(a.z, b.z), std::min(a.w, b.w));
572template<
typename T>
inline
575 return Vector4D<T>(std::max(a.x, b.x), std::max(a.y, b.y),
576 std::max(a.z, b.z), std::max(a.w, b.w));
585inline Vector4D<T>
lerp(
const Vector4D<T>& a,
const Vector4D<T>& b,
typename Vector4D<T>::TParam t)
587 Vector4D<T> result = b;
598template<
typename T,
typename Char,
typename Traits>
599std::basic_ostream<Char, Traits>& operator<<(
600 std::basic_ostream<Char, Traits>& stream,
const Vector4D<T>& b)
602 LASS_ENFORCE_STREAM(stream) <<
"(" << b.x <<
", " << b.y <<
", " << b.z <<
", " << b.w <<
")";
610template<
typename T,
typename Char,
typename Traits>
611std::basic_istream<Char, Traits>& operator>>(
612 std::basic_istream<Char, Traits>& stream, Vector4D<T>& b)
620 stream.clear(std::ios::failbit);
625 stream >> result.x >> c;
628 stream.clear(std::ios::failbit);
633 stream >> result.y >> c;
636 stream.clear(std::ios::failbit);
641 stream >> result.z >> c;
644 stream.clear(std::ios::failbit);
649 stream >> result.w >> c;
652 stream.clear(std::ios::failbit);
665io::XmlOStream& operator<<(io::XmlOStream& stream,
const Vector4D<T>& b)
667 LASS_ENFORCE_STREAM(stream)
668 <<
"<Vector4D>" << b.x <<
" " << b.y <<
" " << b.z <<
" " << b.w <<
"</Vector4D>\n";
LineSegment3D< T, PP > project(const Plane3D< T, EP, NP > &plane, const LineSegment3D< T, PP > &lineSegment)
project a linesegment on a plane.
T norm(const T &x)
return norm of x as if x is real part of complex number: sqr(x)
set of geometrical primitives
Library for Assembled Shared Sources.
Vector4D< T > operator/(const Vector4D< T > &a, typename Vector4D< T >::TParam b)
divide all components of a by b
const Vector4D< T > & operator+() const
A weird way to get back the same object.
Vector4D< T >::TValue dot(const Vector4D< T > &a, const Vector4D< T > &b)
dot product.
const Vector4D< T > reject(const Vector4D< T > &other) const
Project vector on this one.
Vector4D< T > operator+(const Vector4D< T > &a, const Vector4D< T > &b)
componentwise addition
Vector4D< T > lerp(const Vector4D< T > &a, const Vector4D< T > &b, typename Vector4D< T >::TParam t)
interpolate linearly between two vectors: a + t * (b - a)
Vector4D< T > operator-(typename Vector4D< T >::TParam a, const Vector4D< T > &b)
subtract a of all components of b
const Vector4D< T > normal() const
return a unit vector with same direction/sense as this vector.
Vector4D::TConstReference at(signed index) const
Wrap index around range.
const TValue norm() const
Return norm of vector.
Vector4D< T > operator*(typename Vector4D< T >::TParam a, const Vector4D< T > &b)
multiply all components of b with a
bool isZero() const
Return true if all the components are (exactly!) zero.
Vector4D< T > operator+(const Vector4D< T > &a, typename Vector4D< T >::TParam b)
add b to all components of a.
const TValue squaredNorm() const
Return squared norm of vector.
Vector4D< T > & operator+=(const Vector4D< T > &other)
componentwise addition
void normalize()
Normalize vector.
Vector4D< T > operator*(const Vector4D< T > &a, const Vector4D< T > &b)
Componentwise multiplication.
Vector4D< T > & operator/=(const Vector4D< T > &other)
Componentwise division.
Vector4D< T > & operator*=(const Vector4D< T > &other)
Componentwise multiplication.
const Vector4D< T > transform(T(*op)(T)) const
apply a function to every component
Vector4D< T > pointwiseMin(const Vector4D< T > &a, const Vector4D< T > &b)
return a vector with, for each coordinate, the minimum value of a and b
Vector4D< T > & operator-=(const Vector4D< T > &other)
componentwise subtraction
const Vector4D< T > project(const Vector4D< T > &other) const
Project vector on this one.
Vector4D< T > operator*(const Vector4D< T > &a, typename Vector4D< T >::TParam b)
muliply all components of a by b
bool isNaN() const
Return true if at least one of the components is NaN.
Vector4D< T > operator-(const Vector4D< T > &a, typename Vector4D< T >::TParam b)
subtract b of all components of a.
Vector4D< T > operator/(const Vector4D< T > &a, const Vector4D< T > &b)
Componentwise division.
Vector4D< T > pointwiseMax(const Vector4D< T > &a, const Vector4D< T > &b)
return a vector with, for each coordinate, the maximum value of a and b
Vector4D< T > operator+(typename Vector4D< T >::TParam a, const Vector4D< T > &b)
add a to all components of b
Vector4D< T > operator-(const Vector4D< T > &a, const Vector4D< T > &b)
componentwise subtraction