// // XYPoint.cc // Implementation of the 2D Point class // #include #include #include "XYpoint.h" using namespace std; // local counter used to produce globally unique point ID's static int counter = 0; // Constructor with no elements XYPoint::XYPoint(void) : _x(0), _y(0) { _num = counter++; } // Constructor with initial x and y values XYPoint::XYPoint(double x, double y) : _x(x), _y(y) { _num = counter++; } double XYPoint::distance(const XYPoint *other) const { double dx = x() - other->x(); double dy = y() - other->y(); return sqrt(dx * dx + dy * dy); } bool XYPoint::isLeftOf(const XYPoint *other) const { return (_x < other->_x || (_x == other->_x && _num < other->_num)); } bool XYPoint::isBelow(const XYPoint *other) const { return (_y < other->_y || (_y == other->_y && _num < other->_num)); } ostream &operator<< (ostream &os, const XYPoint &point) { os << '(' << point.x() << ',' << point.y() << ')'; return os; } ostream &operator<< (ostream &os, const XYPoint *point) { if (point == NULL) { os << "NULL"; } else { os << *point; } return os; }