home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IRECT.INL < prev    next >
Text File  |  1993-10-22  |  12KB  |  386 lines

  1. #ifndef _IRECT_INL_
  2. #define _IRECT_INL_ 0
  3. /*******************************************************************************
  4. * FILE NAME: irect.inl                                                         *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the definition of the inline functions for the          *
  8. *   class(es) declared in irect.hpp.                                           *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or               *
  15. *   disclosure                                                                 *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #ifndef _IRECT_
  20.   #undef  _IRECT_INL_
  21.   #define _IRECT_INL_ 1
  22.   extern "C"
  23.     {
  24.     #include <os2.h>
  25.     }
  26.   #include <irect.hpp>
  27. #endif
  28.  
  29. #if _IRECT_INL_
  30.   #define inline
  31. #endif
  32.  
  33. /*------------------------------- Constructors -------------------------------*/
  34. inline IRectangle :: IRectangle ( )
  35.   : origin( 0, 0 ), corner( 0, 0 )
  36.   {
  37.   }
  38. inline IRectangle :: IRectangle ( const IPoint &point1,
  39.                                   const IPoint &point2 )
  40.   : origin( point1.minimum( point2 ) ), corner( point1.maximum( point2 ) )
  41.   {
  42.   }
  43. inline IRectangle :: IRectangle ( const IPoint &aPoint,
  44.                                   const ISize  &aSize )
  45.   : origin( aPoint.minimum( aPoint+aSize ) ),
  46.     corner( aPoint.maximum( aPoint+aSize ) )
  47.   {
  48.   }
  49. inline IRectangle :: IRectangle ( Coord x1,
  50.                                   Coord y1,
  51.                                   Coord x2,
  52.                                   Coord y2 )
  53.    : origin( IPair( x1, y1 ).minimum( IPair( x2, y2 ) ) ),
  54.      corner( IPair( x1, y1 ).maximum( IPair( x2, y2 ) ) )
  55.   {
  56.   }
  57. #if defined(OS2DEF_INCLUDED)
  58. inline IRectangle :: IRectangle ( const RECTL &aRECTL)
  59.   : origin( IPair( aRECTL.xLeft, aRECTL.yBottom ).
  60.       minimum( IPair( aRECTL.xRight, aRECTL.yTop ) ) ),
  61.     corner( IPair( aRECTL.xLeft, aRECTL.yBottom ).
  62.       maximum( IPair( aRECTL.xRight, aRECTL.yTop  ) ) )
  63.   {
  64.   }
  65. #endif
  66. inline IRectangle :: IRectangle ( Coord width,
  67.                                   Coord height )
  68.   : origin( IPair( width, height ).minimum( IPair() ) ),
  69.     corner( IPair( width, height ).maximum( IPair() ) )
  70.   {
  71.   }
  72. inline IRectangle :: IRectangle ( const IPair &aPair )
  73.   : origin( aPair.minimum( IPair() ) ),
  74.     corner( aPair.maximum( IPair() ) )
  75.   {
  76.   }
  77. /*-------------------------------- Accessors ---------------------------------*/
  78. inline IRectangle::Coord IRectangle :: bottom ( ) const
  79.   {
  80.   return origin.y();
  81.   }
  82. inline IRectangle::Coord IRectangle :: height ( ) const
  83.   {
  84.   return corner.y() - origin.y();
  85.   }
  86. inline IRectangle::Coord IRectangle :: left ( ) const
  87.   {
  88.   return origin.x();
  89.   }
  90. inline IRectangle::Coord IRectangle :: right ( ) const
  91.   {
  92.   return corner.x();
  93.   }
  94. inline IRectangle::Coord IRectangle :: top ( ) const
  95.   {
  96.   return corner.y();
  97.   }
  98. inline IRectangle::Coord IRectangle :: width ( ) const
  99.   {
  100.   return corner.x() - origin.x();
  101.   }
  102. inline IPoint IRectangle :: bottomCenter ( ) const
  103.   {
  104.   return IPoint( ( right() + left() ) / 2,
  105.                  bottom() );
  106.   }
  107. inline IPoint IRectangle :: bottomLeft ( ) const
  108.   {
  109.   return origin;
  110.   }
  111. inline IPoint IRectangle :: bottomRight ( ) const
  112.   {
  113.   return IPoint( right(),
  114.                  bottom() );
  115.   }
  116. inline IPoint IRectangle :: center ( ) const
  117.   {
  118.   return ( origin + corner ) / 2;
  119.   }
  120. inline IPoint IRectangle :: leftCenter ( ) const
  121.   {
  122.   return IPoint( left(),
  123.                  ( top() + bottom() ) / 2 );
  124.   }
  125. inline IPoint IRectangle :: rightCenter ( ) const
  126.   {
  127.   return IPoint( right(),
  128.                  ( top() + bottom() ) / 2 );
  129.   }
  130. inline IPoint IRectangle :: topCenter ( ) const
  131.   {
  132.   return IPoint( ( right() + left() ) / 2,
  133.                  top() );
  134.   }
  135. inline IPoint IRectangle :: topLeft ( ) const
  136.   {
  137.   return IPoint( left(),
  138.                  top() );
  139.   }
  140. inline IPoint IRectangle :: topRight ( ) const
  141.   {
  142.   return corner;
  143.   }
  144. inline ISize IRectangle :: size ( ) const
  145.   {
  146.   return corner - origin;
  147.   }
  148. inline IRectangle::Coord IRectangle :: area ( ) const
  149.   {
  150.   return height() * width();
  151.   }
  152. #ifdef OS2_INCLUDED
  153. inline RECTL IRectangle :: asRECTL ( ) const
  154.   {
  155.   RECTL rectl = { left(), bottom(), right(), top() };
  156.   return rectl;
  157.   }
  158. #endif
  159. /*--------------------------- Comparison Operators ---------------------------*/
  160. inline IBase::Boolean IRectangle :: operator == ( const IRectangle &aRect ) const
  161.   {
  162.   return ( origin == aRect.origin
  163.            &&
  164.            corner == aRect.corner );
  165.   }
  166. inline IBase::Boolean IRectangle :: operator != ( const IRectangle& aRect ) const
  167.   {
  168.   return !( *this == aRect );
  169.   }
  170. /*------------------------------ Implementation ------------------------------*/
  171. inline IRectangle &IRectangle :: validate ( )
  172.   {
  173.   if ( corner < origin )
  174.     origin = corner = IPoint( 0, 0 );
  175.   return *this;
  176.   }
  177. /*-------------------------- Manipulation Operators --------------------------*/
  178. inline IRectangle &IRectangle :: operator &= ( const IRectangle &aRect )
  179.   {
  180.   origin = origin.maximum( aRect.origin );
  181.   corner = corner.minimum( aRect.corner );
  182.   return validate();
  183.   }
  184. inline IRectangle IRectangle :: operator &  ( const IRectangle &aRect ) const
  185.   {
  186.   IRectangle result( *this );
  187.   return ( result &= aRect );
  188.   }
  189. inline IRectangle &IRectangle :: operator |= ( const IRectangle &aRect )
  190.   {
  191.   origin = origin.minimum( aRect.origin ),
  192.   corner = corner.maximum( aRect.corner );
  193.   return *this;
  194.   }
  195. inline IRectangle IRectangle :: operator |  ( const IRectangle &aRect ) const
  196.   {
  197.   IRectangle result( *this );
  198.   return result |= aRect;
  199.   }
  200. /*------------------------------- Manipulation -------------------------------*/
  201. inline IRectangle &IRectangle :: moveBy ( const IPair &aPair )
  202.   {
  203.   origin += aPair;
  204.   corner += aPair;
  205.   return *this;
  206.   }
  207. inline IRectangle &IRectangle :: centerAt ( const IPoint &aPoint )
  208.   {
  209.   return moveBy( aPoint - center() );
  210.   }
  211. inline IRectangle IRectangle :: centeredAt ( const IPoint &aPoint ) const
  212.   {
  213.   IRectangle result( *this );
  214.   return result.centerAt( aPoint );
  215.   }
  216. inline IRectangle &IRectangle :: expandBy ( const IPair &aPair )
  217.   {
  218.   origin -= aPair;
  219.   corner += aPair;
  220.   return validate();
  221.   }
  222. inline IRectangle &IRectangle :: expandBy ( Coord coord )
  223.   {
  224.   origin -= coord,
  225.   corner += coord;
  226.   return validate();
  227.   }
  228. inline IRectangle IRectangle :: expandedBy ( const IPair &aPair ) const
  229.   {
  230.   IRectangle result( *this );
  231.   return result.expandBy( aPair );
  232.   }
  233. inline IRectangle IRectangle :: expandedBy ( Coord coord ) const
  234.   {
  235.   IRectangle result( *this );
  236.   return result.expandBy( coord );
  237.   }
  238. inline IRectangle IRectangle :: movedBy ( const IPair &aPair ) const
  239.   {
  240.   IRectangle result( *this );
  241.   return result.moveBy( aPair );
  242.   }
  243. inline IRectangle &IRectangle :: moveTo ( const IPoint &aPoint )
  244.   {
  245.   return moveBy( aPoint - origin );
  246.   }
  247. inline IRectangle IRectangle :: movedTo ( const IPoint &aPoint ) const
  248.   {
  249.   IRectangle result( *this );
  250.   return result.moveTo( aPoint );
  251.   }
  252. inline IRectangle &IRectangle :: scaleBy ( const IPair &aPair )
  253.   {
  254.   origin *= aPair;
  255.   corner *= aPair;
  256.   return *this;
  257.   }
  258. inline IRectangle &IRectangle :: scaleBy ( Coord coord )
  259.   {
  260.   origin *= coord,
  261.   corner *= coord;
  262.   return *this;
  263.   }
  264. inline IRectangle &IRectangle :: scaleBy ( double amt )
  265.   {
  266.   origin *= amt;
  267.   corner *= amt;
  268.   return *this;
  269.   }
  270. inline IRectangle &IRectangle :: scaleBy ( double xamt, double yamt )
  271.   {
  272.   origin.scaleBy( xamt, yamt );
  273.   corner.scaleBy( xamt, yamt );
  274.   return *this;
  275.   }
  276. inline IRectangle IRectangle :: scaledBy ( const IPair &aPair ) const
  277.   {
  278.   IRectangle result( *this );
  279.   return result.scaleBy( aPair );
  280.   }
  281. inline IRectangle IRectangle :: scaledBy ( Coord coord ) const
  282.   {
  283.   IRectangle result( *this );
  284.   return result.scaleBy( coord );
  285.   }
  286. inline IRectangle IRectangle :: scaledBy ( double amt ) const
  287.   {
  288.   IRectangle result( *this );
  289.   return result.scaleBy( amt );
  290.   }
  291. inline IRectangle IRectangle :: scaledBy ( double xamt, double yamt ) const
  292.   {
  293.   IRectangle result( *this );
  294.   return result.scaleBy( xamt, yamt );
  295.   }
  296. inline IRectangle &IRectangle :: shrinkBy ( const IPair &aPair )
  297.   {
  298.   return expandBy( -aPair );
  299.   }
  300. inline IRectangle &IRectangle :: shrinkBy ( Coord coord )
  301.   {
  302.   return expandBy( -coord );
  303.   }
  304. inline IRectangle IRectangle :: shrunkBy ( const IPair &aPair ) const
  305.   {
  306.   return expandedBy( -aPair );
  307.   }
  308. inline IRectangle IRectangle :: shrunkBy ( Coord coord ) const
  309.   {
  310.   return expandedBy( -coord );
  311.   }
  312. inline IRectangle &IRectangle :: sizeTo ( const IPair &aPair )
  313.   {
  314.   corner = origin + aPair;
  315.   return *this;
  316.   }
  317. inline IRectangle IRectangle :: sizedTo ( const IPair &aPair ) const
  318.   {
  319.   IRectangle result( *this );
  320.   return result.sizeTo( aPair );
  321.   }
  322. inline IRectangle &IRectangle :: sizeBy ( Coord factor )
  323.   {
  324.   IPoint save( bottomLeft() );
  325.   moveTo( IPoint(0,0) ).scaleBy( factor ).moveTo( save );
  326.   return *this;
  327.   }
  328. inline IRectangle &IRectangle :: sizeBy ( const IPair &aPair )
  329.   {
  330.   IPoint save( bottomLeft() );
  331.   moveTo( IPoint(0,0) ).scaleBy( aPair ).moveTo( save );
  332.   return *this;
  333.   }
  334. inline IRectangle &IRectangle :: sizeBy ( double factor )
  335.   {
  336.   IPoint save( bottomLeft() );
  337.   moveTo( IPoint(0,0) ).scaleBy( factor ).moveTo( save );
  338.   return *this;
  339.   }
  340. inline IRectangle &IRectangle :: sizeBy ( double xfact, double yfact )
  341.   {
  342.   IPoint save( bottomLeft() );
  343.   moveTo( IPoint(0,0) ).scaleBy( xfact, yfact ).moveTo( save );
  344.   return *this;
  345.   }
  346. inline IRectangle IRectangle :: sizedBy ( Coord factor ) const
  347.   {
  348.   IRectangle result( *this );
  349.   return result.sizeBy( factor );
  350.   }
  351. inline IRectangle IRectangle :: sizedBy ( const IPair &aPair ) const
  352.   {
  353.   IRectangle result( *this );
  354.   return result.sizeBy( aPair );
  355.   }
  356. inline IRectangle IRectangle :: sizedBy ( double factor ) const
  357.   {
  358.   IRectangle result( *this );
  359.   return result.sizeBy( factor );
  360.   }
  361. inline IRectangle IRectangle :: sizedBy ( double xfact, double yfact ) const
  362.   {
  363.   IRectangle result( *this );
  364.   return result.sizeBy( xfact, yfact );
  365.   }
  366. /*--------------------------------- Testing ----------------------------------*/
  367. inline IBase::Boolean IRectangle :: contains ( const IRectangle &aRect ) const
  368.   {
  369.   return ( origin <= aRect.origin
  370.            &&
  371.            aRect.corner <= corner );
  372.   }
  373. inline IBase::Boolean IRectangle :: contains ( const IPoint &aPoint ) const
  374.   {
  375.   return ( aPoint >= origin
  376.            &&
  377.            aPoint < corner );
  378.   }
  379. inline IBase::Boolean IRectangle :: intersects ( const IRectangle &aRect ) const
  380.   {
  381.   return ( origin < aRect.corner
  382.            &&
  383.            aRect.origin < corner );
  384.   }
  385. #endif /* _IRECT_INL_ */
  386.