home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0636.ZIP / CCE_0636 / GEMLIB / GMLIBS30.ZOO / aesrc.c < prev    next >
C/C++ Source or Header  |  1991-09-05  |  2KB  |  126 lines

  1. /*
  2.  *    Aes rectangle utils
  3.  *        rc_copy        copy grects
  4.  *         rc_equal    compare two grects
  5.  *              rc_intersect    check if two grects intersect, ret intersec
  6.  *              rc_union        union of two grects
  7.  *        grect_to_aray    convert GRECT to a vdi pxy style coordinate
  8.  *                array
  9.  *
  10.  *        ++jrb    bammi@cadence.com
  11.  *        modified: mj -- ntomczak@vm.ucs.ualberta.ca
  12.  */
  13. #include <macros.h>
  14. #include <gemfast.h>
  15.  
  16. #ifdef __DEF_ALL__
  17.  
  18. #define L_rc_copy
  19. #define L_rc_equal
  20. /***
  21. #define L_max
  22. #define L_min
  23. ***/
  24. #define L_rc_inter
  25. #define L_grect_to
  26.  
  27. #endif /* __DEF_ALL__ */
  28.  
  29.  
  30. #ifdef L_rc_copy
  31.  
  32. /* rc_copy    copy grects
  33.  * always returns success
  34.  */
  35. int rc_copy(GRECT *src, GRECT *dst)
  36. {
  37.     *dst = *src;
  38.     return 1;
  39. }
  40. #endif /* L_rc_copy */
  41.  
  42. #ifdef L_rc_equal
  43.  
  44. /* rc_equal    compare two rectangles
  45.  * returns 0 is not same
  46.  */
  47. rc_equal(GRECT *p1, GRECT *p2)
  48. {
  49.     return ((p1->g_x == p2->g_x) &&
  50.         (p1->g_y == p2->g_y) &&
  51.         (p1->g_w == p2->g_w) &&
  52.         (p1->g_h == p2->g_h));
  53. }
  54. #endif /* L_rc_equal */
  55.  
  56.  
  57. #if 0
  58. #ifdef L_max
  59. static int max(int x, int y)
  60. {
  61.     return (x > y)? x : y;
  62. }
  63. #endif /* L_max */
  64.  
  65. #ifdef L_min
  66.  
  67. static int min(int x, int y)
  68. {
  69.     return (x > y)? y : x;
  70. }
  71. #endif /* L_min */
  72. #endif
  73.  
  74. #ifdef L_rc_inter
  75.  
  76. /*
  77.  * rc_intersect       check if two rects intersect
  78.  * returns 0 if they do not intersect,
  79.  * otherwise returns 1 and rect2 is set to common area
  80.  */
  81. int rc_intersect(GRECT *r1, GRECT *r2)
  82. {
  83.       int     tx, ty, tw, th, ret;
  84.     
  85.       tx = max (r2->g_x, r1->g_x);
  86.       tw = min (r2->g_x + r2->g_w, r1->g_x + r1->g_w) - tx;
  87.       if (ret = (0 < tw)) {
  88.           ty = max (r2->g_y, r1->g_y);
  89.           th = min (r2->g_y + r2->g_h, r1->g_y + r1->g_h) - ty;
  90.           if (ret = (0 < th)) {
  91.               r2->g_x = tx;
  92.               r2->g_y = ty;
  93.               r2->g_w = tw;
  94.               r2->g_h = th;
  95.           }
  96.       }
  97.       return (ret);
  98. }
  99. #endif /* L_rc_inter */
  100.  
  101. #ifdef L_grect_to
  102.  
  103. /*
  104.  * convert a GRECT to a pxy array
  105.  * returns &pxy_array[0]
  106.  */
  107. int *grect_to_array(GRECT *area, int *array)
  108. {
  109.     int *ip = array;
  110.  
  111.     *ip = area->g_x;
  112.     ip[2] = *ip;
  113.     ip++;
  114.     *ip = area->g_y;
  115.     ip[2] = *ip;
  116.     ip++;
  117.     *ip++ += area->g_w - 1;
  118.     *ip   += area->g_h - 1;
  119.     return (array);
  120. }
  121. #endif /* L_grect_to */
  122.  
  123. /* rc_union todo */
  124.  
  125. /* -eof- */
  126.