// TwoSpacePoint.h #ifndef TwoSpacePoint_H #define TwoSpacePoint_H // Describes a point in 2-space. The default Space point is at the origin. // Derived classes can be used to set values in cartesian or cylindrical // coordinates. Point is set in the constructor and cannot be changed. // The methods simply return different coordinates. // // Transformations (translations, rotations, etc) are carried out by // external functions which return new TwoSpacePoints. #include #ifdef DEFECT_NO_BOOL #include #endif class TwoSpacePoint { protected: // data double _x; double _y; double _xy; double _phi; public: // static methods // Return if two doubles are close enough to be considered equal. // This is used to compare components for operator==. static bool equal(double x1, double x2); public: // methods // Default constructor. // Sets point to be the origin. TwoSpacePoint( ); // Destructor. virtual ~TwoSpacePoint( ); // Cartesian x. double x( ) const { return _x; }; // Cartesian y. double y( ) const { return _y; }; // Cylindrical r. double rxy( ) const { return _xy; }; // Cylindrical phi. double phi( ) const { return _phi; }; // cos(phi) double cos_phi( ) const; // sin(phi) double sin_phi( ) const; }; std::ostream& operator<<(std::ostream & stream, const TwoSpacePoint& spt); //********************************************************************** class CartesianTwoPoint : public TwoSpacePoint { public: // Constructor. CartesianTwoPoint(double x, double y); }; //********************************************************************** class CylindricalTwoPoint : public TwoSpacePoint { public: // Constructor. CylindricalTwoPoint(double r, double phi); }; //********************************************************************** // Free functions. //********************************************************************** // Equality. bool operator==(const TwoSpacePoint& lhs, const TwoSpacePoint& rhs); //********************************************************************** // Inequality. bool operator!=(const TwoSpacePoint& lhs, const TwoSpacePoint& rhs); //********************************************************************** // Return the distance between two space points. double distance(const TwoSpacePoint spt1, const TwoSpacePoint spt2); //********************************************************************** #endif