#include "Point.h" /* * ========================================================================== * Point Implementation * ========================================================================== */ // Initialise static members unsigned int Point::mInstanceCount=0; // Default constructor: just initialise to zero. Point::Point() : mX (0.0), mY (0.0) { mInstanceCount++; } // Set position of point on construction. Point::Point(double pX, double pY) : mX (pX), mY (pY) { mInstanceCount++; } // Copy constructor Point::Point(const Point& pSrc) : mX (pSrc.mX), mY (pSrc.mY) { mInstanceCount++; } // Destructor Point::~Point() { mInstanceCount--; } bool Point::operator==(const Point& pSrc) { return (mX == pSrc.mX && mY == pSrc.mY); } bool Point::operator==(const double pVal) { return (distance() == pVal); } bool Point::operator!=(const Point& pSrc) { return !operator==(pSrc); } bool Point::operator!=(const double pVal) { return !operator==(pVal); } bool Point::operator<(const Point& pSrc) { return operator<(pSrc.distance()); } bool Point::operator<=(const Point& pSrc) { return (operator<(pSrc) || operator==(pSrc.distance())); } bool Point::operator>(const Point& pSrc) { return operator>(pSrc.distance()); } bool Point::operator>=(const Point& pSrc) { return (operator>(pSrc) || operator==(pSrc.distance())); } bool Point::operator<(const double pVal) { return (distance() < pVal); } bool Point::operator<=(const double pVal) { return (operator<(pVal) || operator==(pVal)); } bool Point::operator>(const double pVal) { return (distance() > pVal); } bool Point::operator>=(const double pVal) { return (operator>(pVal) || operator==(pVal)); } Point& Point::operator=(const Point& pSrc) { if (this == &pSrc) { cout << "Ignoring self-assignment" << endl; return *this; } mX = pSrc.mX; mY = pSrc.mY; return *this; } Point Point::operator+(const Point& pSrc) { return Point(mX + pSrc.mX, mY + pSrc.mY); } Point Point::operator-(const Point& pSrc) { return Point(mX - pSrc.mX, mY - pSrc.mY); } double Point::getX() { return mX; } double Point::getY() { return mY; } void Point::setX(double pVal) { mX = pVal; } void Point::setY(double pVal) { mY = pVal; } double Point::distance() const { return sqrt(mX*mX + mY*mY); } void Point::printInstances() { cout << "There are " << mInstanceCount << " points." << endl; }