home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / OOD / PRIM.CP$ / PRIM
Encoding:
Text File  |  1991-10-22  |  1.7 KB  |  81 lines

  1. /**********************************************************************
  2.  
  3.    FILE: PRIM.CPP
  4.  
  5. **********************************************************************/
  6.  
  7. #include "prim.h"
  8.  
  9.  
  10. // OffsetRect by a Point (interpeted as a vector)
  11.  
  12. Rect Rect::operator+( Point pt ) const
  13. {
  14.     return Rect(left + pt.x, top + pt.y,
  15.                 right + pt.x, bottom + pt.y);
  16. }
  17.  
  18. Rect Rect::operator+=( Point pt )
  19. {
  20.     left += pt.x;
  21.     right += pt.x;
  22.     top += pt.y;
  23.     bottom += pt.y;
  24.     return self;
  25. }
  26.  
  27. Rect Rect::operator-( Point pt ) const
  28. {
  29.     return Rect(left - pt.x, top - pt.y,
  30.                 right - pt.x, bottom - pt.y);
  31. }
  32.  
  33. Rect Rect::operator-=(Point pt)
  34. {
  35.     left -= pt.x;
  36.     right -= pt.x;
  37.     top -= pt.y;
  38.     bottom -= pt.y;
  39.     return self;
  40. }
  41.  
  42.  
  43. // intersection of two rectangles
  44.  
  45. Rect Rect::operator&( const Rect& other ) const
  46. {
  47.     return Rect( max( left, other.left ),
  48.                  max( top, other.top ),
  49.                  min( right, other.right ),
  50.                  min( bottom, other.bottom ) );
  51. }
  52.  
  53. Rect Rect::operator&=( const Rect& other )
  54. {
  55.     left = max( left, other.left );
  56.     top = max( top, other.top );
  57.     right = min( right, other.right );
  58.     bottom = min( bottom, other.bottom );
  59.     return self;
  60. }
  61.  
  62. // union of two rectangles
  63.  
  64. Rect Rect::operator|( const Rect& other ) const
  65. {
  66.     return Rect( min( left, other.left ),
  67.                  min( top, other.top ),
  68.                  max( right, other.right ),
  69.                  max( bottom, other.bottom ) );
  70. }
  71.  
  72. Rect Rect::operator|=( const Rect& other )
  73. {
  74.     left = min( left, other.left );
  75.     top = min( top, other.top );
  76.     right = max( right, other.right );
  77.     bottom = max( bottom, other.bottom );
  78.     return self;
  79. }
  80.  
  81.