The IRectangle class represents a rectangular area defined by two points that form opposite corners of the rectangle. These two points are referred to as the minimum and maximum points.
IRectangle objects are usable independently of the coordinate system in use. The minimum, or origin, is defined as the point with the lowest coordinate values. Therefore, in a coordinate space where 0,0 is the top-left corner and increasing a point's coordinate value moves it to the right and down, the minimum point of an IRectangle will be the top-left corner and the maximum corner the bottom-right corner. Conversely, in a coordinate space where 0,0 is the bottom-left corner and increasing a point's coordinate value moves it to the right and up, the minimum corner of an IRectangle will be the bottom left, and the maximum corner the top right.
IRectangle provides some member functions that use the terms "right," "left," "top," and "bottom." These are synonyms for the functions defined in terms of minimum and maximum corners. The directional orientation for the right, left, top, and bottom functions is correct for a coordinate space where 0,0 is the lower-left corner. For other coordinate systems, left and bottom are the sides of the rectangle with the lowest coordinate value, and top and right the sides with the highest.
Mathematically, a rectangle includes all the points on the lines that intersect its minimum corner. It does not include the points that lie on its edges that do not intersect the origin. This is important when you are doing detailed graphics work. For example, a rectangle specified as having a minimum of 0,0 and maximum of 10,20 will include the points 0,0 though 0,19 but will not include 0,20. Similarly, the points 1,0 through 9,0 are contained, but 10,0 is not.
Various graphics and windowing classes, as well as their member functions, use rectangles.
You can also construct objects of this class by providing a Presentation Manager Toolkit RECTL structure.
You can also construct objects of this class by providing Windows toolkit RECT or RECTL structures.
Constructors & Destructor
You can construct, copy, and assign objects of this
class.
Note:
![]() |
public:
IRectangle( Coord point1X, Coord point1Y, Coord point2X, Coord point2Y )
Constructs a rectangle from four values representing coordinates of the corners.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle(const IPoint& point1, const IPoint& point2)
Constructs a rectangle from two points at opposite corners.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle(const struct _RECTL& rectl)
Constructs a rectangle from a PM toolkit RECTL structure.
| Windows | OS/2 | AIX |
| Yes | Yes | No |
public:
IRectangle(const IPair& pair)
Constructs a rectangle with corners at 0,0 and the specified location. The lower of aPair and 0,0 will be the origin of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle(const struct tagRECT& rect)
Constructs a rectangle from a Windows toolkit RECT structure.
| Windows | OS/2 | AIX |
| Yes | No | No |
public:
IRectangle(Coord width, Coord height)
Constructs a rectangle of the specified size. The size is specified as follows:
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle(const IPoint& point, const ISize& size)
Creates a rectangle from a point and size. The maximum point is calculated by adding the width of the size to the X-coordinate of the given point and adding the height of the size to the Y-coordinate of the given point.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle()
Constructs a rectangle at (0,0),(0,0).
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
ComparisonsUse these members to compare two rectangles for equality or inequality.
![]() |
public:
bool operator !=(const IRectangle& rectangle) const
If the rectangles differ, true is returned.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool operator ==(const IRectangle& rectangle) const
If the two rectangles are identical, true is returned. Identity of rectangles means that the two defining points are the same.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
ConversionsUse these members to convert a rectangle into various formats.
![]() |
public:
IString asDebugInfo() const
Renders the rectangle as a diagnostic representation.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
struct _RECTL asRECTL() const
Converts the rectangle into a system-dependent structure.
| Windows | OS/2 | AIX |
| Yes | Yes | No |
Renders the rectangle as a Presentation Manager Toolkit RECTL structure.
Renders the rectangle as a Windows toolkit RECTL structure.
![]() |
public:
IString asString() const
Renders the rectangle as an IString("IRectangle(x1,y1,x2,y2)").
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
DimensionsUse these members to obtain information about a rectangle's size.
![]() |
public:
Coord area() const
Returns the area of the rectangle. The area is determined by multiplying the width of the rectangle by the height. For example, a rectangle defined from IPoint(1,1), IPoint(10,20) would have an area of 9*19, or 171.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord height() const
Returns the height of the rectangle. The height is determined by subtracting the Y-coordinate of the minimum point from the Y-coordinate of the maximum point.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord maxX() const
Returns the X-coordinate of the vertical line that is opposite the origin of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord maxY() const
Returns the Y-coordinate of the horizontal line opposite the origin.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord minX() const
Returns the X-coordinate of the vertical line that passes though the origin.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord minY() const
Returns the Y-coordinate of the horizontal line that passes though the origin of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
ISize size() const
Returns the ISize(width, height).
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord width() const
Returns the width of the rectangle. The width is determined by subtracting the X-coordinate of the minimum point from the X-coordinate of the maximum point.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
ImplementationThese members are used internally to implement the class.
![]() |
protected:
IRectangle& validate()
Corrects an invalid rectangle after creation, expansion,
or intersection.
Note:
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
ManipulationUse these members to modify the rectangle, changing its size, proportions, or location.
![]() |
public:
IRectangle& centerAt(const IPoint& point)
Moves the rectangle so that its center is at the specified point.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle centeredAt(const IPoint& point) const
Same as centerAt, but returns a new rectangle, leaving the original unmodified.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Moves the corners of the rectangle outward from the center by the specified amount. The specified amount can be either a scalar (long integer) or a point.
public:
IRectangle& expandBy(const IPair& pair)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& expandBy(Coord coord)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Same as expandBy, but returns a new rectangle, leaving the original unmodified.
public:
IRectangle expandedBy(const IPair& pair) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle expandedBy(Coord coord) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle& moveBy(const IPair& pair)
Moves the rectangle by the amount specified by aPair.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle movedBy(const IPair& pair) const
Same as moveBy, but returns a new rectangle, leaving the original unmodified.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle movedTo(const IPoint& point) const
Same as moveTo, but returns a new rectangle, leaving the original unmodified.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle& moveTo(const IPoint& point)
Moves the rectangle so that its origin corner is at the specified point.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Scales the rectangle by the specified amount. Scaling a rectangle multiplies its coordinates by the scale amount.
public:
IRectangle& scaleBy(const IPair& pair)
Scales by a point specifying the amounts in the X-axis and Y-axis directions.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& scaleBy(double xfactor, double yfactor)
Scales by a pair of doubles. The function uses the first double to scale in the X-axis direction; the second in the Y-axis direction.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& scaleBy(Coord coord)
Scales by a long integer value.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& scaleBy(double factor)
Scales by a double value.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Same as scaleBy, but returns a new rectangle, leaving the original unmodified.
public:
IRectangle scaledBy(double factor) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle scaledBy(const IPair& pair) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle scaledBy(Coord coord) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle scaledBy(double xfactor, double yfactor) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Moves the corners of the rectangle inward toward the center
by the specified amount, either a scalar or a point.
Note:
public:
IRectangle& shrinkBy(const IPair& pair)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& shrinkBy(Coord coord)
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Same as shrinkBy, but returns a new rectangle, leaving the original unmodified.
public:
IRectangle shrunkBy(const IPair& pair) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle shrunkBy(Coord coord) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
Scales the rectangle by the specified value, leaving the rectangle at the same location because the bottom-left point remains fixed.
public:
IRectangle& sizeBy(double factor)
Scales by the same double factor in both the X-axis and Y-axis directions.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& sizeBy(double xfactor, double yfactor)
Scales by two doubles specifying factors in the X-axis and Y-axis directions, respectively.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& sizeBy(Coord factor)
Scales by the same integer factor in both the X-axis and Y-axis directions.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle& sizeBy(const IPair& pair)
Scales by a pair of integer scalars specifying different factors in the X-axis and Y-axis directions.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle sizedBy(double factor) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle sizedBy(const IPair& pair) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle sizedBy(Coord factor) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
IRectangle sizedBy(double xfactor, double yfactor) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle sizedTo(const IPair& pair) const
Same as sizeTo, but returns a new rectangle, leaving the original unmodified.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle& sizeTo(const IPair& pair)
Sizes the rectangle to the specified size.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
Manipulation OperatorsUse these members to find a rectangle's union and intersection with another rectangle.
![]() |
public:
IRectangle operator &(const IRectangle& rectangle) const
Returns a rectangle representing the intersection of the specified rectangles.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle& operator &=(const IRectangle& rectangle)
Resets the rectangle to its intersection with the specified rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle operator |(const IRectangle& rectangle) const
Returns the rectangle representing the union of the specified rectangles. This is the smallest rectangle that encompasses both specified rectangles.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IRectangle& operator |=(const IRectangle& rectangle)
Resets the rectangle to its union with the specified rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
PointsUse these members to access points on or within the rectangle. You can query any of nine points on a rectangle's perimeter or its center by using these members.
![]() |
public:
IPoint centerXCenterY() const
Returns the X- and Y-coordinates of the center point of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint centerXMaxY() const
Returns the X- and Y-coordinates of the center point of the horizontal line opposite the origin of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint centerXMinY() const
Returns the X- and Y-coordinates of the center point of the horizontal line passing through the origin of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint maxXCenterY() const
Returns the X- and Y-coordinates of the center point of the vertical line opposite the origin of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint maxXMaxY() const
Returns the X- and Y-coordinates of the corner of the rectangle opposite the origin.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint maxXMinY() const
Returns the X- and Y-coordinates of the corner of the rectangle at the other end of the horizontal line passing though the origin.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint minXCenterY() const
Returns the X- and Y-coordinates of the center of the vertical line that passes through the origin.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint minXMaxY() const
Returns the X- and Y-coordinates of the corner of the rectangle at the other end of the vertical line passing though the origin.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint minXMinY() const
Returns the X- and Y-coordinates of the origin corner of the rectangle.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
SynonymsUse these members when you are working in a coordinate space where 0,0 is the bottom-left corner. In this case the right-left-top-bottom orientation is correct. You can still use these members in other coordinate systems, but left and bottom are the sides of the rectangle with the lowest coordinate value, and top and right are the sides with the highest.
The following table lists the members and synonyms defined for them:
![]() |
public:
Coord bottom() const
Returns the Y-coordinate of the horizontal line that forms the bottom of the rectangle. This is an alias for minY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint bottomCenter() const
Returns the X- and Y-coordinates of the bottom-center point of the rectangle. This is an alias for centerXMinY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint bottomLeft() const
Returns the X- and Y-coordinates of the bottom-left corner of the rectangle This is an alias for minXMinY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint bottomRight() const
Returns the X- and Y-coordinates of the bottom-right corner of the rectangle. This is an alias for maxXMinY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint center() const
Returns the X- and Y-coordinates of the center point of the rectangle. This is an alias for centerXCenterY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord left() const
Returns the X-coordinate of the vertical line that forms the left side of the rectangle. This is an alias for minX.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint leftCenter() const
Returns the X- and Y-coordinates of the left-center point of the rectangle. This is an alias for minXCenterY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord right() const
Returns the X-coordinate of the vertical line that forms the right side of the rectangle. This is an alias for maxX.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint rightCenter() const
Returns the X- and Y-coordinates of the right-center point of the rectangle. This is an alias for maxXCenterY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
Coord top() const
Returns the Y-coordinate of the horizontal line that forms the top of the rectangle. This is an alias for maxY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint topCenter() const
Returns the X- and Y-coordinates of the top-center point of the rectangle. This is an alias for centerXMaxY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint topLeft() const
Returns the X- and Y-coordinates of the top-left corner of the rectangle. This is an alias for minXMaxY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPoint topRight() const
Returns the X- and Y-coordinates of the top-right corner of the rectangle. This is an alias for maxXMaxY.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
TestingUse these members to test various attributes of a rectangle.
![]() |
If the rectangle contains the specified point or rectangle, true is returned. A point is contained by a rectangle if its coordinates are greater than or equal to the minimum point of the rectangle and less than the maximum point. A rectangle is contained within another rectangle if its minimum point is greater than or equal to the containing rectangle's minimum point and its maximum point is less than or equal to the containing rectangle's maximum point.
public:
bool contains(const IPoint& point) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
public:
bool contains(const IRectangle& rectangle) const
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
bool intersects(const IRectangle& rectangle) const
If the rectangle and specified rectangle overlap, true is returned.
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
typedef IPair::Coord Coord
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
ostream& operator <<(ostream& stream, const IRectangle& rectangle)