Public Member Functions | Public Attributes | Friends

Coord Class Reference

Class for storing host positions. More...

#include <Coord.h>

List of all members.

Public Member Functions

 Coord (double _x=0, double _y=0)
 Coord (const Coord &pos)
 Coord (const Coord *pos)
std::string info () const
const Coordoperator+= (const Coord &a)
const Coordoperator= (const Coord &a)
const Coordoperator-= (const Coord &a)
double distance (const Coord &a) const
double sqrdist (const Coord &a) const

Public Attributes

double x
 x and y coordinates of the position
double y

Friends

Coord operator+ (const Coord &a, const Coord &b)
Coord operator- (const Coord &a, const Coord &b)
Coord operator* (const Coord &a, double f)
Coord operator/ (const Coord &a, double f)
bool operator== (const Coord &a, const Coord &b)
bool operator!= (const Coord &a, const Coord &b)

Detailed Description

Class for storing host positions.

Class for a double-tuple storing a position / two-dimensional vector. Some comparison and basic arithmetic operators on Coord structures are implemented.

Author:
Christian Frank

Definition at line 38 of file Coord.h.


Constructor & Destructor Documentation

Coord::Coord ( double  _x = 0,
double  _y = 0 
) [inline]

Initializes coordinates.

Definition at line 45 of file Coord.h.

: x(_x), y(_y) {};

Coord::Coord ( const Coord pos  )  [inline]

Initializes coordinates.

Definition at line 49 of file Coord.h.

                          {
        x=pos.x;
        y=pos.y;
  }

Coord::Coord ( const Coord pos  )  [inline]

Initializes coordinates.

Definition at line 55 of file Coord.h.

                          {
        x=pos->x;
        y=pos->y;
  }


Member Function Documentation

double Coord::distance ( const Coord a  )  const [inline]

Returns the distance to const Coord& a

Definition at line 127 of file Coord.h.

                                        {
        return sqrt(sqrdist(a));
  }

std::string Coord::info (  )  const [inline]

Definition at line 60 of file Coord.h.

                         {
        std::stringstream os;
        os << "(" << x << "," << y << ")";
        return os.str();
  }

const Coord& Coord::operator+= ( const Coord a  )  [inline]

Adds coordinate vector b to a.

Definition at line 87 of file Coord.h.

                                          {
        x+=a.x;
        y+=a.y;
        return *this;
  }

const Coord& Coord::operator-= ( const Coord a  )  [inline]

Subtracts coordinate vector b from a.

Definition at line 101 of file Coord.h.

                                          {
        x-=a.x;
        y-=a.y;
        return *this;
  }

const Coord& Coord::operator= ( const Coord a  )  [inline]

Assigns a this.

Definition at line 94 of file Coord.h.

                                         {
        x=a.x;
        y=a.y;
        return *this;
  }

double Coord::sqrdist ( const Coord a  )  const [inline]

Returns distance^2 to Coord a (omits square root).

Definition at line 134 of file Coord.h.

                                       {
        double dx=x-a.x;
        double dy=y-a.y;
        return dx*dx + dy*dy;
  }


Friends And Related Function Documentation

bool operator!= ( const Coord a,
const Coord b 
) [friend]

Tests whether two coordinate vectors are not equal. Negation of the operator==.

Definition at line 120 of file Coord.h.

                                                         {
        return !(a==b);
  }

Coord operator* ( const Coord a,
double  f 
) [friend]

Multiplies a coordinate vector by a real number.

Definition at line 77 of file Coord.h.

                                                   {
        return Coord(a.x*f, a.y*f);
  }

Coord operator+ ( const Coord a,
const Coord b 
) [friend]

Adds two coordinate vectors.

Definition at line 67 of file Coord.h.

                                                         {
        return Coord(a.x+b.x, a.y+b.y);
  }

Coord operator- ( const Coord a,
const Coord b 
) [friend]

Subtracts two coordinate vectors.

Definition at line 72 of file Coord.h.

                                                         {
        return Coord(a.x-b.x, a.y-b.y);
  }

Coord operator/ ( const Coord a,
double  f 
) [friend]

Divides a coordinate vector by a real number.

Definition at line 82 of file Coord.h.

                                                   {
        return Coord(a.x/f, a.y/f);
  }

bool operator== ( const Coord a,
const Coord b 
) [friend]

Tests whether two coordinate vectors are equal. Because coordinates are of type double, this is done through the FWMath::close function.

Definition at line 112 of file Coord.h.

                                                         {
        return FWMath::close(a.x,b.x) && FWMath::close(a.y,b.y);
  }


Member Data Documentation

double Coord::x

x and y coordinates of the position

Definition at line 42 of file Coord.h.

Referenced by Coord(), operator+=(), operator-=(), operator<<(), operator=(), and sqrdist().

double Coord::y

Definition at line 42 of file Coord.h.

Referenced by Coord(), operator+=(), operator-=(), operator<<(), operator=(), and sqrdist().


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