home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / ipoint.inl < prev    next >
Encoding:
Text File  |  1996-02-22  |  9.0 KB  |  318 lines

  1. #ifndef _IPOINT_INL_
  2. #define _IPOINT_INL_ 0
  3. /*******************************************************************************
  4. * FILE NAME: ipoint.inl                                                        *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the definition of the inline functions for the          *
  8. *   classes declared in ipoint.hpp.                                            *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   IBM Open Class Library                                                     *
  12. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  13. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _IPOINT_
  19.   #undef  _IPOINT_INL_
  20.   #define _IPOINT_INL_ 1
  21.   #include <ipoint.hpp>
  22. #endif
  23.  
  24. #if _IPOINT_INL_
  25.   #define inline
  26. #endif
  27.  
  28. /*---------------------------------- IPair -----------------------------------*/
  29. inline IPair::IPair ( )
  30.   : coordCl1( 0 ), coordCl2( 0 )
  31.   {
  32.   }
  33. inline IPair::IPair ( Coord init )
  34.   : coordCl1( init ), coordCl2( init )
  35.   {
  36.   }
  37. inline IPair::IPair ( Coord coord1, Coord coord2 )
  38.   : coordCl1( coord1 ), coordCl2( coord2 )
  39.   {
  40.   }
  41. inline IPair::Coord  IPair::coord1 ( )  const
  42.   {
  43.   return coordCl1;
  44.   }
  45. inline IPair::Coord  IPair::coord2 ( )  const
  46.   {
  47.   return coordCl2;
  48.   }
  49. inline IPair& IPair::setCoord1 ( Coord coord1 )
  50.   {
  51.   coordCl1 = coord1;
  52.   return *this;
  53.   }
  54. inline IPair& IPair::setCoord2 ( Coord coord2 )
  55.   {
  56.   coordCl2 = coord2;
  57.   return *this;
  58.   }
  59. inline IPair IPair::operator - ( ) const
  60.   {
  61.   return IPair( -coordCl1, -coordCl2 );
  62.   }
  63. inline IBase::Boolean IPair::operator == ( const IPair& pair ) const
  64.   {
  65.   return ( coordCl1 == pair.coordCl1 && coordCl2 == pair.coordCl2);
  66.   }
  67. inline IBase::Boolean IPair::operator != ( const IPair& pair ) const
  68.   {
  69.   return !( *this == pair );
  70.   }
  71. inline IBase::Boolean IPair::operator <  ( const IPair& pair ) const
  72.   {
  73.   return ( coordCl1 < pair.coordCl1 && coordCl2 < pair.coordCl2 );
  74.   }
  75. inline IBase::Boolean IPair::operator >  ( const IPair& pair ) const
  76.   {
  77.   return ( coordCl1 > pair.coordCl1 && coordCl2 > pair.coordCl2 );
  78.   }
  79. inline IBase::Boolean IPair::operator <= (const IPair& pair ) const
  80.   {
  81.   return ( coordCl1 <= pair.coordCl1 && coordCl2 <= pair.coordCl2);
  82.   }
  83. inline IBase::Boolean IPair::operator >= ( const IPair& pair ) const
  84.   {
  85.   return ( coordCl1 >= pair.coordCl1 && coordCl2 >= pair.coordCl2);
  86.   }
  87. inline IPair operator +  ( const IPair& pair1, const IPair& pair2 )
  88.   {
  89.   return IPair( pair1.coordCl1 + pair2.coordCl1,
  90.                 pair1.coordCl2 + pair2.coordCl2 );
  91.   }
  92. inline IPair operator *  ( const IPair& pair1, const IPair& pair2 )
  93.   {
  94.   return IPair( pair1.coordCl1 * pair2.coordCl1,
  95.                 pair1.coordCl2 * pair2.coordCl2 );
  96.   }
  97. inline IPair operator *  ( const IPair& pair1, double d )
  98.   {
  99.   return IPair( (IPair::Coord)(d * pair1.coordCl1),
  100.                 (IPair::Coord)(d * pair1.coordCl2));
  101.   }
  102. inline IPair operator -  ( const IPair& pair1, const IPair& pair2 )
  103.   {
  104.   return IPair( pair1.coordCl1 - pair2.coordCl1,
  105.                 pair1.coordCl2 - pair2.coordCl2);
  106.   }
  107. inline IPair operator / ( const IPair& pair1, const IPair& pair2 )
  108.   {
  109.   return IPair( pair1.coordCl1 / pair2.coordCl1,
  110.                 pair1.coordCl2 / pair2.coordCl2);
  111.   }
  112. inline IPair operator /  ( const IPair& pair1, double d )
  113.   {
  114.   return IPair( (IPair::Coord)(pair1.coordCl1 / d),
  115.                 (IPair::Coord)(pair1.coordCl2 / d) );
  116.   }
  117. inline IPair operator %  ( const IPair& pair1, const IPair& pair2 )
  118.   {
  119.   return IPair( pair1.coordCl1 % pair2.coordCl1,
  120.                 pair1.coordCl2 % pair2.coordCl2 );
  121.   }
  122. inline IPair operator %  ( const IPair& pair1, IPair::Coord d )
  123.   {
  124.   return IPair( pair1.coordCl1 % d,
  125.                 pair1.coordCl2 % d );
  126.   }
  127. inline IPair& IPair::operator += ( const IPair &aPair )
  128.   {
  129.   return (*this).setCoord1( coordCl1 + aPair.coordCl1 ).
  130.                  setCoord2( coordCl2 + aPair.coordCl2 );
  131.   }
  132. inline IPair& IPair::operator -= ( const IPair &aPair )
  133.   {
  134.   return (*this).setCoord1( coordCl1 - aPair.coordCl1 ).
  135.                  setCoord2( coordCl2 - aPair.coordCl2 );
  136.   }
  137. inline IPair& IPair::operator *= ( const IPair &aPair )
  138.   {
  139.   return (*this).setCoord1( coordCl1 * aPair.coordCl1 ).
  140.                  setCoord2( coordCl2 * aPair.coordCl2 );
  141.   }
  142. inline IPair& IPair::operator *= ( double d )
  143.   {
  144.   return (*this).setCoord1( (Coord)(coordCl1 * d) ).
  145.                  setCoord2( (Coord)(coordCl2 * d) );
  146.   }
  147. inline IPair& IPair::operator /= ( const IPair &aPair )
  148.   {
  149.   return (*this).setCoord1( coordCl1 / aPair.coordCl1 ).
  150.                  setCoord2( coordCl2 / aPair.coordCl2 );
  151.   }
  152. inline IPair& IPair::operator /= ( double d )
  153.   {
  154.   return (*this).setCoord1( (Coord)(coordCl1 / d) ).
  155.                  setCoord2( (Coord)(coordCl2 / d) );
  156.   }
  157. inline IPair& IPair::operator %= ( const IPair &aPair )
  158.   {
  159.   return (*this).setCoord1( coordCl1 % aPair.coordCl1 ).
  160.                  setCoord2( coordCl2 % aPair.coordCl2 );
  161.   }
  162. inline IPair& IPair::operator %= ( Coord d )
  163.   {
  164.   return (*this).setCoord1( coordCl1 % d ).
  165.                  setCoord2( coordCl2 % d );
  166.   }
  167. inline long IPair::dotProduct( const IPair &aPair ) const
  168.   {
  169.   return coordCl1 * aPair.coordCl1 + coordCl2 * aPair.coordCl2;
  170.   }
  171. inline IPair transpose ( const IPair &aPair )
  172.   {
  173.   return IPair( aPair.coordCl2, aPair.coordCl1 );
  174.   }
  175. inline IPair& IPair::transpose ( )
  176.   {
  177.   *this = ::transpose( *this );
  178.   return *this;
  179.   }
  180. inline IPair& IPair :: scaleBy ( double xfact, double yfact )
  181.   {
  182.   setCoord1( (Coord)(coordCl1 * xfact) ).setCoord2( (Coord)(coordCl2 * yfact) );
  183.   return *this;
  184.   }
  185. inline IPair IPair :: scaledBy ( double xfact, double yfact ) const
  186.   {
  187.   IPair result( *this );
  188.   return result.scaleBy( xfact, yfact );
  189.   }
  190. /*---------------------------------- IPoint ----------------------------------*/
  191. inline IPoint::IPoint ( )
  192.   {
  193.   }
  194. inline IPoint::IPoint ( const IPair& pair )
  195.   : IPair( pair )
  196.   {
  197.   }
  198. inline IPoint::IPoint ( Coord x, Coord y )
  199.   : IPair( x, y )
  200.   {
  201.   }
  202. #if (defined(OS2DEF_INCLUDED) || defined(_WINDEF_))
  203. inline IPoint::IPoint ( const POINTL& ptl )
  204.   : IPair( ptl.x, ptl.y )
  205.   {
  206.   }
  207. #endif
  208. #ifdef _WINDEF_
  209. inline IPoint::IPoint ( const POINT& ptl )
  210.   : IPair( ptl.x, ptl.y )
  211.   {
  212.   }
  213. #endif
  214. inline IPair::Coord IPoint::x ( ) const
  215.   {
  216.   return coord1();
  217.   }
  218. inline IPair::Coord IPoint::y ( ) const
  219.   {
  220.   return coord2();
  221.   }
  222. inline IPoint& IPoint::setX ( Coord x )
  223.   {
  224.   setCoord1( x );
  225.   return *this;
  226.   }
  227. inline IPoint& IPoint::setY ( Coord y )
  228.   {
  229.   setCoord2( y );
  230.   return *this;
  231.   }
  232.  
  233. /*---------------------------------- ISize -----------------------------------*/
  234. inline ISize::ISize ( )
  235.   {
  236.   }
  237. inline ISize::ISize ( const IPair& pair )
  238.   : IPair( pair )
  239.   {
  240.   }
  241. inline ISize::ISize ( Coord width, Coord height )
  242.   : IPair( width, height )
  243.   {
  244.   }
  245. #if (defined(GPI_INCLUDED) || defined(_WINDEF_))
  246. inline ISize::ISize ( const SIZEL &sizl )
  247.   : IPair( sizl.cx, sizl.cy )
  248.   {
  249.   }
  250. #endif
  251. #ifdef OS2DEF_INCLUDED
  252. inline ISize::ISize ( const RECTL& rcl )
  253.   : IPair ( rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom )
  254.   {
  255.   }
  256. #endif
  257. #ifdef _WINDEF_
  258. inline ISize::ISize ( const RECTL& rcl )
  259.   : IPair ( rcl.right - rcl.left, rcl.bottom - rcl.top )
  260.   {
  261.   }
  262. #endif
  263. inline IPair::Coord ISize::width ( ) const
  264.   {
  265.   return  coord1();
  266.   }
  267. inline IPair::Coord ISize::height ( ) const
  268.   {
  269.   return  coord2();
  270.   }
  271. inline ISize& ISize::setWidth ( Coord cx )
  272.   {
  273.   setCoord1( cx );
  274.   return *this;
  275.   }
  276. inline ISize& ISize::setHeight ( Coord cy )
  277.   {
  278.   setCoord2( cy );
  279.   return *this;
  280.   }
  281.  
  282. /*---------------------------------- IRange ----------------------------------*/
  283. inline IRange::IRange ( )
  284.   : IPair( 0, 0 )
  285.   {
  286.   }
  287. inline IRange::IRange ( const IPair& pair )
  288.   : IPair( pair )
  289.   {
  290.   }
  291. inline IRange::IRange ( Coord lowerBound, Coord upperBound )
  292.   : IPair( lowerBound, upperBound )
  293.   {
  294.   }
  295. inline IPair::Coord IRange::lowerBound ( ) const
  296.   {
  297.   return coord1();
  298.   }
  299. inline IPair::Coord IRange::upperBound ( ) const
  300.   {
  301.   return coord2();
  302.   }
  303. inline IRange& IRange::setLowerBound ( Coord lowerBound )
  304.   {
  305.   setCoord1( lowerBound );
  306.   return *this;
  307.   }
  308. inline IRange& IRange::setUpperBound ( Coord upperBound )
  309.   {
  310.   setCoord2( upperBound );
  311.   return *this;
  312.   }
  313. inline IBase::Boolean IRange::includes ( Coord aValue ) const
  314.   {
  315.   return ( aValue >= lowerBound() && aValue <= upperBound() );
  316.   }
  317. #endif /* _IPOINT_INL_ */
  318.