CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
Public Types | Public Member Functions | Public Attributes

claw::math::coordinate_2d< T > Class Template Reference

Coordinates in a two dimensional space. More...

#include <coordinate_2d.hpp>

Inheritance diagram for claw::math::coordinate_2d< T >:
claw::math::vector_2d< T >

List of all members.

Public Types

typedef T value_type
 The type of the values we store.
typedef coordinate_2d< value_typeself_type
 The type of the current class.

Public Member Functions

 coordinate_2d ()
 Constructor.
template<typename U >
 coordinate_2d (const coordinate_2d< U > &that)
 Copy constructor.
 coordinate_2d (const value_type &_x, const value_type &_y)
 Constructor with initialization.
template<typename U >
coordinate_2d< U > cast_value_type_to () const
 Get a copy of the rectangle by converting its members to a given type.
void set (const value_type &_x, const value_type &_y)
 Sets new values to the coordinate.
value_type distance (const self_type &p) const
 Get the distance separing two coordinates.
bool operator== (const self_type &vect) const
 Equality operator.
bool operator!= (const self_type &vect) const
 Difference operator.
self_type operator+ (const self_type &vect) const
 Addition.
self_type operator- (const self_type &vect) const
 Subtraction.
self_typeoperator+= (const self_type &vect)
 Add a coordinate.
self_typeoperator-= (const self_type &vect)
 Subtract a coordinate.
self_type operator* (const value_type &v) const
 Multiplication.
self_type operator/ (const value_type &v) const
 Division.
self_typeoperator*= (const value_type &v)
 Multiply the coordinates.
self_typeoperator/= (const value_type &v)
 Divide the coordinates.

Public Attributes

value_type x
 X-coordinate.
value_type y
 Y-coordinate.

Detailed Description

template<typename T>
class claw::math::coordinate_2d< T >

Coordinates in a two dimensional space.

Author:
Julien Jorge

Definition at line 42 of file coordinate_2d.hpp.


Member Typedef Documentation

template<typename T>
typedef coordinate_2d<value_type> claw::math::coordinate_2d< T >::self_type

The type of the current class.

Reimplemented in claw::math::vector_2d< T >, and claw::math::vector_2d< value_type >.

Definition at line 49 of file coordinate_2d.hpp.

template<typename T>
typedef T claw::math::coordinate_2d< T >::value_type

The type of the values we store.

Reimplemented in claw::math::vector_2d< T >, and claw::math::vector_2d< value_type >.

Definition at line 46 of file coordinate_2d.hpp.


Constructor & Destructor Documentation

template<typename T >
claw::math::coordinate_2d< T >::coordinate_2d ( )

Constructor.

Definition at line 37 of file coordinate_2d.tpp.

{

} // coordinate_2d::coordinate_2d() [constructor]
template<typename T >
template<typename U >
claw::math::coordinate_2d< T >::coordinate_2d ( const coordinate_2d< U > &  that)

Copy constructor.

Definition at line 48 of file coordinate_2d.tpp.

  : x(that.x), y(that.y)
{

} // coordinate_2d::coordinate_2d() [copy constructor]
template<typename T >
claw::math::coordinate_2d< T >::coordinate_2d ( const value_type _x,
const value_type _y 
)

Constructor with initialization.

Parameters:
_xx value.
_yy Value.

Definition at line 62 of file coordinate_2d.tpp.

  : x(_x), y(_y)
{

} // coordinate_2d::coordinate_2d() [constructor whit values]

Member Function Documentation

template<class T >
template<typename U >
claw::math::coordinate_2d< U > claw::math::coordinate_2d< T >::cast_value_type_to ( ) const

Get a copy of the rectangle by converting its members to a given type.

Consider the following code:

coordinate_2d<float> a;

...

coordinate_2d<int> b(a);

The copy constructor will be called, and your compiler should print some warnings in your console. These warnings have a meaning, so we don't wan't to make them disapear by adding explicit type conversion inside the coordinate_2d class nor adding a cast operator that will be used silently by the compiler.

If you really want to convert the type, this method will explicitly cast the member variables.

Definition at line 92 of file coordinate_2d.tpp.

