Public Member Functions | Static Public Attributes | Protected Attributes | Friends

Coord Class Reference
[baseUtils - utilities for base MiXiMutils - utility classes]

Class for storing host positions. More...

#include <Coord.h>

List of all members.

Public Member Functions

 Coord (bool use2D=false)
 Initialize a 3d (default) or 2d coordinate with the origin.
 Coord (double x, double y, double z)
 Initializes 3D coordinate.
 Coord (double x, double y)
 Initializes 2D coordinate.
 Coord (const Coord &pos)
 Initializes coordinate from other coordinate.
 Coord (const Coord *pos)
 Initializes coordinate from other coordinate.
std::string info () const
 Returns a string with the value of the coordinate.
Coord operator*= (double f)
 Multiplies this coordinate vector by a real number.
Coord operator/= (double f)
 Divides this coordinate vector by a real number.
Coord operator+= (const Coord &a)
 Adds coordinate vector 'a' to this.
Coord operator= (const Coord &a)
 Assigns a this.
Coord operator-= (const Coord &a)
 Subtracts coordinate vector 'a' from this.
double distance (const Coord &a) const
 Returns the distance to Coord 'a'.
double sqrdist (const Coord &a) const
 Returns distance^2 to Coord 'a' (omits square root).
double sqrTorusDist (const Coord &b, const Coord &playgroundSize) const
 Returns the squared distance on a torus of this to Coord 'b' (omits square root).
double squareLength () const
 Returns the square of the length of this Coords position vector.
double length () const
 Returns the length of this Coords position vector.
double getX () const
 Getter for the x coordinate.
void setX (double x)
 Setter for the x coordinate.
double getY () const
 Getter for the y coordinate.
void setY (double y)
 Setter for the y coordinate.
double getZ () const
 Getter for the z coordinate.
void setZ (double z)
 Setter for the z coordinate.
bool isValid () const
 Returns true if this coordinate is valid.
bool is2D () const
 Returns true if this coordinate is two-dimensional.
bool is3D () const
 Returns true if this coordinate is three-dimensional.
bool isInRectangle (const Coord &upperLeftCorner, const Coord &lowerRightCorner) const
 Checks if this coordinate is inside a specified rectangle.
bool isInBoundary (const Coord &lowerBound, const Coord &upperBound) const
 Checks if this coordinate is inside the passed boundary of [lowerBound, upperBound).
Coord min (const Coord &a)
 Returns the minimal coordinates.
Coord max (const Coord &a)
 Returns the maximal coordinates.

Static Public Attributes

static const double UNDEFINED = 0.0
 Constant representing an undefined value.

Protected Attributes

bool use2DFlag
 Member to store whether this coordinate is 2D or 3D.
x, y and z coordinate of the position.

double x
double y
double z

Friends

Coord operator+ (const Coord &a, const Coord &b)
 Adds two coordinate vectors.
Coord operator- (const Coord &a, const Coord &b)
 Subtracts two coordinate vectors.
Coord operator* (const Coord &a, double f)
 Multiplies a coordinate vector by a real number.
Coord operator/ (const Coord &a, double f)
 Divides a coordinate vector by a real number.
bool operator== (const Coord &a, const Coord &b)
 Tests whether two coordinate vectors are equal.
bool operator!= (const Coord &a, const Coord &b)
 Tests whether two coordinate vectors are not equal.
bool operator> (const Coord &a, const Coord &b)
 Tests whether this coordinate vector is strictly larger than another coordinate vector (component-wise).
bool operator< (const Coord &a, const Coord &b)
 Tests whether this coordinate vector is strictly smaller than another coordinate vector (component-wise).

Detailed Description

Class for storing host positions.

Class for a storing a position / vector. Some comparison and basic arithmetic operators on Coord structures are implemented.

Note: This class can work 2-dimensional or 3-dimensional. The dimension of a Coord can only be set at construction time. The only way to change it afterwards is by assigning Coord a new value with the overloaded "="-operator. So every time you create a new Coord variable you should make sure to use the proper constructor. Since most time you won't have own constructors in Omnet-modules every member variable of type Coord becomes 3D at the beginning (because the default-constructor creates a 3D-Coord). In this case you should give it the right dimension by assigning them a new value in the "initialize()"-Method by a line like this:

coordMember = Coord(x, y); <- 2D coordMember = Coord(x, y, z); <- 3D

See the constructors for more details.

Most methods of Coord does not check for dimension compatibility. For example the overloaded "+"-operator does not check if both Coord are of the same dimension. The user has to assure the proper use of this methods!

Author:
Christian Frank

Definition at line 61 of file Coord.h.


Member Function Documentation

double Coord::distance ( const Coord a  )  const [inline]
double Coord::getZ (  )  const [inline]
bool Coord::isInBoundary ( const Coord lowerBound,
const Coord upperBound 
) const [inline]

Checks if this coordinate is inside the passed boundary of [lowerBound, upperBound).

Does not check for dimension compatibility!

Parameters:
lowerBound The lower boundary.
upperBound the upper boundary.

