/* Point.h 2-D point class Original code: JM, 12 Oct 97 */ #ifndef POINT_H #define POINT_H #define RAD(x) (x*3.1415926/180.0) #define DEG(x) (x*180.0/3.1415926) #ifndef M_PI #define M_PI 3.1415926 #endif typedef struct point *Point; Point ConsPoint( double x, double y ); /* Construct points from cartesian pair Pre-cond: none Post-cond: returns a valid point or NULL if no memory */ Point ConsPointRT( double r, double theta ); /* Construct points from polar representation pair Pre-cond: r >= 0 Post-cond: returns a valid point or NULL if no memory */ void DeletePoint( Point p ); /* Delete p and free resources Pre-cond: p != NULL */ Point CopyPoint( Point p ); /* Make a copy of point p Pre-cond: p != NULL Post-cond: returns copy of p or NULL if no memory */ void FreePoint( Point p ); /* Synonym for DeletePoint */ void SetPoint( Point p, double x, double y ); /* Set point p to (x,y) (enable re-use of structures, saves unnecessary Cons/Delete) Pre-cond: p != NULL Post-cond: p is set to (x,y) */ void SetPoint2( Point p, Point p1 ); /* Set a point .. enables re-use of the structure! Pre-cond: (p != NULL) && (p1 != NULL) Post-cond: p and p1 are identical */ double XCoord( Point p ); double YCoord( Point p ); double RPolar( Point p ); double TPolar( Point p ); /* Projectors Pre-cond: p != NULL */ double Dist( Point p1, Point p2 ); /* Returns distance between p1 and p2 Pre-cond: (p1 != NULL) && (p2 != NULL) */ void Displace( Point p, Point delta ); /* Displace p by delta: p := p+delta Pre-cond: (p != NULL) && (delta != NULL) Post-cond: p is displaced by delta */ double Direction( Point p1, Point p2 ); /* Return the direction from p1 to p2 in radians Pre-cond: (p1 != NULL) && (p2 != NULL) Post-cond: return value is in -PI,+PI */ double AngleBetween( Point p1, Point p2, Point p3 ); void PrintPoint( char *s, Point p ); #endif