{
  return claw::math::coordinate_2d<U>( (U)x, (U)y );
} // coordinate_2d::cast_value_type_to()
template<typename T >
claw::math::coordinate_2d< T >::value_type claw::math::coordinate_2d< T >::distance ( const self_type p) const

Get the distance separing two coordinates.

Parameters:
pThe second coordinate

Definition at line 118 of file coordinate_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  return (value_type)sqrt( (p.x - x)*(p.x - x) + (p.y - y)*(p.y - y) );
} // coordinate_2d::distance()
template<typename T >
bool claw::math::coordinate_2d< T >::operator!= ( const self_type that) const

Difference operator.

Parameters:
thatCoordinate to compare to.

Definition at line 140 of file coordinate_2d.tpp.

{
  return !(*this == that);
} // coordinate_2d::operator!=()
template<typename T >
claw::math::coordinate_2d< T > claw::math::coordinate_2d< T >::operator* ( const value_type v) const

Multiplication.

Parameters:
vFactor.

Definition at line 206 of file coordinate_2d.tpp.

{
  return self_type( x * v, y * v );
} // coordinate_2d::operator*()
template<typename T >
claw::math::coordinate_2d< T > & claw::math::coordinate_2d< T >::operator*= ( const value_type v)

Multiply the coordinates.

Parameters:
vFactor.

Definition at line 230 of file coordinate_2d.tpp.

{
  x *= v;
  y *= v;

  return *this;
} // coordinate_2d::operator*=()
template<typename T >
claw::math::coordinate_2d< T > claw::math::coordinate_2d< T >::operator+ ( const self_type that) const

Addition.

Parameters:
thatCoordinate to add.

Definition at line 152 of file coordinate_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  return self_type( x + that.x, y + that.y );
} // coordinate_2d::operator+()
template<typename T >
claw::math::coordinate_2d< T > & claw::math::coordinate_2d< T >::operator+= ( const self_type that)

Add a coordinate.

Parameters:
thatCoordinate to add.

Definition at line 176 of file coordinate_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  x += that.x;
  y += that.y;

  return *this;
} // coordinate_2d::operator+=()
template<typename T >
claw::math::coordinate_2d< T > claw::math::coordinate_2d< T >::operator- ( const self_type that) const

Subtraction.

Parameters:
thatCoordinate to subtract.

Definition at line 164 of file coordinate_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  return self_type( x - that.x, y - that.y );
} // coordinate_2d::operator-()
template<typename T >
claw::math::coordinate_2d< T > & claw::math::coordinate_2d< T >::operator-= ( const self_type that)

Subtract a coordinate.

Parameters:
thatCoordinate to subtract.

Definition at line 191 of file coordinate_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  x -= that.x;
  y -= that.y;

  return *this;
} // coordinate_2d::operator-=()
template<typename T >
claw::math::coordinate_2d< T > claw::math::coordinate_2d< T >::operator/ ( const value_type v) const

Division.

Parameters:
vDivider.

Definition at line 218 of file coordinate_2d.tpp.

{
  return self_type( x / v, y / v );
} // coordinate_2d::operator/()
template<typename T >
claw::math::coordinate_2d< T > & claw::math::coordinate_2d< T >::operator/= ( const value_type v)

Divide the coordinates.

Parameters:
vDivider.

Definition at line 245 of file coordinate_2d.tpp.

{
  x /= v;
  y /= v;

  return *this;
} // coordinate_2d::operator/=()
template<typename T >
bool claw::math::coordinate_2d< T >::operator== ( const self_type that) const

Equality operator.

Parameters:
thatCoordinate to compare to.

Definition at line 129 of file coordinate_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  return (x == that.x) && (y == that.y);
} // coordinate_2d::operator==()
template<typename T >
void claw::math::coordinate_2d< T >::set ( const value_type _x,
const value_type _y 
)

Sets new values to the coordinate.

Parameters:
_xNew x value.
_yNew y Value.

Definition at line 105 of file coordinate_2d.tpp.

{
  x = _x;
  y = _y; 
} // coordinate_2d::set()

Member Data Documentation

template<typename T>
value_type claw::math::coordinate_2d< T >::x
template<typename T>
value_type claw::math::coordinate_2d< T >::y

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