library of assembled shared sources

http://lass.cocamware.com

lass::prim::Vector2D< T > Struct Template Reference

2D Vector More...

#include <vector_2d.h>


Data Structures

struct  Rebind

Public Types

enum  { dimension = 2 }
typedef Vector2D< T > TSelf
typedef util::CallTraits< T >
::TValue 
TValue
typedef util::CallTraits< T >
::TParam 
TParam
typedef util::CallTraits< T >
::TReference 
TReference
typedef util::CallTraits< T >
::TConstReference 
TConstReference
typedef num::NumTraits< T > TNumTraits

Public Member Functions

 Vector2D ()
 Vector2D (TParam x, TParam y)
template<typename U >
 Vector2D (const Vector2D< U > &other)
template<typename U >
 Vector2D (const U &x, const U &y)
Vector2D::TConstReference operator[] (size_t index) const
Vector2D::TReference operator[] (size_t index)
Vector2D::TConstReference at (signed index) const
 Wrap index around range.
Vector2D::TReference at (signed index)
 Wrap index around range.
const Vector2D< T > & operator+ () const
 A weird way to get back the same object.
const Vector2D< T > operator- () const
Vector2D< T > & operator+= (const Vector2D< T > &other)
 componentwise addition
Vector2D< T > & operator-= (const Vector2D< T > &other)
 componentwise subtraction
Vector2D< T > & operator*= (const Vector2D< T > &other)
 Componentwise multiplication.
Vector2D< T > & operator/= (const Vector2D< T > &other)
 Componentwise division.
Vector2D< T > & operator+= (TParam other)
 add other to each component of this.
Vector2D< T > & operator-= (TParam other)
 subtract other of each component of this.
Vector2D< T > & operator*= (TParam other)
 multiply each component of this with other.
Vector2D< T > & operator/= (TParam other)
 divide each component of this by other.
const bool isZero () const
 Return true if all the components are (exactly!) zero.
const bool isNaN () const
 Return true if at least one of the components is NaN.
const TValue squaredNorm () const
 Return squared norm of vector.
const TValue norm () const
 Return norm of vector.
const Vector2D< T > normal () const
 return a unit vector with same direction/sense as this vector.
const Vector2D< T > reciprocal () const
 return the reciprocal version of this vector
const Vector2D< T > perp () const
 return the vector perpendicular to this one, 90° to the left.
const Vector2D< T > project (const Vector2D< T > &other) const
 Project vector on this one.
const Vector2D< T > reject (const Vector2D< T > &other) const
 Project vector on this one.
const Vector2D< T > reflect (const Vector2D< T > &other) const
const Vector2D< T > transform (T(*iOperator)(T)) const
 apply a function to every component
void normalize ()
 Normalize vector.

Static Public Member Functions

template<class RandomGenerator >
static Vector2D< T > random (RandomGenerator &generator)
 Random unit vector.

Data Fields

TValue x
TValue y

Related Functions

(Note that these are not member functions.)

template<typename T >
Vector2D< T >::TValue dot (const Vector2D< T > &a, const Vector2D< T > &b)
 dot product.
template<typename T >
Vector2D< T >::TValue cos (const Vector2D< T > &a, const Vector2D< T > &b)
 returns cosine of angle between both vectors.
template<typename T >
Vector2D< T >::TValue perpDot (const Vector2D< T > &a, const Vector2D< T > &b)
 perp dot product (cross product for 2D vectors).
template<typename T >
bool operator== (const Vector2D< T > &a, const Vector2D< T > &b)
template<typename T >
bool operator!= (const Vector2D< T > &a, const Vector2D< T > &b)
template<typename T >
Vector2D< T > operator+ (const Vector2D< T > &a, const Vector2D< T > &b)
 componentwise addition
template<typename T >
Vector2D< T > operator- (const Vector2D< T > &a, const Vector2D< T > &b)
 componentwise subtraction
template<typename T >
Vector2D< T > operator* (const Vector2D< T > &a, const Vector2D< T > &b)
 Componentwise multiplication.
