home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IRECT.INL
< prev
next >
Wrap
Text File
|
1993-10-22
|
12KB
|
386 lines
#ifndef _IRECT_INL_
#define _IRECT_INL_ 0
/*******************************************************************************
* FILE NAME: irect.inl *
* *
* DESCRIPTION: *
* This file contains the definition of the inline functions for the *
* class(es) declared in irect.hpp. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or *
* disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IRECT_
#undef _IRECT_INL_
#define _IRECT_INL_ 1
extern "C"
{
#include <os2.h>
}
#include <irect.hpp>
#endif
#if _IRECT_INL_
#define inline
#endif
/*------------------------------- Constructors -------------------------------*/
inline IRectangle :: IRectangle ( )
: origin( 0, 0 ), corner( 0, 0 )
{
}
inline IRectangle :: IRectangle ( const IPoint &point1,
const IPoint &point2 )
: origin( point1.minimum( point2 ) ), corner( point1.maximum( point2 ) )
{
}
inline IRectangle :: IRectangle ( const IPoint &aPoint,
const ISize &aSize )
: origin( aPoint.minimum( aPoint+aSize ) ),
corner( aPoint.maximum( aPoint+aSize ) )
{
}
inline IRectangle :: IRectangle ( Coord x1,
Coord y1,
Coord x2,
Coord y2 )
: origin( IPair( x1, y1 ).minimum( IPair( x2, y2 ) ) ),
corner( IPair( x1, y1 ).maximum( IPair( x2, y2 ) ) )
{
}
#if defined(OS2DEF_INCLUDED)
inline IRectangle :: IRectangle ( const RECTL &aRECTL)
: origin( IPair( aRECTL.xLeft, aRECTL.yBottom ).
minimum( IPair( aRECTL.xRight, aRECTL.yTop ) ) ),
corner( IPair( aRECTL.xLeft, aRECTL.yBottom ).
maximum( IPair( aRECTL.xRight, aRECTL.yTop ) ) )
{
}
#endif
inline IRectangle :: IRectangle ( Coord width,
Coord height )
: origin( IPair( width, height ).minimum( IPair() ) ),
corner( IPair( width, height ).maximum( IPair() ) )
{
}
inline IRectangle :: IRectangle ( const IPair &aPair )
: origin( aPair.minimum( IPair() ) ),
corner( aPair.maximum( IPair() ) )
{
}
/*-------------------------------- Accessors ---------------------------------*/
inline IRectangle::Coord IRectangle :: bottom ( ) const
{
return origin.y();
}
inline IRectangle::Coord IRectangle :: height ( ) const
{
return corner.y() - origin.y();
}
inline IRectangle::Coord IRectangle :: left ( ) const
{
return origin.x();
}
inline IRectangle::Coord IRectangle :: right ( ) const
{
return corner.x();
}
inline IRectangle::Coord IRectangle :: top ( ) const
{
return corner.y();
}
inline IRectangle::Coord IRectangle :: width ( ) const
{
return corner.x() - origin.x();
}
inline IPoint IRectangle :: bottomCenter ( ) const
{
return IPoint( ( right() + left() ) / 2,
bottom() );
}
inline IPoint IRectangle :: bottomLeft ( ) const
{
return origin;
}
inline IPoint IRectangle :: bottomRight ( ) const
{
return IPoint( right(),
bottom() );
}
inline IPoint IRectangle :: center ( ) const
{
return ( origin + corner ) / 2;
}
inline IPoint IRectangle :: leftCenter ( ) const
{
return IPoint( left(),
( top() + bottom() ) / 2 );
}
inline IPoint IRectangle :: rightCenter ( ) const
{
return IPoint( right(),
( top() + bottom() ) / 2 );
}
inline IPoint IRectangle :: topCenter ( ) const
{
return IPoint( ( right() + left() ) / 2,
top() );
}
inline IPoint IRectangle :: topLeft ( ) const
{
return IPoint( left(),
top() );
}
inline IPoint IRectangle :: topRight ( ) const
{
return corner;
}
inline ISize IRectangle :: size ( ) const
{
return corner - origin;
}
inline IRectangle::Coord IRectangle :: area ( ) const
{
return height() * width();
}
#ifdef OS2_INCLUDED
inline RECTL IRectangle :: asRECTL ( ) const
{
RECTL rectl = { left(), bottom(), right(), top() };
return rectl;
}
#endif
/*--------------------------- Comparison Operators ---------------------------*/
inline IBase::Boolean IRectangle :: operator == ( const IRectangle &aRect ) const
{
return ( origin == aRect.origin
&&
corner == aRect.corner );
}
inline IBase::Boolean IRectangle :: operator != ( const IRectangle& aRect ) const
{
return !( *this == aRect );
}
/*------------------------------ Implementation ------------------------------*/
inline IRectangle &IRectangle :: validate ( )
{
if ( corner < origin )
origin = corner = IPoint( 0, 0 );
return *this;
}
/*-------------------------- Manipulation Operators --------------------------*/
inline IRectangle &IRectangle :: operator &= ( const IRectangle &aRect )
{
origin = origin.maximum( aRect.origin );
corner = corner.minimum( aRect.corner );
return validate();
}
inline IRectangle IRectangle :: operator & ( const IRectangle &aRect ) const
{
IRectangle result( *this );
return ( result &= aRect );
}
inline IRectangle &IRectangle :: operator |= ( const IRectangle &aRect )
{
origin = origin.minimum( aRect.origin ),
corner = corner.maximum( aRect.corner );
return *this;
}
inline IRectangle IRectangle :: operator | ( const IRectangle &aRect ) const
{
IRectangle result( *this );
return result |= aRect;
}
/*------------------------------- Manipulation -------------------------------*/
inline IRectangle &IRectangle :: moveBy ( const IPair &aPair )
{
origin += aPair;
corner += aPair;
return *this;
}
inline IRectangle &IRectangle :: centerAt ( const IPoint &aPoint )
{
return moveBy( aPoint - center() );
}
inline IRectangle IRectangle :: centeredAt ( const IPoint &aPoint ) const
{
IRectangle result( *this );
return result.centerAt( aPoint );
}
inline IRectangle &IRectangle :: expandBy ( const IPair &aPair )
{
origin -= aPair;
corner += aPair;
return validate();
}
inline IRectangle &IRectangle :: expandBy ( Coord coord )
{
origin -= coord,
corner += coord;
return validate();
}
inline IRectangle IRectangle :: expandedBy ( const IPair &aPair ) const
{
IRectangle result( *this );
return result.expandBy( aPair );
}
inline IRectangle IRectangle :: expandedBy ( Coord coord ) const
{
IRectangle result( *this );
return result.expandBy( coord );
}
inline IRectangle IRectangle :: movedBy ( const IPair &aPair ) const
{
IRectangle result( *this );
return result.moveBy( aPair );
}
inline IRectangle &IRectangle :: moveTo ( const IPoint &aPoint )
{
return moveBy( aPoint - origin );
}
inline IRectangle IRectangle :: movedTo ( const IPoint &aPoint ) const
{
IRectangle result( *this );
return result.moveTo( aPoint );
}
inline IRectangle &IRectangle :: scaleBy ( const IPair &aPair )
{
origin *= aPair;
corner *= aPair;
return *this;
}
inline IRectangle &IRectangle :: scaleBy ( Coord coord )
{
origin *= coord,
corner *= coord;
return *this;
}
inline IRectangle &IRectangle :: scaleBy ( double amt )
{
origin *= amt;
corner *= amt;
return *this;
}
inline IRectangle &IRectangle :: scaleBy ( double xamt, double yamt )
{
origin.scaleBy( xamt, yamt );
corner.scaleBy( xamt, yamt );
return *this;
}
inline IRectangle IRectangle :: scaledBy ( const IPair &aPair ) const
{
IRectangle result( *this );
return result.scaleBy( aPair );
}
inline IRectangle IRectangle :: scaledBy ( Coord coord ) const
{
IRectangle result( *this );
return result.scaleBy( coord );
}
inline IRectangle IRectangle :: scaledBy ( double amt ) const
{
IRectangle result( *this );
return result.scaleBy( amt );
}
inline IRectangle IRectangle :: scaledBy ( double xamt, double yamt ) const
{
IRectangle result( *this );
return result.scaleBy( xamt, yamt );
}
inline IRectangle &IRectangle :: shrinkBy ( const IPair &aPair )
{
return expandBy( -aPair );
}
inline IRectangle &IRectangle :: shrinkBy ( Coord coord )
{
return expandBy( -coord );
}
inline IRectangle IRectangle :: shrunkBy ( const IPair &aPair ) const
{
return expandedBy( -aPair );
}
inline IRectangle IRectangle :: shrunkBy ( Coord coord ) const
{
return expandedBy( -coord );
}
inline IRectangle &IRectangle :: sizeTo ( const IPair &aPair )
{
corner = origin + aPair;
return *this;
}
inline IRectangle IRectangle :: sizedTo ( const IPair &aPair ) const
{
IRectangle result( *this );
return result.sizeTo( aPair );
}
inline IRectangle &IRectangle :: sizeBy ( Coord factor )
{
IPoint save( bottomLeft() );
moveTo( IPoint(0,0) ).scaleBy( factor ).moveTo( save );
return *this;
}
inline IRectangle &IRectangle :: sizeBy ( const IPair &aPair )
{
IPoint save( bottomLeft() );
moveTo( IPoint(0,0) ).scaleBy( aPair ).moveTo( save );
return *this;
}
inline IRectangle &IRectangle :: sizeBy ( double factor )
{
IPoint save( bottomLeft() );
moveTo( IPoint(0,0) ).scaleBy( factor ).moveTo( save );
return *this;
}
inline IRectangle &IRectangle :: sizeBy ( double xfact, double yfact )
{
IPoint save( bottomLeft() );
moveTo( IPoint(0,0) ).scaleBy( xfact, yfact ).moveTo( save );
return *this;
}
inline IRectangle IRectangle :: sizedBy ( Coord factor ) const
{
IRectangle result( *this );
return result.sizeBy( factor );
}
inline IRectangle IRectangle :: sizedBy ( const IPair &aPair ) const
{
IRectangle result( *this );
return result.sizeBy( aPair );
}
inline IRectangle IRectangle :: sizedBy ( double factor ) const
{
IRectangle result( *this );
return result.sizeBy( factor );
}
inline IRectangle IRectangle :: sizedBy ( double xfact, double yfact ) const
{
IRectangle result( *this );
return result.sizeBy( xfact, yfact );
}
/*--------------------------------- Testing ----------------------------------*/
inline IBase::Boolean IRectangle :: contains ( const IRectangle &aRect ) const
{
return ( origin <= aRect.origin
&&
aRect.corner <= corner );
}
inline IBase::Boolean IRectangle :: contains ( const IPoint &aPoint ) const
{
return ( aPoint >= origin
&&
aPoint < corner );
}
inline IBase::Boolean IRectangle :: intersects ( const IRectangle &aRect ) const
{
return ( origin < aRect.corner
&&
aRect.origin < corner );
}
#endif /* _IRECT_INL_ */