index page
0001: /////////////////////////////////////////////
0002: //
0003: //         Definition of XY class
0004: //
0005: //    Copyright 2001 by TAKENAKA, A.
0006: 
0007: #if !defined(___XY_H)
0008: #define ___XY_H
0009: 
0010: #include <cmath>
0011: 
0012: //////////////////////////
0013: //
0014: //  XY coordinate class
0015: 
0016: class XY
0017: {
0018:   public:
0019: 
0020:     double X;
0021:     double Y;
0022: 
0023:     XY(void) : X(0), Y(0) {}
0024:     XY(const double x, const double y) : X(x), Y(y) {}
0025: 
0026:     double distance (const XY& p) const {
0027:         double dx = X - p.X;
0028:         double dy = Y - p.Y;
0029:         return  sqrt(dx * dx + dy * dy);
0030:     }
0031: 
0032:   //  '==' and '<' operators are needed to handle XY objects with STL.
0033: 
0034:     bool operator == (const XY &p) const {return (X == p.X && Y == p.Y);}
0035:     bool operator <  (const XY &p) const {return ((X < p.X) || ((X == p.X) && (Y < p.Y)));}
0036: };
0037: 
0038: #endif

Back to Top of this Page