//Angle class -- copyright 2001, Information Disciplines, Inc. // This class supports operations on plane angles. #ifndef ANGLE #define ANGLE const Angle #include /* For trig functions */ class Angle{ double value; // normalized radians // For compatibility with the standard C-library and other software, range is // (-pi,pi] not [0,2pi), enforced by the following function: void normalize(); // Constructors // ------------ public: Angle(DOUBLE rad = 0.0) : value(rad) {normalize();} Angle(INT deg, INT min, INT sec=0); // The compiler will supply an acceptable copy constructor, destructor // and assignment operator. // Accessors // --------- double toDegrees() const {return 180.0 * (value / PI);} double toRadians() const {return value;} short degrees() const {return short(toDegrees());} short minutes() const; short seconds() const; // Operators follow the standard additive pattern // --------- #define Class Angle #include "Additive.hpp" #undef Class // Trigonometric functions (for notational consistency and to hide internal // ----------------------- representation. User can use other old functions // by extracting value with toRadians() accessor) double cos() const {return ::cos (value);} double sin() const {return ::sin (value);} double tan() const {return ::tan (value);} }; // *************** End of class definition // Non-member operators // -------------------- ostream& operator<< (ostream& ls, ANGLE rs); // WARNING: Floating point equality test is undependable inline bool operator==(ANGLE ls, ANGLE rs) {return ls.toRadians() == rs.toRadians();} // NOTE: Ordering is ambiguous and not transitive, due to normalization. inline bool operator< (ANGLE ls, ANGLE rs) {return ls.toRadians() < rs.toRadians();} // Inverse trigonometric functions (forward to C library versions) // ------------------------------- inline Angle arccos(DOUBLE x) {return ::acos(x);} inline Angle arcsin(DOUBLE x) {return ::asin(x);} inline Angle arctan(DOUBLE y, DOUBLE x = 1.0) {return ::atan2(y,x);} #endif