home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IPOINT.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
20KB
|
368 lines
#ifndef _IPOINT_
#define _IPOINT_
/*******************************************************************************
* FILE NAME: ipoint.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IPair - General-purpose "ordered pair" of (long) integer values *
* IPoint - Ordered pair representing a point as x- and y-coordinates in *
* two dimensional space *
* ISize - Ordered pair representing a two-dimensional size as horizontal *
* and vertical dimensions *
* IRange - Ordered pair representing a range of values as starting and *
* ending values *
* *
* 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 _IBASE_
#include <ibase.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
struct _POINTL;
struct _RECTL;
struct _SIZEL;
class ISize;
class IWindowHandle;
class IPair : public IBase {
typedef IBase
Inherited;
/*******************************************************************************
* Objects of the IPair class are generic ordered pairs of coordinates. The *
* class serves as the base for the specific ordered pair classes IPoint, *
* ISize, and IRange. *
* *
* This class provides basic utilities to get and set the two coordinate *
* values. In addition, it provides a full set of comparison and mathematical *
* operators to manipulate ordered pairs. *
*******************************************************************************/
public:
/*------------------------------ Related Types ---------------------------------
| The following related type is defined for this class: |
| Coord - Type of the coordinate values (long int). |
------------------------------------------------------------------------------*/
typedef long Coord;
/*------------------------------- Constructors ---------------------------------
| You can construct instances of this class in the following ways: |
| - From the default constructor. This constructs an instance of the |
| ordered pair (0,0). |
| - From a single coordinate. This constructs an ordered pair with both |
| coordinates set to the same argument value. |
| - From two coordinates. This constructs an ordered pair with each |
| coordinate set to a different argument value. |
------------------------------------------------------------------------------*/
IPair ( );
IPair ( Coord init );
IPair ( Coord coord1,
Coord coord2 );
/*-------------------------------- Accessors -----------------------------------
| The following functions provide access to attributes of IPair objects: |
| coord1 - Obtains the value of the first coordinate. |
| coord2 - Obtains the value of the second coordinate. |
| setCoord1 - Sets the value of the first coordinate. |
| setCoord2 - Sets the value of the second coordinate. |
------------------------------------------------------------------------------*/
Coord
coord1 ( ) const,
coord2 ( ) const;
IPair
&setCoord1 ( Coord coord1 ),
&setCoord2 ( Coord coord2 );
/*----------------------------- Minimum/Maximum --------------------------------
| minimum - Returns an ordered pair whose coordinates are the minimum of the |
| corresponding coordinates of the IPair and the argument IPair. |
| maximum - Returns an ordered pair whose coordinates are the maximum of the |
| corresponding coordinates of the IPair and the argument IPair. |
------------------------------------------------------------------------------*/
IPair
minimum ( const IPair &aPair ) const,
maximum ( const IPair &aPair ) const;
/*--------------------------------- Negation -----------------------------------
| operator - - (unary) Returns an ordered pair with negated coordinates. |
------------------------------------------------------------------------------*/
IPair
operator - ( ) const;
/*--------------------------- Comparison Operators -----------------------------
| This class provides a complete set of operators for comparing one ordered |
| pair to another: |
| operator == - True if and only if both coordinates match those of the |
| argument. |
| operator != - True if and only if either coordinate differs. |
| operator < - True if and only if both coordinates are less than those of |
| the argument. |
| operator > - True if and only if both coordinates are greater than those |
| of the argument. |
| operator <= - True if and only if both coordinates are less than or equal. |
| operator >= - True if and only if both coordinates are greater than or |
| equal. |
------------------------------------------------------------------------------*/
Boolean
operator == ( const IPair &aPair ) const,
operator != ( const IPair &aPair ) const,
operator < ( const IPair &aPair ) const,
operator > ( const IPair &aPair ) const,
operator <= ( const IPair &aPair ) const,
operator >= ( const IPair &aPair ) const;
/*-------------------------- Manipulation Operators ----------------------------
| This class provides a complete set of arithmetic operators that can be |
| applied to two ordered pairs; these are friend (non-member) functions. |
| operator + - Returns an ordered pair whose coordinates are the sums of |
| the corresponding coordinates of the IPair and the argument. |
| operator * - Returns an ordered pair whose coordinates are the product |
| of the IPair and the argument. |
| operator - - Returns an ordered pair whose coordinates are the |
| difference between the corresponding coordinates of the |
| IPair and the argument. |
| operator / - Returns an ordered pair whose coordinates are the quotient |
| of the corresponding coordinates of the IPair and the |
| argument. |
| operator % - Returns an ordered pair whose coordinates are the remainder |
| of the corresponding coordinates of the IPair and the |
| argument. |
| operator += - Adds to the coordinates of an ordered pair those of the |
| argument. |
| operator -= - Subtracts from the coordinates those of the argument. |
| operator *= - Multiplies the coordinates by those of the argument. |
| operator /= - Divides the coordinates by those of the argument. |
| operator %= - Replaces the coordinates with the remainder when divided by |
| those of the argument. |
------------------------------------------------------------------------------*/
friend IPair
operator + ( const IPair &pair1, const IPair &pair2 ),
operator * ( const IPair &pair1, const IPair &pair2 ),
operator * ( const IPair &pair1, double multiplier ),
operator - ( const IPair &pair1, const IPair &pair2 ),
operator / ( const IPair &pair1, const IPair &pair2 ),
operator / ( const IPair &pair1, double divisor ),
operator % ( const IPair &pair1, const IPair &pair2 ),
operator % ( const IPair &aPair1, long divisor );
IPair
&operator += ( const IPair &aPair ),
&operator -= ( const IPair &aPair ),
&operator *= ( const IPair &aPair ),
&operator *= ( double multiplier ),
&operator /= ( const IPair &aPair ),
&operator /= ( double divisor ),
&operator %= ( const IPair &aPair ),
&operator %= ( long divisor );
/*-------------------------- Manipulation Functions ----------------------------
| These functions can be used to scale a pair by different floating point |
| values in the X- and Y-dimensions: |
| scaleBy - Scales the X-coordinate by one amount, the Y-coordinate by |
| another. |
| scaledBy - Same as scaleBy, but returns a new IPair, leaving the original |
| unmodified. |
------------------------------------------------------------------------------*/
IPair
&scaleBy ( double xFactor, double yFactor ),
scaledBy ( double xFactor, double yFactor ) const;
/*------------------------------ Miscellaneous ---------------------------------
| distanceFrom - Returns the distance from some other ordered pair. |
| dotProduct - Returns the dot product with some other ordered pair. |
| transpose - Swaps the coordinates of the ordered pair; the friend |
| function returns a new pair with transposed coordinates. |
------------------------------------------------------------------------------*/
double
distanceFrom ( const IPair &aPair ) const;
long
dotProduct ( const IPair &aPair ) const;
IPair
&transpose ( );
friend IPair
transpose ( const IPair &aPair );
/*-------------------------------- Conversion ----------------------------------
| asString - Converts the ordered pair (a,b) to an IString( "(a,b)" ). |
| asDebugInfo - Converts the ordered pair to an IString that contains a |
| diagnostic representation of the object. |
------------------------------------------------------------------------------*/
IString
asString ( ) const,
asDebugInfo ( ) const;
/*-------------------------------- Displaying ----------------------------------
| operator << - This operator is provided to enable ordered pairs to be |
| written to ostreams in the conventional manner. |
------------------------------------------------------------------------------*/
friend ostream
&operator << ( ostream &aStream,
const IPair &aRectangle );
private:
/*--------------------------------- PRIVATE ----------------------------------*/
Coord
coordCl1,
coordCl2;
}; // class IPair
class IPoint : public IPair {
typedef IPair
Inherited;
/*******************************************************************************
* Objects of the IPoint class represent points in two dimensional space. In *
* addition to all the functions inherited from its base class, IPair, the *
* IPoint class provides a few other functions. *
*******************************************************************************/
public:
/*------------------------------- Constructors ---------------------------------
| You can construct instances of this class in the following ways: |
| - From the default constructor. The resulting point has X- and |
| Y-coordinates equal to 0. |
| - From any other ordered pair. |
| - From arbitrary X- and Y-coordinates. |
| - From a Presentation Manager Toolkit-defined POINTL structure. |
------------------------------------------------------------------------------*/
IPoint ( );
IPoint ( const IPair &pair );
IPoint ( Coord x, Coord y );
IPoint ( const struct _POINTL &ptl );
/*-------------------------------- Accessors -----------------------------------
| x - Returns the point's X-coordinate. |
| y - Returns the point's Y-coordinate. |
| setX - Sets the point's X-coordinate. |
| setY - Sets the point's Y-coordinate. |
------------------------------------------------------------------------------*/
Coord
x ( ) const,
y ( ) const;
IPoint
&setX ( Coord X ),
&setY ( Coord Y );
/*-------------------------------- Conversion ----------------------------------
| asPOINTL - Renders the point as a Presentation Manager Toolkit POINTL |
| structure. |
------------------------------------------------------------------------------*/
struct _POINTL
asPOINTL ( ) const;
}; // class IPoint
class ISize : public IPair {
typedef IPair
Inherited;
/*******************************************************************************
* Objects of the ISize class use their coordinates to represent a rectangular *
* size (in horizontal and vertical dimensions). *
*******************************************************************************/
public:
/*------------------------------- Constructors ---------------------------------
| Objects of this class can be constructed from: |
| - The default constructor. The resulting size has a width and height |
| of 0. |
| - Another ordered pair of coordinates. |
| - A given width and height. |
| - A Presentation Manager Toolkit SIZEL structure. |
| - A Presentation Manager Toolkit RECTL structure; in this case, the |
| resulting ISize object represents the size of the RECTL. |
------------------------------------------------------------------------------*/
ISize ( );
ISize ( const IPair &pair );
ISize ( Coord width, Coord height );
ISize ( const struct _SIZEL &sizl );
ISize ( const struct _RECTL &rcl );
/*-------------------------------- Accessors -----------------------------------
| width - Returns the width represented by the ISize object. |
| height - Returns the height represented by the ISize object. |
| setWidth - Sets the size's width. |
| setHeight - Sets the size's height. |
------------------------------------------------------------------------------*/
Coord
width ( ) const,
height ( ) const;
ISize
&setWidth ( Coord cx ),
&setHeight ( Coord cy );
/*-------------------------------- Conversion ----------------------------------
| asSIZEL - Returns the ISize as a Presentation Manager Toolkit SIZEL |
| structure. |
------------------------------------------------------------------------------*/
struct _SIZEL
asSIZEL ( ) const;
}; // class ISize
class IRange : public IPair {
typedef IPair
Inherited;
/*******************************************************************************
Objects of the IRange class represent a range of IPair::Coord values
between a given lower and upper bound (inclusive).
*******************************************************************************/
public:
/*------------------------------- Constructors ---------------------------------
| You can construct instances of this class in the following ways: |
| - By using the default constructor. The resulting range is [0, 0]. |
| - From any ordered pair (a,b). The resulting range is [a, b]. |
| - From any given lower and upper bounds. |
------------------------------------------------------------------------------*/
IRange ( );
IRange ( const IPair &aPair );
IRange ( Coord lower, Coord upper );
/*-------------------------------- Accessors -----------------------------------
| This class provides accessing functions that manage the elements of the |
| ordered pair as "lower" and "upper" values: |
| lowerBound - Returns the lower bound of the range. |
| upperBound - Returns the upper bound of the range. |
| setLowerBound - Sets the lower bound of the range. |
| setUpperBound - Sets the upper bound of the range. |
------------------------------------------------------------------------------*/
Coord
lowerBound ( ) const,
upperBound ( ) const;
IRange
&setUpperBound ( Coord upper ),
&setLowerBound ( Coord lower );
/*--------------------------------- Testing ------------------------------------
| The following function is used to test argument coordinate values: |
| includes - Returns true if and only if the argument coordinate value is |
| contained in the range. |
------------------------------------------------------------------------------*/
Boolean
includes ( Coord aValue ) const;
}; // class IRange
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
/*----------------------------- Inline Functions -----------------------------*/
#ifndef I_NO_INLINES
#include <ipoint.inl>
#endif
#endif /* _IPOINT_ */