home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IPOINT.INL < prev    next >
Text File  |  1993-10-22  |  9KB  |  325 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. *   class(es) declared in ipoint.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 _IPOINT_
  20.   #undef  _IPOINT_INL_
  21.   #define _IPOINT_INL_ 1
  22.   extern "C"
  23.     {
  24.     #include <os2.h>
  25.     }
  26.   #include <ipoint.hpp>
  27. #endif
  28.  
  29. #if _IPOINT_INL_
  30.   #define inline
  31. #endif
  32.  
  33. /*---------------------------------- IPair -----------------------------------*/
  34. inline IPair::IPair ( )
  35.   : coordCl1( 0 ), coordCl2( 0 )
  36.   { 
  37.   }
  38. inline IPair::IPair ( Coord init )
  39.   : coordCl1( init ), coordCl2( init )
  40.   { 
  41.   }
  42. inline IPair::IPair ( Coord coord1, Coord coord2 )
  43.   : coordCl1( coord1 ), coordCl2( coord2 )
  44.   { 
  45.   }
  46. inline IPair::Coord  IPair::coord1 ( )  const
  47.   { 
  48.   return coordCl1;
  49.   }
  50. inline IPair::Coord  IPair::coord2 ( )  const
  51.   { 
  52.   return coordCl2;
  53.   }
  54. inline IPair &IPair::setCoord1 ( Coord coord1 )
  55.   { 
  56.   coordCl1 = coord1;
  57.   return *this;
  58.   }
  59. inline IPair &IPair::setCoord2 ( Coord coord2 )
  60.   { 
  61.   coordCl2 = coord2;
  62.   return *this;
  63.   }
  64. inline IPair IPair::operator - ( ) const
  65.   {
  66.   return IPair( -coordCl1, -coordCl2 );
  67.   }
  68. inline IBase::Boolean IPair::operator == ( const IPair &pair ) const
  69.   {
  70.   return ( coordCl1 == pair.coordCl1 && coordCl2 == pair.coordCl2); 
  71.   }
  72. inline IBase::Boolean IPair::operator != ( const IPair &pair ) const
  73.   {
  74.   return !( *this == pair );
  75.   }
  76. inline IBase::Boolean IPair::operator <  ( const IPair &pair ) const
  77.   {
  78.   return ( coordCl1 < pair.coordCl1 && coordCl2 < pair.coordCl2 );
  79.   }
  80. inline IBase::Boolean IPair::operator >  ( const IPair &pair ) const
  81.   {
  82.   return ( coordCl1 > pair.coordCl1 && coordCl2 > pair.coordCl2 );
  83.   }
  84. inline IBase::Boolean IPair::operator <= (const IPair &pair ) const
  85.   {
  86.   return ( coordCl1 <= pair.coordCl1 && coordCl2 <= pair.coordCl2); 
  87.   }
  88. inline IBase::Boolean IPair::operator >= ( const IPair &pair ) const
  89.   {
  90.   return ( coordCl1 >= pair.coordCl1 && coordCl2 >= pair.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, const IPair &pair2 )
  98.   {
  99.   return IPair( pair1.coordCl1 * pair2.coordCl1,
  100.                 pair1.coordCl2 * pair2.coordCl2 );
  101.   }
  102. inline IPair operator *  ( const IPair &pair1, double d )
  103.   {
  104.   return IPair( (IPair::Coord)(d * pair1.coordCl1),
  105.                 (IPair::Coord)(d * pair1.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, const IPair &pair2 )
  113.   {
  114.   return IPair( pair1.coordCl1 / pair2.coordCl1,
  115.                 pair1.coordCl2 / pair2.coordCl2);
  116.   }
  117. inline IPair operator /  ( const IPair &pair1, double d )
  118.   {
  119.   return IPair( (IPair::Coord)(pair1.coordCl1 / d),
  120.                 (IPair::Coord)(pair1.coordCl2 / d) );
  121.   }
  122. inline IPair operator %  ( const IPair &pair1, const IPair &pair2 )
  123.   {
  124.   return IPair( pair1.coordCl1 % pair2.coordCl1,
  125.                 pair1.coordCl2 % pair2.coordCl2 );
  126.   }
  127. inline IPair operator %  ( const IPair &pair1, IPair::Coord d )
  128.   {
  129.   return IPair( pair1.coordCl1 % d,
  130.                 pair1.coordCl2 % d );
  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 *= ( const IPair &aPair )
  143.   {
  144.   return (*this).setCoord1( coordCl1 * aPair.coordCl1 ).
  145.                  setCoord2( coordCl2 * aPair.coordCl2 );
  146.   }
  147. inline IPair &IPair::operator *= ( double d )
  148.   {
  149.   return (*this).setCoord1( (Coord)(coordCl1 * d) ).
  150.                  setCoord2( (Coord)(coordCl2 * d) );
  151.   }
  152. inline IPair &IPair::operator /= ( const IPair &aPair )
  153.   {
  154.   return (*this).setCoord1( coordCl1 / aPair.coordCl1 ).
  155.                  setCoord2( coordCl2 / aPair.coordCl2 );
  156.   }
  157. inline IPair &IPair::operator /= ( double d )
  158.   {
  159.   return (*this).setCoord1( (Coord)(coordCl1 / d) ).
  160.                  setCoord2( (Coord)(coordCl2 / d) );
  161.   }
  162. inline IPair &IPair::operator %= ( const IPair &aPair )
  163.   {
  164.   return (*this).setCoord1( coordCl1 % aPair.coordCl1 ).
  165.                  setCoord2( coordCl2 % aPair.coordCl2 );
  166.   }
  167. inline IPair &IPair::operator %= ( Coord d )
  168.   {
  169.   return (*this).setCoord1( coordCl1 % d ).
  170.                  setCoord2( coordCl2 % d );
  171.   }
  172. inline long IPair::dotProduct( const IPair &aPair ) const
  173.   {
  174.   return coordCl1 * aPair.coordCl1 + coordCl2 * aPair.coordCl2;
  175.   }
  176. inline IPair transpose ( const IPair &aPair )
  177.   {
  178.   return IPair( aPair.coordCl2, aPair.coordCl1 );
  179.   }
  180. inline IPair &IPair::transpose ( )
  181.   {
  182.   *this = ::transpose( *this );
  183.   return *this;
  184.   }
  185. inline IPair &IPair :: scaleBy ( double xfact, double yfact )
  186.   {
  187.   setCoord1( (Coord)(coordCl1 * xfact) ).setCoord2( (Coord)(coordCl2 * yfact) );
  188.   return *this;
  189.   }
  190. inline IPair IPair :: scaledBy ( double xfact, double yfact ) const
  191.   {
  192.   IPair result( *this );
  193.   return result.scaleBy( xfact, yfact );
  194.   }
  195. /*---------------------------------- IPoint ----------------------------------*/
  196. inline IPoint::IPoint ( )
  197.   {
  198.   }
  199. inline IPoint::IPoint ( const IPair &pair )
  200.   : IPair( pair )
  201.   {
  202.   }
  203. inline IPoint::IPoint ( Coord x, Coord y )
  204.   : IPair( x, y )
  205.   {
  206.   }
  207. #ifdef OS2DEF_INCLUDED 
  208. inline IPoint::IPoint ( const POINTL& ptl )
  209.   : IPair( ptl.x, ptl.y )
  210.   {
  211.   }
  212. #endif
  213. inline IPair::Coord IPoint::x ( ) const
  214.   {   
  215.   return coord1();  
  216.   }
  217. inline IPair::Coord IPoint::y ( ) const
  218.   {   
  219.   return coord2();  
  220.   }
  221. inline IPoint &IPoint::setX ( Coord x )
  222.   {   
  223.   setCoord1( x );
  224.   return *this;
  225.   }
  226. inline IPoint &IPoint::setY ( Coord y )
  227.   {   
  228.   setCoord2( y );
  229.   return *this;
  230.   }
  231. #ifdef OS2DEF_INCLUDED
  232. inline POINTL IPoint::asPOINTL ( ) const
  233.   {
  234.   POINTL ptl = { x(), y() };
  235.   return ptl;
  236.   }
  237. #endif
  238.  
  239. /*---------------------------------- ISize -----------------------------------*/
  240. inline ISize::ISize ( )
  241.   {
  242.   }
  243. inline ISize::ISize ( const IPair &pair ) 
  244.   : IPair( pair ) 
  245.   {
  246.   }
  247. inline ISize::ISize ( Coord width, Coord height )
  248.   : IPair( width, height )
  249.   {
  250.   }
  251. #ifdef GPI_INCLUDED
  252. inline ISize::ISize ( const SIZEL &sizl )  
  253.   : IPair( sizl.cx, sizl.cy ) 
  254.   {
  255.   }
  256. #endif
  257. #ifdef OS2DEF_INCLUDED
  258. inline ISize::ISize ( const RECTL &rcl )
  259.   : IPair ( rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom ) 
  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. #ifdef GPI_INCLUDED
  282. inline SIZEL ISize::asSIZEL ( ) const
  283.   {
  284.   SIZEL sizl = { width(), height() };
  285.   return sizl;
  286.   }
  287. #endif
  288.  
  289. /*---------------------------------- IRange ----------------------------------*/
  290. inline IRange::IRange ( ) 
  291.   : IPair( 0, 0 ) 
  292.   {
  293.   }
  294. inline IRange::IRange ( const IPair &pair ) 
  295.   : IPair( pair ) 
  296.   {
  297.   }
  298. inline IRange::IRange ( Coord lowerBound, Coord upperBound )
  299.   : IPair( lowerBound, upperBound )
  300.   {
  301.   }
  302. inline IPair::Coord IRange::lowerBound ( ) const
  303.   {
  304.   return coord1(); 
  305.   }
  306. inline IPair::Coord IRange::upperBound ( ) const
  307.   {
  308.   return coord2(); 
  309.   }
  310. inline IRange &IRange::setLowerBound ( Coord lowerBound ) 
  311.   {
  312.   setCoord1( lowerBound );
  313.   return *this;
  314.   }
  315. inline IRange &IRange::setUpperBound ( Coord upperBound )
  316.   {
  317.   setCoord2( upperBound );
  318.   return *this;
  319.   }
  320. inline IBase::Boolean IRange::includes ( Coord aValue ) const
  321.   {
  322.   return ( aValue >= lowerBound() && aValue <= upperBound() );
  323.   }
  324. #endif /* _IPOINT_INL_ */
  325.