home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / H / utils / geo-decls.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  7.3 KB  |  202 lines

  1. /***********************************************************************
  2. **
  3. **    geo-decls.h
  4. **
  5. **    Declarations for various 2D constructs.
  6. **
  7. **    These routines do *not* use the float types from adt/.
  8. **
  9. **    XXX These routines were not written by a numerical analyst.
  10. **
  11. ** Identification:
  12. **    $Header: /private/postgres/src/lib/H/utils/RCS/geo-decls.h,v 1.11 1992/05/18 18:50:07 mer Exp $
  13. **
  14. ***********************************************************************/
  15.  
  16. #ifndef    GeoDeclsIncluded
  17. #define    GeoDeclsIncluded
  18.  
  19. #ifndef FmgrIncluded
  20. /*--------------------------------------------------------------------
  21.  *    Useful floating point utilities and constants.
  22.  *-------------------------------------------------------------------*/
  23.  
  24. #include <math.h>
  25. #include "tmp/c.h"
  26.  
  27. #define    EPSILON            1.0E-06
  28.  
  29. #define    FPzero(A)        (fabs(A) <= EPSILON)
  30. #define    FPeq(A,B)        (fabs((A) - (B)) <= EPSILON)
  31. #define    FPlt(A,B)        ((B) - (A) > EPSILON)
  32. #define    FPle(A,B)        ((A) - (B) <= EPSILON)
  33. #define    FPgt(A,B)        ((A) - (B) > EPSILON)
  34. #define    FPge(A,B)        ((B) - (A) <= EPSILON)
  35.  
  36. #define    HYPOT(A, B)        sqrt((A) * (A) + (B) * (B))
  37.  
  38. /*--------------------------------------------------------------------
  39.  *    Memory management.
  40.  *-------------------------------------------------------------------*/
  41.  
  42. #define    PALLOC(SIZE)        palloc(SIZE)
  43. #define    PFREE(P)        pfree((char *) (P))
  44. #define    PALLOCTYPE(TYPE)    (TYPE *) PALLOC(sizeof(TYPE))
  45.  
  46. /*--------------------------------------------------------------------
  47.  *    Handy things...
  48.  *-------------------------------------------------------------------*/
  49.  
  50. #ifdef sun
  51. extern char *sprintf();
  52. #endif sun
  53.  
  54. #endif !FmgrIncluded
  55.  
  56. /*---------------------------------------------------------------------
  57.  *    POINT    -    (x,y)
  58.  *-------------------------------------------------------------------*/
  59. typedef struct {
  60.     double    x, y;
  61. } POINT;
  62.  
  63.  
  64. /*---------------------------------------------------------------------
  65.  *    LSEG    -     A straight line, specified by endpoints.
  66.  *-------------------------------------------------------------------*/
  67. typedef    struct {
  68.     POINT    p[2];
  69.  
  70.     double    m;    /* precomputed to save time, not in tuple */
  71. } LSEG;
  72.  
  73.  
  74. /*---------------------------------------------------------------------
  75.  *    PATH    -     Specified by vertex points.
  76.  *-------------------------------------------------------------------*/
  77. typedef    struct {
  78.     long    length;
  79.     short    closed;    /* is this a closed polygon? */
  80.     long    npts;
  81.     POINT    p[1];    /* variable length array of POINTs */
  82. } PATH;
  83.  
  84.  
  85. /*---------------------------------------------------------------------
  86.  *    LINE    -    Specified by its general equation (Ax+By+C=0).
  87.  *            If there is a y-intercept, it is C, which
  88.  *             incidentally gives a freebie point on the line
  89.  *             (if B=0, then C is the x-intercept).
  90.  *            Slope m is precalculated to save time; if
  91.  *             the line is not vertical, m == A.
  92.  *-------------------------------------------------------------------*/
  93. typedef struct {
  94.     double    A, B, C;
  95.     double    m;
  96. } LINE;
  97.  
  98.  
  99. /*---------------------------------------------------------------------
  100.  *    BOX    -     Specified by two corner points, which are
  101.  *             sorted to save calculation time later.
  102.  *-------------------------------------------------------------------*/
  103. typedef struct {
  104.     double    xh, yh, xl, yl;        /* high and low coords */
  105. } BOX;
  106.  
  107. /*---------------------------------------------------------------------
  108.  *  POLYGON - Specified by an array of doubles defining the points, 
  109.  *              keeping the number of points and the bounding box for 
  110.  *              speed purposes.
  111.  *-------------------------------------------------------------------*/
  112. typedef struct {
  113.     long size;
  114.     long npts;
  115.     BOX boundbox;
  116.     char pts[1];
  117. } POLYGON;
  118.  
  119.  
  120. /* ----------------------
  121.  * function prototypes -- not called by function manager
  122.  * ----------------------
  123.  */
  124. double poly_max ARGS((double *coords , int ncoords ));
  125. double poly_min ARGS((double *coords , int ncoords ));
  126. BOX *box_fill ARGS((BOX *result , double x1 , double x2 , double y1 , double y2 ));
  127. BOX *box_construct ARGS((double x1 , double x2 , double y1 , double y2 ));
  128. BOX *box_copy ARGS((BOX *box ));
  129. double *box_area ARGS((BOX *box ));
  130. double *box_length ARGS((BOX *box ));
  131. double *box_height ARGS((BOX *box ));
  132. double *box_distance ARGS((BOX *box1 , BOX *box2 ));
  133. double box_ar ARGS((BOX *box ));
  134. double box_ln ARGS((BOX *box ));
  135. double box_ht ARGS((BOX *box ));
  136. double box_dt ARGS((BOX *box1 , BOX *box2 ));
  137. BOX *box_intersect ARGS((BOX *box1 , BOX *box2 ));
  138. LSEG *box_diagonal ARGS((BOX *box ));
  139. LINE *line_construct_pm ARGS((POINT *pt , double m ));
  140. LINE *line_construct_pp ARGS((POINT *pt1 , POINT *pt2 ));
  141. long line_intersect ARGS((LINE *l1 , LINE *l2 ));
  142. long line_parallel ARGS((LINE *l1 , LINE *l2 ));
  143. long line_perp ARGS((LINE *l1 , LINE *l2 ));
  144. long line_vertical ARGS((LINE *line ));
  145. long line_horizontal ARGS((LINE *line ));
  146. long line_eq ARGS((LINE *l1 , LINE *l2 ));
  147. double *line_distance ARGS((LINE *l1 , LINE *l2 ));
  148. POINT *line_interpt ARGS((LINE *l1 , LINE *l2 ));
  149. long path_n_lt ARGS((PATH *p1 , PATH *p2 ));
  150. long path_n_gt ARGS((PATH *p1 , PATH *p2 ));
  151. long path_n_eq ARGS((PATH *p1 , PATH *p2 ));
  152. long path_n_le ARGS((PATH *p1 , PATH *p2 ));
  153. long path_n_ge ARGS((PATH *p1 , PATH *p2 ));
  154. long path_inter ARGS((PATH *p1 , PATH *p2 ));
  155. double *path_length ARGS((PATH *path ));
  156. double path_ln ARGS((PATH *path ));
  157. POINT *point_construct ARGS((double x , double y ));
  158. POINT *point_copy ARGS((POINT *pt ));
  159. long point_vert ARGS((POINT *pt1 , POINT *pt2 ));
  160. long point_horiz ARGS((POINT *pt1 , POINT *pt2 ));
  161. double *point_distance ARGS((POINT *pt1 , POINT *pt2 ));
  162. double point_dt ARGS((POINT *pt1 , POINT *pt2 ));
  163. double *point_slope ARGS((POINT *pt1 , POINT *pt2 ));
  164. double point_sl ARGS((POINT *pt1 , POINT *pt2 ));
  165. LSEG *lseg_construct ARGS((POINT *pt1 , POINT *pt2 ));
  166. void statlseg_construct ARGS((LSEG *lseg , POINT *pt1 , POINT *pt2 ));
  167. long lseg_intersect ARGS((LSEG *l1 , LSEG *l2 ));
  168. long lseg_parallel ARGS((LSEG *l1 , LSEG *l2 ));
  169. long lseg_perp ARGS((LSEG *l1 , LSEG *l2 ));
  170. long lseg_vertical ARGS((LSEG *lseg ));
  171. long lseg_horizontal ARGS((LSEG *lseg ));
  172. long lseg_eq ARGS((LSEG *l1 , LSEG *l2 ));
  173. double *lseg_distance ARGS((LSEG *l1 , LSEG *l2 ));
  174. double lseg_dt ARGS((LSEG *l1 , LSEG *l2 ));
  175. POINT *lseg_interpt ARGS((LSEG *l1 , LSEG *l2 ));
  176. double *dist_pl ARGS((POINT *pt , LINE *line ));
  177. double *dist_ps ARGS((POINT *pt , LSEG *lseg ));
  178. double *dist_pb ARGS((POINT *pt , BOX *box ));
  179. double *dist_sl ARGS((LSEG *lseg , LINE *line ));
  180. double *dist_sb ARGS((LSEG *lseg , BOX *box ));
  181. double *dist_lb ARGS((LINE *line , BOX *box ));
  182. POINT *interpt_sl ARGS((LSEG *lseg , LINE *line ));
  183. POINT *close_pl ARGS((POINT *pt , LINE *line ));
  184. POINT *close_ps ARGS((POINT *pt , LSEG *lseg ));
  185. POINT *close_pb ARGS((POINT *pt , BOX *box ));
  186. POINT *close_sl ARGS((LSEG *lseg , LINE *line ));
  187. POINT *close_sb ARGS((LSEG *lseg , BOX *box ));
  188. POINT *close_lb ARGS((LINE *line , BOX *box ));
  189. long on_pl ARGS((POINT *pt , LINE *line ));
  190. long on_ps ARGS((POINT *pt , LSEG *lseg ));
  191. long on_pb ARGS((POINT *pt , BOX *box ));
  192. long on_ppath ARGS((POINT *pt , PATH *path ));
  193. long on_sl ARGS((LSEG *lseg , LINE *line ));
  194. long on_sb ARGS((LSEG *lseg , BOX *box ));
  195. long inter_sl ARGS((LSEG *lseg , LINE *line ));
  196. long inter_sb ARGS((LSEG *lseg , BOX *box ));
  197. long inter_lb ARGS((LINE *line , BOX *box ));
  198. void make_bound_box ARGS((POLYGON *poly ));
  199. long poly_pt_count ARGS((char *s , char delim ));
  200. void statlseg_construct ARGS((LSEG *lseg, POINT *pt1, POINT *pt2));
  201. #endif !GeoDeclsIncluded
  202.