LOOS  v2.3.2
loos::Coord< T > Class Template Reference

Basic 3-D coordinates class. More...

#include <Coord.hpp>

Inheritance diagram for loos::Coord< T >:

Public Types

typedef T element_type
 

Public Member Functions

 Coord (const T ax, const T ay, const T az)
 
 Coord (const Coord< T > &o)
 
 Coord (const T x)
 
void x (const T ax)
 
void y (const T ay)
 
void z (const T az)
 
const T & x (void) const
 
const T & y (void) const
 
const T & z (void) const
 
T & x (void)
 
T & y (void)
 
T & z (void)
 
T & operator[] (const unsigned int i) throw (std::out_of_range)
 Retrieve an element from the Coord with range-checking.
 
const T & operator[] (const unsigned int i) const throw (std::out_of_range)
 Retrieve an element from a const Coord with range-checking.
 
void set (const T x, const T y, const T z)
 Short-cut to set the cartesian coordinates...
 
const Coord< T > & operator= (const Coord< T > &c)
 
Coord< T > & operator/= (const T rhs)
 Division by a constant.
 
Coord< T > operator/ (const T rhs) const
 
Coord< T > & operator+= (const T rhs)
 
Coord< T > operator+ (const T rhs) const
 
Coord< T > & operator+= (const Coord< T > &rhs)
 Handle addition.
 
Coord< T > operator+ (const Coord< T > &rhs) const
 
Coord< T > & operator-= (const Coord< T > &rhs)
 Subtraction.
 
Coord< T > operator- (const Coord< T > &rhs) const
 
Coord< T > & operator-= (const T rhs)
 
Coord< T > operator- (const T rhs) const
 
Coord< T > operator- ()
 Unary negation.
 
Coord< T > & operator*= (const T rhs)
 Multiplication by a constant.
 
Coord< T > operator* (const T rhs) const
 
dot (const Coord< T > &rhs) const
 Dot product.
 
operator* (const Coord< T >rhs) const
 
Coord< T > cross (const Coord< T > &rhs) const
 Cross-product. Returns a new Coord<T>
 
Coord< T > & operator^= (const Coord< T > &rhs)
 Mutating cross-product (note precedence issues)
 
Coord< T > operator^ (const Coord< T > &rhs) const
 Cross-product (note precedence issues)
 
Coord< T > & operator%= (const Coord< T > &rhs)
 Modulo of each component of the Coord with a constant.
 
Coord< T > operator% (const Coord< T > &rhs) const
 
void reimage (const Coord< T > &box)
 Handle coordinates with periodic boundary conditions.
 
double length2 (void) const
 Length of the Coord (as a vector) squared.
 
double length (void) const
 Length of the coordinate (as a vector)
 
double distance2 (const Coord< T > &o) const
 Distance squared between two coordinates.
 
double distance2 (const Coord< T > &o, const Coord< T > &box) const
 
double distance (const Coord< T > &o) const
 Distance between two coordinates.
 
double distance (const Coord< T > &o, const Coord< T > &box) const
 
void random (void)
 Generate a random vector on a unit sphere. More...
 
void zero (void)
 Zero out the coordinates (while keeping it homogenous)
 
bool operator== (const Coord< T > &rhs) const
 Compute equality based on norm(u-v) < epsilon.
 
bool operator!= (const Coord< T > &rhs) const
 Compute inequality based on ! ==.
 

Friends

std::ostream & operator<< (std::ostream &os, const Coord< T > &o)
 Output the coordinate in pseudo-XML.
 
std::istream & operator>> (std::istream &is, Coord< T > &i) throw (std::runtime_error)
 
Coord< T > operator+ (const T lhs, const Coord< T > &rhs)
 Handle the case of T + Coord<T>
 
Coord< T > operator- (const T lhs, const Coord< T > &rhs)
 Handle the case of T - Coord<T>
 
Coord< T > operator* (const Matrix44< T > &, const Coord< T > &)
 For matrix-vector multiply. More...
 
Coord< T > operator* (const T lhs, const Coord< T > &rhs)
 Handle T * Coord<T>
 
Coord< T > operator/ (const T lhs, const Coord< T > &rhs)
 T / Coord<T> case... This may not actually be a good idea?
 

Detailed Description

template<class T>
class loos::Coord< T >

Basic 3-D coordinates class.

Coordinates are stored internally as homogenous coordinates in an array of T. There is some awkward support for making coordinates in higher-dimensions, but caveat programmer...

Warnings:

  • The modulus operator assumes that T can be converted to double and back since it does this internally to use fmod().
  • The distance() and length() methods assume that T can be converted into a double (and return a double as the result).

Notes:

  • The size of the stored coords is determined by the CoordIndex enum. Places where The size is effectively hard-coded are in the constructor, the individual accessors, and in the cross-product. Internally, the coords are homogenous, being of size n+1 where the n+1th element is always 1...
  • Performance will probably suffer until you set the optimization level high enough to do some loop-unrolling.
  • The +, -, and * operation are symmetric with respect to T, i.e. 1 + v and v + 1 are the same
  • The precedence for the cross-product operator ^ is low, so be careful
  • The * operator has dual use... If either side is a T, then that value will be multiplied across all elements of the coord. If it is a Coord<T>, then the dot- product will be computed. What's a little confusion amongst friends???

Definition at line 36 of file Coord.hpp.

Member Function Documentation

template<class T>
double loos::Coord< T >::distance ( const Coord< T > &  o,
const Coord< T > &  box 
) const
inline

Distance between two coordinates considering periodic boundary conditions

Definition at line 449 of file Coord.hpp.

template<class T>
double loos::Coord< T >::distance2 ( const Coord< T > &  o,
const Coord< T > &  box 
) const
inline

Distance squared between two coordinates considering periodic boundary conditions

Definition at line 436 of file Coord.hpp.

template<class T>
void loos::Coord< T >::random ( void  )
inline

Generate a random vector on a unit sphere.

Note: this method uses a singleton random number generator set up by LOOS, but doesn't set the initial seed. Instead, the calling program needs to do that, either by calling randomSeedRNG() (see utils_random.cpp), which seeds off the time, or by generating the seed another way.

Definition at line 461 of file Coord.hpp.

Friends And Related Function Documentation

template<class T>
Coord<T> operator* ( const Matrix44< T > &  M,
const Coord< T > &  v 
)
friend

For matrix-vector multiply.

Matrix-vector multiply This has to be a friend outside the class for GCC to be happy...

Definition at line 244 of file Matrix44.hpp.


The documentation for this class was generated from the following file: