// CSE 303, Spring 2009, Marty Stepp // Implementation of a Point class. #include #include "Point.h" // Constructs a new Point at the given x/y coordinates. // If no coordinates are specified, uses (0, 0). Point::Point(int x = 0, int y = 0) { setLocation(x, y); } // Returns the direct 2D distance between this point and the given point. // The method is set as 'const' to indicate that calling it doesn't modify // the Point's state. // The method takes a reference to a Point as a parameter so that the // client's parameter is not copied every time it is passed. double Point::distance(Point& p) const { int dx = this->x - p.getX(); int dy = this->y - p.getY(); return sqrt(dx*dx + dy*dy); } // Returns the x coordinate of this Point. int Point::getX() const { return x; } // Returns the y coordinate of this Point. int Point::getY() const { return y; } // Sets the x/y coordinates of this Point to the given values. void Point::setLocation(int x, int y) { this->x = x; this->y = y; } // Shifts this point's location by the given amount. void Point::translate(int dx, int dy) { setLocation(x + dx, y + dy); }