<Source Index | <PPA-L top page

xy.h


/////////////////////////////////////////////
//
//         Definition of XY class
//
//    Copyright 2001 by TAKENAKA, A.

#if !defined(___XY_H)
#define ___XY_H

#include <cmath>

//////////////////////////
//
//  XY coordinate class

class XY
{
  public:

    double X;
    double Y;

    XY(void) : X(0), Y(0) {}
    XY(const double x, const double y) : X(x), Y(y) {}

    double distance (const XY& p) const {
        double dx = X - p.X;
        double dy = Y - p.Y;
        return  sqrt(dx * dx + dy * dy);
    }

  //  '==' and '<' operators are needed to handle XY objects with STL.

    bool operator == (const XY &p) const {return (X == p.X && Y == p.Y);}
    bool operator <  (const XY &p) const {return ((X < p.X) || ((X == p.X) && (Y < p.Y)));}
};

#endif