Definition at line 368 of file Coord.h.

References use2DFlag.

Referenced by PostureTransition::findAreaType(), and MoBANCoordinator::isInsideWorld().

                                                                            {
    return  x >= lowerBound.x && x < upperBound.x &&
        y >= lowerBound.y && y < upperBound.y &&
        (use2DFlag || (z >= lowerBound.z && z < upperBound.z));
  }

bool Coord::isInRectangle ( const Coord upperLeftCorner,
const Coord lowerRightCorner 
) const [inline]

Checks if this coordinate is inside a specified rectangle.

Does not check for dimension compatibility!

Parameters:
upperLeftCorner The upper left corner of the rectangle.
lowerRightCorner the lower right corner of the rectangle.

Definition at line 353 of file Coord.h.

References use2DFlag.

Referenced by BaseMobility::initialize().

                                                                                          {
        return  x >= upperLeftCorner.x && x <= lowerRightCorner.x &&
                y >= upperLeftCorner.y && y <= lowerRightCorner.y &&
                (use2DFlag || (z >= upperLeftCorner.z && z <= lowerRightCorner.z));
    }

bool Coord::isValid (  )  const [inline]

Returns true if this coordinate is valid.

Valid means this Coord is 3-dimensional or this Coord is 2-Dimensional and the z-value is equal to Coord::UNDEFINED.

Definition at line 331 of file Coord.h.

References UNDEFINED, and use2DFlag.

                         {
        return (z == UNDEFINED) || !use2DFlag;
    }

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

Adds coordinate vector 'a' to this.

Does not check for dimension compatibility!

Definition at line 184 of file Coord.h.

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

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

Subtracts coordinate vector 'a' from this.

Does not check for dimension compatibility!

Definition at line 209 of file Coord.h.

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

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

Assigns a this.

This operator can change the dimension of the coordinate.

Definition at line 196 of file Coord.h.

References use2DFlag.

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

void Coord::setZ ( double  z  )  [inline]

Setter for the z coordinate.

This method does not check its dimension! So never call it if you are working with two-dimensional coordinates! A 2D-Coord looses its functionality if the z-value becomes another value than Coord::UNDEFINED

Definition at line 322 of file Coord.h.

Referenced by BaseMobility::checkIfOutside(), BaseMobility::goToBorder(), BaseMobility::initialize(), BaseConnectionManager::initialize(), MoBANLocal::insideWorld(), max(), min(), MoBANCoordinator::readConfigurationFile(), BaseMobility::reflectCoordinate(), BaseMobility::reflectIfOutside(), MoBANCoordinator::selectDestination(), MoBANLocal::setTargetPosition(), and BaseMobility::wrapIfOutside().

{this->z = z;}

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

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

Does not check for dimension compatibility!

Definition at line 254 of file Coord.h.

References squareLength().

Referenced by SimplePathlossModel::calcPathloss(), SimplePathlossModel::filterSignal(), BreakpointPathlossModel::filterSignal(), and BaseConnectionManager::updateNicConnections().

                                           {
        Coord dist=*this-a;
        return dist.squareLength();
    }

double Coord::sqrTorusDist ( const Coord b,
const Coord playgroundSize 
) const

Returns the squared distance on a torus of this to Coord 'b' (omits square root).

Does not check for dimension compatibility!

Definition at line 8 of file Coord.cc.

Referenced by SimplePathlossModel::calcPathloss(), SimplePathlossModel::filterSignal(), BreakpointPathlossModel::filterSignal(), and BaseConnectionManager::updateNicConnections().

                                                                            {

    double xDist = fabs(x - b.x);
    double yDist = fabs(y - b.y);
    double zDist = fabs(z - b.z);

    
    /*
     * on a torus the end and the begin of the axes are connected so you
     * get a circle. On a circle the distance between two points can't be greater
     * than half of the circumference.
     * If the normal distance between two points on one axis is bigger than
     * half of the playground there must be a "shorter way" over the playground
     * border on this axis
     */
    if(xDist * 2.0 > playgroundSize.x)
    {
        xDist = playgroundSize.x - xDist;
    }
    //same for y- and z-coordinate
    if(yDist * 2.0 > playgroundSize.y)
    {
      yDist = playgroundSize.y - yDist;
    }
    if(zDist * 2.0 > playgroundSize.z)
    {
      zDist = playgroundSize.z - zDist;
    }
    return xDist * xDist + yDist * yDist + zDist * zDist;
}


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==.

Does not check for dimension compatibility!

Definition at line 235 of file Coord.h.

                                                           {
        return !(a==b);
    }

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

Adds two coordinate vectors.

Does not check for dimension compatibility!

Definition at line 128 of file Coord.h.

                                                           {
        Coord tmp = a;
        tmp += b;
        return tmp;
    }

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

Subtracts two coordinate vectors.

Does not check for dimension compatibility!

Definition at line 139 of file Coord.h.

                                                           {
        Coord tmp = a;
        tmp -= b;
        return tmp;
    }

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.

Does not check for dimension compatibility!

Definition at line 224 of file Coord.h.

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


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