template<typename T >
Vector2D< T > operator/ (const Vector2D< T > &a, const Vector2D< T > &b)
 Componentwise division.
template<typename T >
Vector2D< T > operator+ (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 add b to all components of a.
template<typename T >
Vector2D< T > operator- (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 subtract b of all components of a.
template<typename T >
Vector2D< T > operator* (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 muliply all components of a by b
template<typename T >
Vector2D< T > operator/ (const Vector2D< T > &a, typename Vector2D< T >::TParam b)
 divide all components of a by b
template<typename T >
Vector2D< T > operator+ (typename Vector2D< T >::TParam a, const Vector2D< T > &b)
 add a to all components of b
template<typename T >
Vector2D< T > operator- (typename Vector2D< T >::TParam a, const Vector2D< T > &b)
 subtract a of all components of b
template<typename T >
Vector2D< T > operator* (typename Vector2D< T >::TParam a, const Vector2D< T > &b)
 multiply all components of b with a
template<typename T >
Vector2D< T > pointwiseMin (const Vector2D< T > &a, const Vector2D< T > &b)
 return a vector with, for each coordinate, the minimum value of a and b
template<typename T >
Vector2D< T > pointwiseMax (const Vector2D< T > &a, const Vector2D< T > &b)
 return a vector with, for each coordinate, the maximum value of a and b
template<typename T >
Vector2D< T > lerp (const Vector2D< T > &a, const Vector2D< T > &b, typename Vector2D< T >::TParam t)
 interpolate linearly between two vectors: a + t * (b - a)
template<typename T , typename Char , typename Traits >
std::basic_ostream< Char,
Traits > & 
operator<< (std::basic_ostream< Char, Traits > &stream, const Vector2D< T > &b)
template<typename T , typename Char , typename Traits >
std::basic_istream< Char,
Traits > & 
operator>> (std::basic_istream< Char, Traits > &stream, Vector2D< T > &b)
template<typename T >
io::XmlOStreamoperator<< (io::XmlOStream &stream, const Vector2D< T > &b)


Detailed Description

template<typename T>
struct lass::prim::Vector2D< T >

2D Vector

Author:
BdG
Date:
2003

Definition at line 71 of file vector_2d.h.


Member Typedef Documentation

template<typename T >
typedef Vector2D<T> lass::prim::Vector2D< T >::TSelf

Definition at line 73 of file vector_2d.h.

template<typename T >
typedef util::CallTraits<T>::TValue lass::prim::Vector2D< T >::TValue

Definition at line 75 of file vector_2d.h.

template<typename T >
typedef util::CallTraits<T>::TParam lass::prim::Vector2D< T >::TParam

Definition at line 76 of file vector_2d.h.

template<typename T >
typedef util::CallTraits<T>::TReference lass::prim::Vector2D< T >::TReference

Definition at line 77 of file vector_2d.h.

template<typename T >
typedef util::CallTraits<T>::TConstReference lass::prim::Vector2D< T >::TConstReference

Definition at line 78 of file vector_2d.h.

template<typename T >
typedef num::NumTraits<T> lass::prim::Vector2D< T >::TNumTraits

Definition at line 79 of file vector_2d.h.


Member Enumeration Documentation

template<typename T >
anonymous enum

Enumerator:
dimension 

Definition at line 81 of file vector_2d.h.


Constructor & Destructor Documentation

template<typename T >
lass::prim::Vector2D< T >::Vector2D (  )  [inline]

Definition at line 62 of file vector_2d.inl.

Referenced by lass::prim::Vector2D< T >::operator-().

template<typename T >
lass::prim::Vector2D< T >::Vector2D ( TParam  x,
TParam  y 
) [inline]

Definition at line 71 of file vector_2d.inl.

template<typename T >
template<typename U >
lass::prim::Vector2D< T >::Vector2D ( const Vector2D< U > &  other  )  [inline, explicit]

Definition at line 81 of file vector_2d.inl.

template<typename T >
template<typename U >
lass::prim::Vector2D< T >::Vector2D ( const U &  x,
const U &  y 
) [inline]

Definition at line 91 of file vector_2d.inl.


Member Function Documentation

template<typename T >
Vector2D< T >::TConstReference lass::prim::Vector2D< T >::operator[] ( size_t  index  )  const [inline]

template<typename T >
Vector2D< T >::TReference lass::prim::Vector2D< T >::operator[] ( size_t  index  )  [inline]

template<typename T >
Vector2D< T >::TConstReference lass::prim::Vector2D< T >::at ( signed  index  )  const [inline]

Wrap index around range.

Definition at line 120 of file vector_2d.inl.

References lass::prim::Vector2D< T >::dimension, lass::num::mod(), and lass::prim::Vector2D< T >::x.

template<typename T >
Vector2D< T >::TReference lass::prim::Vector2D< T >::at ( signed  index  )  [inline]

Wrap index around range.

Definition at line 130 of file vector_2d.inl.

References lass::prim::Vector2D< T >::dimension, lass::num::mod(), and lass::prim::Vector2D< T >::x.

template<typename T >
const Vector2D< T > & lass::prim::Vector2D< T >::operator+ (  )  const [inline]

A weird way to get back the same object.

Definition at line 140 of file vector_2d.inl.

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::operator- (  )  const [inline]

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator+= ( const Vector2D< T > &  other  )  [inline]

componentwise addition

Definition at line 158 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator-= ( const Vector2D< T > &  other  )  [inline]

componentwise subtraction

Definition at line 170 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator*= ( const Vector2D< T > &  other  )  [inline]

Componentwise multiplication.

Definition at line 182 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator/= ( const Vector2D< T > &  other  )  [inline]

Componentwise division.

Definition at line 194 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator+= ( TParam  other  )  [inline]

add other to each component of this.

Definition at line 206 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator-= ( TParam  other  )  [inline]

subtract other of each component of this.

Definition at line 218 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator*= ( TParam  other  )  [inline]

multiply each component of this with other.

Definition at line 230 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > & lass::prim::Vector2D< T >::operator/= ( TParam  other  )  [inline]

divide each component of this by other.

Definition at line 242 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
const bool lass::prim::Vector2D< T >::isZero (  )  const [inline]

template<typename T >
const bool lass::prim::Vector2D< T >::isNaN (  )  const [inline]

Return true if at least one of the components is NaN.

Definition at line 264 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
const Vector2D< T >::TValue lass::prim::Vector2D< T >::squaredNorm (  )  const [inline]

template<typename T >
const Vector2D< T >::TValue lass::prim::Vector2D< T >::norm (  )  const [inline]

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::normal (  )  const [inline]

return a unit vector with same direction/sense as this vector.

The normalized vector of X is a vector in the same direction but with norm (length) 1. It is denoted X^ and given by X^ = X / |X|, http://mathworld.wolfram.com/NormalizedVector.html.

Definition at line 298 of file vector_2d.inl.

References lass::prim::Vector2D< T >::normalize().

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::reciprocal (  )  const [inline]

return the reciprocal version of this vector

Definition at line 310 of file vector_2d.inl.

References lass::num::NumTraits< C >::one.

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::perp (  )  const [inline]

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::project ( const Vector2D< T > &  other  )  const [inline]

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::reject ( const Vector2D< T > &  other  )  const [inline]

Project vector on this one.

Definition at line 345 of file vector_2d.inl.

References lass::prim::Vector2D< T >::project().

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::reflect ( const Vector2D< T > &  other  )  const [inline]

Definition at line 353 of file vector_2d.inl.

References lass::prim::Vector2D< T >::project().

template<typename T >
const Vector2D< T > lass::prim::Vector2D< T >::transform ( T(*)(T)  iOperator  )  const [inline]

apply a function to every component

Definition at line 363 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
void lass::prim::Vector2D< T >::normalize (  )  [inline]

template<typename T >
template<class RandomGenerator >
Vector2D< T > lass::prim::Vector2D< T >::random ( RandomGenerator &  generator  )  [inline, static]


Friends And Related Function Documentation

template<typename T >
Vector2D< T >::TValue dot ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

template<typename T >
Vector2D< T >::TValue cos ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

returns cosine of angle between both vectors.

Definition at line 409 of file vector_2d.inl.

References lass::prim::dot(), sqrt(), and lass::prim::Vector2D< T >::squaredNorm().

Referenced by lass::prim::Vector2D< T >::random().

template<typename T >
Vector2D< T >::TValue perpDot ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

perp dot product (cross product for 2D vectors).

The "perp dot product" for a and b vectors in the plane is a modification of the two-dimensional dot product in which a is replaced by the perpendicular vector rotated 90° to the left defined by Hill (1994), http://mathworld.wolfram.com/PerpDotProduct.html.

It reminds a lot to the 3D cross product, as its result is equal to the z-value of the cross product of a and b extended to 3D space by setting their z-value to 0: Vector3D<T> c = cross(Vector3D<T>(a.x, a.y, 0), Vector3D<T>(b.x, b.y, 0)). We know of this that c.x and c.y are both zero, and that c.z equals the perp dot product between a and b.

Definition at line 429 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
bool operator== ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

Definition at line 439 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
bool operator!= ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

Definition at line 449 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator+ ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

componentwise addition

Definition at line 460 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator- ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

componentwise subtraction

Definition at line 473 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator* ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

Componentwise multiplication.

Definition at line 486 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator/ ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

Componentwise division.

Definition at line 499 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator+ ( const Vector2D< T > &  a,
typename Vector2D< T >::TParam  b 
) [related]

add b to all components of a.

Definition at line 512 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator- ( const Vector2D< T > &  a,
typename Vector2D< T >::TParam  b 
) [related]

subtract b of all components of a.

Definition at line 525 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator* ( const Vector2D< T > &  a,
typename Vector2D< T >::TParam  b 
) [related]

muliply all components of a by b

Definition at line 538 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator/ ( const Vector2D< T > &  a,
typename Vector2D< T >::TParam  b 
) [related]

divide all components of a by b

Definition at line 551 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator+ ( typename Vector2D< T >::TParam  a,
const Vector2D< T > &  b 
) [related]

add a to all components of b

Definition at line 564 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator- ( typename Vector2D< T >::TParam  a,
const Vector2D< T > &  b 
) [related]

subtract a of all components of b

Definition at line 577 of file vector_2d.inl.

template<typename T >
Vector2D< T > operator* ( typename Vector2D< T >::TParam  a,
const Vector2D< T > &  b 
) [related]

multiply all components of b with a

Definition at line 590 of file vector_2d.inl.

template<typename T >
Vector2D< T > pointwiseMin ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

return a vector with, for each coordinate, the minimum value of a and b

Definition at line 603 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > pointwiseMax ( const Vector2D< T > &  a,
const Vector2D< T > &  b 
) [related]

return a vector with, for each coordinate, the maximum value of a and b

Definition at line 614 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
Vector2D< T > lerp ( const Vector2D< T > &  a,
const Vector2D< T > &  b,
typename Vector2D< T >::TParam  t 
) [related]

interpolate linearly between two vectors: a + t * (b - a)

Definition at line 625 of file vector_2d.inl.

template<typename T , typename Char , typename Traits >
std::basic_ostream< Char, Traits > & operator<< ( std::basic_ostream< Char, Traits > &  stream,
const Vector2D< T > &  b 
) [related]

template<typename T , typename Char , typename Traits >
std::basic_istream< Char, Traits > & operator>> ( std::basic_istream< Char, Traits > &  stream,
Vector2D< T > &  b 
) [related]

Definition at line 652 of file vector_2d.inl.

References lass::prim::Vector2D< T >::x, and lass::prim::Vector2D< T >::y.

template<typename T >
io::XmlOStream & operator<< ( io::XmlOStream stream,
const Vector2D< T > &  b 
) [related]

Definition at line 691 of file vector_2d.inl.

References LASS_ENFORCE_STREAM.


Field Documentation

template<typename T >
TValue lass::prim::Vector2D< T >::x

template<typename T >
TValue lass::prim::Vector2D< T >::y


The documentation for this struct was generated from the following files:

Generated on Mon Nov 10 14:22:14 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo