home *** CD-ROM | disk | FTP | other *** search
- #if !defined(_IPoint_)
- #define _IPoint_
-
- /**************************************************************/
- /* CLASS NAME: IPair, IPoint, ISize, IRange */
- /* */
- /* DESCRIPTION : This file defines a series of classes that */
- /* work on a pair of long integers. */
- /* IPair, IPoint, ISize, and IRange. */
- /* */
- /* CHANGE ACTIVITY: */
- /* DATE: INITIAL: DESCRIPTION */
- /* */
- /* 101091 RDL Move from ibasetyp.hxx */
- /* 012292 RDL Release 2.0 Changes */
- /* 051692 RDL Removed COORD&, added setX etc */
- /* 093092 RDL max/min to maximum.minimum */
- /**************************************************************/
- /* Copyright (c) IBM Corporation 1992 */
- /**************************************************************/
-
- #include <ibasetyp.hpp>
- #include <istring.hpp>
- class IPair;
- class ISize;
- class IPoint;
- class IRange;
- typedef long COORD;
- class IWindowHandle;
-
-
- /***********************************************************/
- /* IPair class */
- /***********************************************************/
- class IPair
- {
- public:
- IPair();
- IPair( long lInit);
- IPair(COORD coord1, COORD coord2);
- virtual ~IPair() {}
-
- COORD coord1() const;
- COORD coord2() const;
- void setCoord1(COORD coord1);
- void setCoord2(COORD coord2);
- IPair minimum(const IPair& pair) const;
- IPair maximum(const IPair& pair) const;
-
- /* Unary */
- IPair operator-() const;
-
- /* Comparison Operators */
- Boolean operator==(const IPair& pair) const;
- Boolean operator!=(const IPair& pair) const;
- Boolean operator<(const IPair& pair) const;
- Boolean operator>(const IPair& pair) const;
- Boolean operator<=(const IPair& pair) const;
- Boolean operator>=(const IPair& pair) const;
-
-
- /* Manipulation Operators */
- friend IPair operator+(IPair pair1, IPair pair2);
- friend IPair operator*(IPair pair1, IPair pair2);
- friend IPair operator-(IPair pair1, IPair pair2);
- friend IPair operator/(IPair pair1, IPair pair2);
- friend IPair operator%(IPair pair1, IPair pair2);
- friend IPair operator*(IPair pair1, double dMultiplier);
- friend IPair operator/(IPair pair1, double dDivisor);
-
- IPair& operator+=(IPair pair);
- IPair& operator*=(IPair pair);
- IPair& operator*=(double d);
- IPair& operator-=(IPair pair);
- IPair& operator/=(IPair pair);
- IPair& operator/=(double d);
- IPair& operator%=(IPair pair);
-
-
- virtual IString dump() const;
-
- private:
- COORD coordCl1;
- COORD coordCl2;
- };
-
-
- /********************************************************/
- /* IPoint class */
- /********************************************************/
- class IPoint : public IPair /* pt */
- {
- public:
- IPoint();
- IPoint(const IPair& pair);
- IPoint( COORD ptX, COORD ptY );
- IPoint( const ISize& siz);
- #if defined(OS2DEF_INCLUDED)
- IPoint( const POINTL& ptl);
- IPoint( const RECTL& rcl);
- #endif
- virtual ~IPoint() {}
-
- COORD x() const;
- COORD y() const;
- void setX(COORD X);
- void setY(COORD Y);
- COORD pointX() const;
- COORD pointY() const;
- IPoint mapToWinPoint(IWindowHandle hwndFrom, IWindowHandle hwndTo) const;
- #if defined(OS2DEF_INCLUDED)
- POINTL pointl() const;
- #endif
- double distanceFrom(const IPoint& pt) const;
-
- virtual IString dump() const;
-
- };
-
- /********************************************************/
- /* ISize class */
- /********************************************************/
- class ISize : public IPair
- {
- public:
- ISize ();
- ISize (const IPair& pair);
- ISize (const IPoint& pt);
- ISize ( COORD coordWidth, COORD coordHeight );
- #if defined(GPI_INCLUDED)
- ISize( const SIZEL& sizl);
- #endif
- #if defined(OS2DEF_INCLUDED)
- ISize( const RECTL& rcl);
- #endif
- virtual ~ISize() {}
-
- COORD width() const;
- COORD height() const;
- void setWidth(COORD cx);
- void setHeight(COORD cy);
- COORD sizeX() const;
- COORD sizeY() const;
- #if defined(GPI_INCLUDED)
- SIZEL sizel() const;
- #endif
- virtual IString dump() const;
- };
-
- class IRange : public IPair
- {
- public:
- IRange ();
- IRange (const IPair& pair);
- IRange (COORD coordLower, COORD coordUpper);
- virtual ~IRange() {}
- COORD lower() const;
- COORD upper() const;
- void setWidth(COORD lw);
- void setHeight(COORD up);
- Boolean isInRange(COORD coord) const;
- virtual IString dump() const;
- };
-
-
-
-
- /* IPair Inline Functions */
-
- inline IPair::IPair()
- { coordCl1 = coordCl2 = 0; }
-
- inline IPair::IPair( long lInit)
- { coordCl1 = coordCl2 = lInit; }
-
- inline IPair::IPair(COORD coord1, COORD coord2)
- { coordCl1 = coord1; coordCl2 = coord2; }
-
- inline COORD IPair::coord1() const
- { return ((IPair*)this)->coordCl1;}
-
- inline COORD IPair::coord2() const
- { return ((IPair*)this)->coordCl2;}
-
- inline void IPair::setCoord1(COORD coord1)
- { coordCl1 = coord1;}
-
- inline void IPair::setCoord2(COORD coord2)
- { coordCl2 = coord2;}
-
- inline IPair IPair::operator-() const
- {return IPair(-coordCl1, -coordCl2);}
-
- inline Boolean IPair::operator==(const IPair& pair) const
- {return (coordCl1==pair.coordCl1 &&
- coordCl2==pair.coordCl2); }
-
- inline Boolean IPair::operator!=(const IPair& pair) const
- {return (coordCl1!=pair.coordCl1 ||
- coordCl2!=pair.coordCl2); }
-
- inline Boolean IPair::operator<(const IPair& pair) const
- {return (coordCl1<pair.coordCl1 &&
- coordCl2<pair.coordCl2); }
-
- inline Boolean IPair::operator>(const IPair& pair) const
- {return (coordCl1>pair.coordCl1 &&
- coordCl2>pair.coordCl2); }
-
- inline Boolean IPair::operator<=(const IPair& pair) const
- {return (coordCl1<=pair.coordCl1 &&
- coordCl2<=pair.coordCl2); }
-
- inline Boolean IPair::operator>=(const IPair& pair) const
- {return (coordCl1>=pair.coordCl1 &&
- coordCl2>=pair.coordCl2); }
-
-
-
- inline IPair operator+(IPair pair1, IPair pair2)
- {return IPair(pair1.coord1()+pair2.coord1(),
- pair1.coord2()+pair2.coord2());}
-
- inline IPair operator*(IPair pair1, IPair pair2)
- {return IPair(pair1.coord1()*pair2.coord1(),
- pair1.coord2()*pair2.coord2());}
-
- inline IPair operator*(IPair pair1, double d)
- {return IPair((COORD)(d*pair1.coord1()),
- (COORD)(d*pair1.coord2()));}
-
- inline IPair operator-(IPair pair1, IPair pair2)
- {return IPair(pair1.coord1()-pair2.coord1(),
- pair1.coord2()-pair2.coord2());}
-
- inline IPair operator/(IPair pair1, IPair pair2)
- {return IPair(pair1.coord1()/pair2.coord1(),
- pair1.coord2()/pair2.coord2());}
-
- inline IPair operator/(IPair pair1, double d)
- {return IPair((COORD)(pair1.coord1()/d),
- (COORD)(pair1.coord2()/d));}
-
- inline IPair operator%(IPair pair1, IPair pair2)
- {return IPair(pair1.coord1()%pair2.coord1(),
- pair1.coord2()%pair2.coord2());}
-
-
- /* IPoint Inline Functions */
-
- inline IPoint::IPoint()
- {}
- inline IPoint::IPoint(const IPair& pair)
- : IPair(pair)
- {}
- inline IPoint::IPoint( COORD ptX, COORD ptY )
- : IPair( ptX, ptY )
- {}
-
- #if defined(OS2DEF_INCLUDED)
- inline IPoint::IPoint( const POINTL& ptl)
- : IPair(ptl.x, ptl.y)
- {}
- inline IPoint::IPoint( const RECTL& rcl)
- : IPair(rcl.xLeft, rcl.yBottom)
- {}
- #endif
-
- inline COORD IPoint::x() const
- { return coord1(); }
-
- inline COORD IPoint::y() const
- { return coord2(); }
-
- inline void IPoint::setX(COORD X)
- { setCoord1(X); }
-
- inline void IPoint::setY(COORD Y)
- { setCoord2(Y); }
-
- inline COORD IPoint::pointX() const
- { return coord1(); }
-
- inline COORD IPoint::pointY() const
- { return coord2(); }
-
- /* ISize inline functions */
- inline ISize::ISize () {}
-
- inline ISize::ISize (const IPair& pair) : IPair(pair) {}
-
- inline ISize::ISize (const IPoint& pt) : IPair(pt) {}
- inline ISize::ISize ( COORD coordWidth, COORD coordHeight )
- : IPair( coordWidth, coordHeight ) {}
- #if defined(GPI_INCLUDED)
- inline ISize::ISize( const SIZEL& sizl) : IPair(sizl.cx, sizl.cy) {}
- #endif
- #if defined(OS2DEF_INCLUDED)
- inline ISize::ISize( const RECTL& rcl)
- : IPair(rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom) {}
- #endif
-
- inline COORD ISize::width() const { return coord1(); }
- inline COORD ISize::height() const { return coord2(); }
- inline void ISize::setWidth(COORD cx) { setCoord1(cx); }
- inline void ISize::setHeight(COORD cy){ setCoord2(cy); }
- inline COORD ISize::sizeX() const { return coord1(); }
- inline COORD ISize::sizeY() const { return coord2(); }
-
-
-
- /* IRange Inline Functions */
-
- inline IRange::IRange () : IPair(0,0) {}
- inline IRange::IRange (const IPair& pair) : IPair(pair) {}
- inline IRange::IRange (COORD coordLower, COORD coordUpper)
- : IPair(coordLower, coordUpper) {}
- inline COORD IRange::lower() const {return coord1(); }
- inline COORD IRange::upper() const { return coord2(); }
- inline void IRange::setWidth(COORD lw) { setCoord1(lw); }
- inline void IRange::setHeight(COORD up){ setCoord2(up); }
- inline Boolean IRange :: isInRange(COORD coord) const
- {return (coord>=lower() && coord<=upper());}
-
- /* Conversion functions */
- inline IPoint::IPoint( const ISize& siz)
- : IPair(siz.width(), siz.height()) {}
-
-
- #endif