home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / dial_cde.hqx / rectutils.c < prev    next >
Text File  |  1988-09-06  |  716b  |  49 lines

  1. /*
  2.  * rectangle utilities
  3.  */
  4.  
  5. #include "rectutils.h"
  6.  
  7. /*
  8.  * make a rectangle from the two points.  If the coordinates would
  9.  * produce an invalid rectangle, switch them so that the rect is
  10.  * always valid.
  11.  */
  12. void
  13. RUMakeRect(p1,p2,r)
  14. Point p1,p2;
  15. Rect *r;
  16. {
  17.     if (p1.h < p2.h) {
  18.         r->left = p1.h;
  19.         r->right = p2.h;
  20.     } else {
  21.         r->left = p2.h;
  22.         r->right = p1.h;
  23.     }
  24.     if (p1.v < p2.v) {
  25.         r->top = p1.v;
  26.         r->bottom = p2.v;
  27.     } else {
  28.         r->top = p2.v;
  29.         r->bottom = p1.v;
  30.     }
  31. }
  32.  
  33. /*
  34.  * like makerect except takes a width/height value in the second
  35.  * point rather than an actual point.
  36.  */
  37. void
  38. RUMakeDeltaRect(p1,d,r)
  39. Point p1,d;
  40. Rect *r;
  41. {
  42. Point p2;
  43.  
  44.     p2.h = p1.h + d.h;
  45.     p2.v = p1.v + d.v;
  46.     RUMakeRect(p1,p2,r);
  47. }
  48.  
  49.