openvrml::vec2d Class Reference

#include <openvrml/basetypes.h>

List of all members.


Detailed Description

Two-component double-precision vector.


Public Member Functions

 vec2d () throw ()
 Construct.
 vec2d (const double(&vec)[2]) throw ()
 Construct from an array.
 vec2d (double x, double y) throw ()
 Construct from x and y components.
vec2doperator *= (double scalar) throw ()
 Multiply by a scalar.
vec2doperator/= (double scalar) throw ()
 Divide by a scalar.
vec2doperator+= (const vec2d &vec) throw ()
 Add a vector.
vec2doperator-= (const vec2d &vec) throw ()
 Subtract a vector.
const vec2d operator- () const throw ()
 Negate.
const double & operator[] (size_t index) const throw ()
 Index-based component access.
double x () const throw ()
 Get the x component.
void x (double value) throw ()
 Set the x component.
double y () const throw ()
 Get the y component.
void y (double value) throw ()
 Set the y component.
double dot (const vec2d &vec) const throw ()
 Dot product.
double length () const throw ()
 Geometric length.
const vec2d normalize () const throw ()
 Normalize.

Private Attributes

double vec [2]
 Vector components.

Friends

std::istream & operator>> (std::istream &in, vec2d &v)
 Stream input.

Related Functions

(Note that these are not member functions.)

const openvrml::vec2d operator * (const vec2d &lhs, const double rhs) throw()
 Multiply a vector by a scalar.
const openvrml::vec2d operator * (const double lhs, const vec2d &rhs) throw()
 Multiply a vector by a scalar.
const openvrml::vec2d operator/ (const vec2d &lhs, const double rhs) throw()
 Divide a vector by a scalar.
const openvrml::vec2d operator+ (const vec2d &lhs, const vec2d &rhs) throw()
 Add two vectors.
const openvrml::vec2d operator- (const vec2d &lhs, const vec2d &rhs) throw()
 Subtract two vectors.
bool operator== (const vec2d &lhs, const vec2d &rhs) throw()
 Compare for equality.
bool operator!= (const vec2d &lhs, const vec2d &rhs) throw()
 Compare for inequality.
std::ostream & operator<< (std::ostream &out, const vec2d &v)
 Stream output.

Constructor & Destructor Documentation

openvrml::vec2d::vec2d (  )  throw ()

Construct.

openvrml::vec2d::vec2d ( const double &  vec[2]  )  throw () [explicit]

Construct from an array.

Precondition:
Elements of vec are valid numeric values (i.e., not NaN).
Parameters:
[in] vec an array comprising the vector components.

openvrml::vec2d::vec2d ( double  x,
double  y 
) throw ()

Construct from x and y components.

Precondition:
x and y are valid numeric values (i.e., not NaN).
Parameters:
[in] x x component.
[in] y y component.


Member Function Documentation

openvrml::vec2d & openvrml::vec2d::operator *= ( double  scalar  )  throw ()

Multiply by a scalar.

Parameters:
[in] scalar factor by which to multiply.
Returns:
a reference to the object.

openvrml::vec2d & openvrml::vec2d::operator/= ( double  scalar  )  throw ()

Divide by a scalar.

Precondition:
scalar is nonzero.
Parameters:
[in] scalar divisor.
Returns:
a reference to the object.

openvrml::vec2d & openvrml::vec2d::operator+= ( const vec2d vec  )  throw ()

Add a vector.

Parameters:
[in] vec the vector to add.
Returns:
a reference to the object.

openvrml::vec2d & openvrml::vec2d::operator-= ( const vec2d vec  )  throw ()

Subtract a vector.

Parameters:
[in] vec the vector to subtract.
Returns:
a reference to the object.

const openvrml::vec2d openvrml::vec2d::operator- (  )  const throw ()

Negate.

Returns:
the additive inverse of the vector.

const double & openvrml::vec2d::operator[] ( size_t  index  )  const throw () [inline]

Index-based component access.

Parameters:
[in] index 0 corresponds to the x component; 1 corresponds to the y component.
Returns:
a const reference to the component corresponding to index.
Precondition:
index is less than 2.

double openvrml::vec2d::x (  )  const throw () [inline]

Get the x component.

Returns:
the x component.

void openvrml::vec2d::x ( double  value  )  throw () [inline]

Set the x component.

Precondition:
value is a valid numeric value (i.e., not NaN).
Parameters:
[in] value new x component value.

double openvrml::vec2d::y (  )  const throw () [inline]

Get the y component.

Returns:
the y component.

void openvrml::vec2d::y ( double  value  )  throw () [inline]

Set the y component.

Precondition:
value is a valid numeric value (i.e., not NaN).
Parameters:
[in] value new y component value.

double openvrml::vec2d::dot ( const vec2d vec  )  const throw ()

Dot product.

Parameters:
[in] vec 
Returns:
the dot product of the vector and vec.

double openvrml::vec2d::length (  )  const throw ()

Geometric length.

Returns:
the length of the vector.

const openvrml::vec2d openvrml::vec2d::normalize (  )  const throw ()

Normalize.

Returns:
the vector normalized.


Friends And Related Function Documentation

std::istream& operator>> ( std::istream &  in,
vec2d v 
) [friend]

Stream input.

Consistent with the VRML97 convention, commas (“,”) in the input are treated as whitespace.

Parameters:
[in,out] in input stream.
[out] v a vec2d.
Returns:
in.

const openvrml::vec2d operator * ( const vec2d lhs,
const double  rhs 
) throw() [related]

Multiply a vector by a scalar.

Parameters:
[in] lhs left-hand operand (the vector).
[in] rhs right-hand operand (the scalar).
Returns:
the result vector.

const openvrml::vec2d operator * ( const double  lhs,
const vec2d rhs 
) throw() [related]

Multiply a vector by a scalar.

Parameters:
[in] lhs left-hand operand (the scalar).
[in] rhs right-hand operand (the vector).
Returns:
the result vector.

const openvrml::vec2d operator/ ( const vec2d lhs,
const double  rhs 
) throw() [related]

Divide a vector by a scalar.

Precondition:
rhs is nonzero.
Parameters:
[in] lhs left-hand operand (the vector).
[in] rhs right-hand operand (the scalar).
Returns:
the result vector.

const openvrml::vec2d operator+ ( const vec2d lhs,
const vec2d rhs 
) throw() [related]

Add two vectors.

Parameters:
[in] lhs left-hand operand.
[in] rhs right-hand operand.
Returns:
the result vector.

const openvrml::vec2d operator- ( const vec2d lhs,
const vec2d rhs 
) throw() [related]

Subtract two vectors.

Parameters:
[in] lhs left-hand operand.
[in] rhs right-hand operand.
Returns:
the result vector.

bool operator== ( const vec2d lhs,
const vec2d rhs 
) throw() [related]

Compare for equality.

Parameters:
[in] lhs left-hand operand.
[in] rhs right-hand operand.
Returns:
true if lhs and rhs have the same value; false otherwise.

bool operator!= ( const vec2d lhs,
const vec2d rhs 
) throw() [related]

Compare for inequality.

Parameters:
[in] lhs left-hand operand.
[in] rhs right-hand operand.
Returns:
true if lhs and rhs dot not have the same value; false otherwise.

std::ostream & operator<< ( std::ostream &  out,
const vec2d v 
) [related]

Stream output.

Parameters:
[in,out] out output stream.
[in] v a 2-component vector.
Returns:
out.


Member Data Documentation

double openvrml::vec2d::vec[2] [private]

Vector components.

For internal use only.