//------------------------------------------ // Filename: Point.C // Author : DL Frey // Date : 2/21/03 // Section : 1234 // Project : CMSC 202, Spring 03, Project 2 // SSN : xxx - xx - xxxx // Description // This file implements the Point class // that encapsulates the x- and y-coordinates // of a point in the cooridinate plane // // See Point.H for complete method documenation // // Basic distance functions are also provide //------------------------------------------- #include // for abs #include // for sqrt #include "Point.H" using namespace std; // constructor Point::Point (int x, int y) { m_XCoordinate = x; m_YCoordinate = y; } // accessor for X coordinate int Point::GetX( void ) const { return m_XCoordinate; } // mutator for X coordinate void Point::SetX (int x ) { m_XCoordinate = x; } // accessor for Y coordinate int Point::GetY ( void ) const { return m_YCoordinate; } // mutator for Y coordinate void Point::SetY ( int y ) { m_YCoordinate = y; } // ---------------------------- // Vertical distance // returns delta-Y //----------------------------- int VerticalDistance (const Point& point1, const Point& point2) { return (abs (point1.GetY() - point2.GetY())); } // ---------------------------- // Horizontal distance // returns delta-X //----------------------------- int HorizontalDistance (const Point& point1, const Point& point2) { return abs(point1.GetX() - point2.GetX()); } // ------------------------------------- // Distance // returns straightline distance from // point1 to point2 using standard calculation // derived from Pythagorean theorem //-------------------------------------- double Distance (const Point& point1, const Point& point2) { int deltaY = VerticalDistance (point1, point2); int deltaX = HorizontalDistance (point1, point2); return (sqrt(static_cast( deltaY * deltaY + deltaX * deltaX))); }