OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TRect Class Reference

TRect is a mathematical class derived from tagRect. More...

#include <owl/geometry.h>

Inheritance diagram for owl::TRect:
owl::TSplitterIndicator owl::THSplitterIndicator owl::TVSplitterIndicator

Public Member Functions

 TRect ()
 Default constructor that does nothing.
 
 TRect (const tagRECT &rect)
 Copy from an existing rectangle.
 
 TRect (const TRect &rect)
 Copy from an existing rectangle.
 
 TRect (int _left, int _top, int _right, int _bottom)
 Constructor that sets all the values explicitly.
 
 TRect (const TPoint &upLeft, const TPoint &loRight)
 Creates a rectangle with the given top left and bottom right points.
 
 TRect (const TPoint &origin, const TSize &extent)
 Creates a rectangle with its origin (top left) at origin, width at extent.cx, height at extent.cy.
 
void SetNull ()
 Sets the left, top, right, and bottom of the rectangle to 0.
 
void SetEmpty ()
 Empties this rectangle by setting left, top, right, and bottom to 0.
 
void Set (int _left, int _top, int _right, int _bottom)
 Repositions and resizes this rectangle to the given values.
 
void SetWH (int _left, int _top, int w, int h)
 Determines the rectangle, given its upperleft point, width, and height.
 
 operator const TPoint * () const
 Type conversion operators converting the pointer to this rectangle to type pointer to TPoint.
 
 operator TPoint * ()
 Type conversion operators converting the pointer to this rectangle to type pointer to TPoint.
 
bool IsEmpty () const
 Returns true if left >= right or top >= bottom; otherwise, returns false.
 
bool IsNull () const
 Returns true if left, right, top, and bottom are all 0; otherwise, returns false.
 
bool operator== (const TRect &other) const
 Returns true if this rectangle has identical corner coordinates to the other rectangle; otherwise, returns false.
 
bool operator!= (const TRect &other) const
 Returns false if this rectangle has identical corner coordinates to the other rectangle; otherwise, returns true.
 
int Left () const
 Returns the left value.
 
int X () const
 Returns the left value.
 
int Top () const
 Returns the top value.
 
int Y () const
 Returns the top value.
 
int Right () const
 Returns the right value.
 
int Bottom () const
 Returns the bottom value.
 
const TPointTopLeft () const
 Returns the upperleft point.
 
TPointTopLeft ()
 Returns the upperleft point.
 
TPoint TopRight () const
 Returns the upperright point.
 
TPoint BottomLeft () const
 Returns the TPoint object representing the bottom left corner of this rectangle.
 
const TPointBottomRight () const
 Returns the TPoint object representing the bottom right corner of this rectangle.
 
TPointBottomRight ()
 Returns the TPoint object representing the bottom right corner of this rectangle.
 
int Width () const
 Returns the width of this rectangle (right - left).
 
int Height () const
 Returns the height of this rectangle (bottom - top).
 
TSize Size () const
 Returns the size of rectangle.
 
long Area () const
 Returns the area of this rectangle.
 
bool Contains (const TPoint &point) const
 Returns true if the given point lies within this rectangle; otherwise, it returns false.
 
bool Contains (const TRect &other) const
 Returns true if the other rectangle lies on or within this rectangle; otherwise, it returns false.
 
bool Touches (const TRect &other) const
 Returns true if the other rectangle shares any interior points with this rectangle; otherwise, returns false.
 
TRect OffsetBy (int dx, int dy) const
 Returns a rectangle with the corners offset by the given delta values.
 
TRect operator+ (const TSize &size) const
 Returns a rectangle offset positively by the delta values' given sizes.
 
TRect operator- (const TSize &size) const
 Returns a rectangle offset negatively by the delta values' given sizes.
 
TRect MovedTo (int x, int y)
 Moves the upper left point of the rectangle while maintaining the current dimension.
 
TRect InflatedBy (int dx, int dy) const
 Returns a rectangle inflated by the given delta arguments.
 
TRect InflatedBy (const TSize &size) const
 Returns a rectangle inflated by the given delta arguments.
 
TRect Normalized () const
 Returns a normalized rectangle with the top left corner at (Min(left, right), Min(top, bottom)) and the bottom right corner at (Max(left, right), Max(top, bottom)).
 
TRect operator& (const TRect &other) const
 Returns the intersection of this rectangle and the other rectangle.
 
TRect operator| (const TRect &other) const
 Returns the union of this rectangle and the other rectangle.
 
int Subtract (const TRect &other, TRect result[]) const
 Determines the parts of this rect that do not lie within "other" region.
 
TRectNormalize ()
 Normalizes this rectangle by switching the left and right data member values if left > right, and switching the top and bottom data member values if top > bottom.
 
TRectOffset (int dx, int dy)
 Changes this rectangle so its corners are offset by the given delta values.
 
TRectoperator+= (const TSize &delta)
 Changes this rectangle so its corners are offset by the given delta values, delta.x and delta.y.
 
TRectoperator-= (const TSize &delta)
 Changes this rectangle so its corners are offset negatively by the given delta values, delta.x and delta.y.
 
TRectMoveTo (int x, int y)
 Moves the upper left corner of the rectangle to a new location and maintains the current dimension.
 
TRectInflate (int dx, int dy)
 Inflates a rectangle inflated by the given delta arguments.
 
TRectDeflateRect (int dx, int dy)
 
TRectInflate (const TSize &delta)
 Inflates a rectangle inflated by the given delta arguments.
 
TRectDeflateRect (const TSize &delta)
 DLN MFC look-alike.
 
TRectoperator&= (const TRect &other)
 Changes this rectangle to its intersection with the other rectangle.
 
TRectoperator|= (const TRect &other)
 Changes this rectangle to its union with the other rectangle.
 

Detailed Description

TRect is a mathematical class derived from tagRect.

The tagRect struct is defined as

struct tagRECT {
int left;
int top;
int right;
int bottom;
};

TRect encapsulates the properties of rectangles with sides parallel to the x- and y-axes. In ObjectWindows, these rectangles define the boundaries of windows, boxes, and clipping regions. TRect inherits four data members from tagRect left, top, right, and bottom. These represent the top left and bottom right (x, y) coordinates of the rectangle. Note that x increases from left to right, and y increases from top to bottom.

TRect places no restrictions on the relative positions of top left and bottom right, so it is legal to have left > right and top > bottom. However, many manipulations–such as determining width and height, and forming unions and intersections–are simplified by normalizing the TRect objects involved. Normalizing a rectangle means interchanging the corner point coordinate values so that left < right and top < bottom. Normalization does not alter the physical properties of a rectangle. myRect.Normalized creates normalized copy of myRect without changing myRect, while myRect.Normalize changes myRect to a normalized format. Both members return the normalized rectangle.

TRect constructors are provided to create rectangles from either four ints, two TPoint objects, or one TPoint and one TSize object. In the latter case, the TPoint object specifies the top left point (also known as the rectangle's origin) and the TSize object supplies the width and height of the rectangle. Member functions perform a variety of rectangle tests and manipulations. Overloaded << and >> operators allow chained insertion and extraction of TRect objects with streams.

Definition at line 308 of file geometry.h.

Constructor & Destructor Documentation

◆ TRect() [1/6]

owl::TRect::TRect ( )
inline

Default constructor that does nothing.

Definition at line 889 of file geometry.h.

References SetNull().

◆ TRect() [2/6]

owl::TRect::TRect ( const tagRECT & rect)
inline

Copy from an existing rectangle.

Definition at line 1111 of file geometry.h.

◆ TRect() [3/6]

owl::TRect::TRect ( const TRect & rect)
inline

Copy from an existing rectangle.

Definition at line 1120 of file geometry.h.

◆ TRect() [4/6]

owl::TRect::TRect ( int _left,
int _top,
int _right,
int _bottom )
inline

Constructor that sets all the values explicitly.

Definition at line 1129 of file geometry.h.

References Set().

◆ TRect() [5/6]

owl::TRect::TRect ( const TPoint & upLeft,
const TPoint & loRight )
inline

Creates a rectangle with the given top left and bottom right points.

Definition at line 1138 of file geometry.h.

References Set().

◆ TRect() [6/6]

owl::TRect::TRect ( const TPoint & origin,
const TSize & extent )
inline

Creates a rectangle with its origin (top left) at origin, width at extent.cx, height at extent.cy.

Definition at line 1148 of file geometry.h.

References Set().

Member Function Documentation

◆ Area()

long owl::TRect::Area ( ) const
inline

Returns the area of this rectangle.

Definition at line 1066 of file geometry.h.

References Height(), and Width().

◆ Bottom()

int owl::TRect::Bottom ( ) const
inline

Returns the bottom value.

Definition at line 974 of file geometry.h.

◆ BottomLeft()

TPoint owl::TRect::BottomLeft ( ) const
inline

Returns the TPoint object representing the bottom left corner of this rectangle.

Definition at line 1010 of file geometry.h.

◆ BottomRight() [1/2]

TPoint & owl::TRect::BottomRight ( )
inline

Returns the TPoint object representing the bottom right corner of this rectangle.

Definition at line 1030 of file geometry.h.

◆ BottomRight() [2/2]

const TPoint & owl::TRect::BottomRight ( ) const
inline

Returns the TPoint object representing the bottom right corner of this rectangle.

Definition at line 1020 of file geometry.h.

◆ Contains() [1/2]

bool owl::TRect::Contains ( const TPoint & point) const
inline

Returns true if the given point lies within this rectangle; otherwise, it returns false.

If point is on the left vertical or on the top horizontal borders of the rectangle, Contains also returns true, but if point is on the right vertical or bottom horizontal borders, Contains returns false.

Definition at line 1200 of file geometry.h.

References owl::ToBool().

◆ Contains() [2/2]

bool owl::TRect::Contains ( const TRect & other) const
inline

Returns true if the other rectangle lies on or within this rectangle; otherwise, it returns false.

Definition at line 1211 of file geometry.h.

References owl::ToBool().

◆ DeflateRect() [1/2]

TRect & owl::TRect::DeflateRect ( const TSize & delta)
inline

DLN MFC look-alike.

Definition at line 1393 of file geometry.h.

References Inflate().

◆ DeflateRect() [2/2]

TRect & owl::TRect::DeflateRect ( int dx,
int dy )

Definition at line 142 of file geometry.cpp.

References Inflate().

◆ Height()

int owl::TRect::Height ( ) const
inline

Returns the height of this rectangle (bottom - top).

Definition at line 1048 of file geometry.h.

◆ Inflate() [1/2]

TRect & owl::TRect::Inflate ( const TSize & delta)
inline

Inflates a rectangle inflated by the given delta arguments.

The new corners are (left - size.cx, top - size.cy) and (right + size.cx, bottom + size.cy).

Definition at line 1386 of file geometry.h.

References Inflate().

◆ Inflate() [2/2]

TRect & owl::TRect::Inflate ( int dx,
int dy )

Inflates a rectangle inflated by the given delta arguments.

The top left corner of the returned rectangle is (left - dx, top - dy), while its bottom right corner is (right + dx, bottom + dy).

Definition at line 129 of file geometry.cpp.

◆ InflatedBy() [1/2]

TRect owl::TRect::InflatedBy ( const TSize & size) const
inline

Returns a rectangle inflated by the given delta arguments.

The new corners are (left - size.cx, top - size.cy) and (right + size.cx, bottom + size.cy). The calling rectangle object is unchanged.

Definition at line 1292 of file geometry.h.

References InflatedBy().

◆ InflatedBy() [2/2]

TRect owl::TRect::InflatedBy ( int dx,
int dy ) const
inline

Returns a rectangle inflated by the given delta arguments.

The top left corner of the returned rectangle is (left - dx, top - dy), while its bottom right corner is (right + dx, bottom + dy). The calling rectangle object is unchanged.

Definition at line 1281 of file geometry.h.

References TRect().

◆ IsEmpty()

bool owl::TRect::IsEmpty ( ) const
inline

Returns true if left >= right or top >= bottom; otherwise, returns false.

Definition at line 1157 of file geometry.h.

References owl::ToBool().

◆ IsNull()

bool owl::TRect::IsNull ( ) const
inline

Returns true if left, right, top, and bottom are all 0; otherwise, returns false.

Definition at line 1167 of file geometry.h.

References owl::ToBool().

◆ Left()

int owl::TRect::Left ( ) const
inline

Returns the left value.

Definition at line 929 of file geometry.h.

◆ MovedTo()

TRect owl::TRect::MovedTo ( int x,
int y )
inline

Moves the upper left point of the rectangle while maintaining the current dimension.

Todo
This should be const, to indicate that the original rectangle is not modified, just like InflatedBy()

Definition at line 1270 of file geometry.h.

References TRect(), Height(), and Width().

◆ MoveTo()

TRect & owl::TRect::MoveTo ( int x,
int y )
inline

Moves the upper left corner of the rectangle to a new location and maintains the current dimension.

Definition at line 1371 of file geometry.h.

References Height(), and Width().

◆ Normalize()

TRect & owl::TRect::Normalize ( )

Normalizes this rectangle by switching the left and right data member values if left > right, and switching the top and bottom data member values if top > bottom.

Normalize returns the normalized rectangle. A valid but nonnormal rectangle might have left > right or top > bottom or both. In such cases, many manipulations (such as determining width and height) become unnecessarily complicated. Normalizing a rectangle means interchanging the corner point values so that left < right and top < bottom. The physical properties of a rectangle are unchanged by this process.

Definition at line 99 of file geometry.cpp.

References Swap().

◆ Normalized()

TRect owl::TRect::Normalized ( ) const
inline

Returns a normalized rectangle with the top left corner at (Min(left, right), Min(top, bottom)) and the bottom right corner at (Max(left, right), Max(top, bottom)).

The calling rectangle object is unchanged. A valid but nonnormal rectangle might have left > right or top > bottom or both. In such cases, many manipulations (such as determining width and height) become unnecessarily complicated. Normalizing a rectangle means interchanging the corner point values so that left < right and top < bottom. The physical properties of a rectangle are unchanged by this process. Note that many calculations assume a normalized rectangle. Some Windows API functions behave erratically if an inside-out Rect is passed.

Definition at line 1310 of file geometry.h.

References TRect().

◆ Offset()

TRect & owl::TRect::Offset ( int dx,
int dy )

Changes this rectangle so its corners are offset by the given delta values.

The revised rectangle has a top left corner at (left + dx, top + dy) and a right bottom corner at (right + dx, bottom + dy). The revised rectangle is returned.

Definition at line 114 of file geometry.cpp.

◆ OffsetBy()

TRect owl::TRect::OffsetBy ( int dx,
int dy ) const
inline

Returns a rectangle with the corners offset by the given delta values.

The returned rectangle has a top left corner at (left + dx, top + dy) and a right bottom corner at (right + dx, bottom + dy). The calling rectangle object is unchanged

Definition at line 1234 of file geometry.h.

References TRect().

◆ operator const TPoint *()

owl::TRect::operator const TPoint * ( ) const
inline

Type conversion operators converting the pointer to this rectangle to type pointer to TPoint.

Return an array of two points (upperleft and bottomright)

Definition at line 909 of file geometry.h.

◆ operator TPoint *()

owl::TRect::operator TPoint * ( )
inline

Type conversion operators converting the pointer to this rectangle to type pointer to TPoint.

Return an array of two points (upperleft and bottomright)

Definition at line 920 of file geometry.h.

◆ operator!=()

bool owl::TRect::operator!= ( const TRect & other) const
inline

Returns false if this rectangle has identical corner coordinates to the other rectangle; otherwise, returns true.

Definition at line 1188 of file geometry.h.

References owl::ToBool().

◆ operator&()

TRect owl::TRect::operator& ( const TRect & other) const
inline

Returns the intersection of this rectangle and the other rectangle.

The calling rectangle object is unchanged. Returns a NULL rectangle if the two don't intersect.

Definition at line 1322 of file geometry.h.

References TRect(), and Touches().

◆ operator&=()

TRect & owl::TRect::operator&= ( const TRect & other)

Changes this rectangle to its intersection with the other rectangle.

This rectangle object is returned. Returns a NULL rectangle if there is no intersection.

Definition at line 153 of file geometry.cpp.

References IsNull(), and SetNull().

◆ operator+()

TRect owl::TRect::operator+ ( const TSize & size) const
inline

Returns a rectangle offset positively by the delta values' given sizes.

The returned rectangle has a top left corner at (left + size.x, top + size.y) and a right bottom corner at (right + size.x, bottom + size.y). The calling rectangle object is unchanged.

Definition at line 1246 of file geometry.h.

References OffsetBy().

◆ operator+=()

TRect & owl::TRect::operator+= ( const TSize & delta)
inline

Changes this rectangle so its corners are offset by the given delta values, delta.x and delta.y.

The revised rectangle has a top left corner at (left + delta.x, top + delta.y) and a right bottom corner at (right + delta.x, bottom + delta.y). The revised rectangle is returned.

Definition at line 1348 of file geometry.h.

References Offset().

◆ operator-()

TRect owl::TRect::operator- ( const TSize & size) const
inline

Returns a rectangle offset negatively by the delta values' given sizes.

The returned rectangle has a top left corner at (left - size.cx, top - size.cy) and a right bottom corner at (right - size.cx, bottom - size.cy). The calling rectangle object is unchanged.

Definition at line 1258 of file geometry.h.

References OffsetBy().

◆ operator-=()

TRect & owl::TRect::operator-= ( const TSize & delta)
inline

Changes this rectangle so its corners are offset negatively by the given delta values, delta.x and delta.y.

The revised rectangle has a top left corner at (left - delta.x, top - delta.y) and a right bottom corner at (right - delta.x, bottom - delta.y). The revised rectangle is returned.

Definition at line 1361 of file geometry.h.

◆ operator==()

bool owl::TRect::operator== ( const TRect & other) const
inline

Returns true if this rectangle has identical corner coordinates to the other rectangle; otherwise, returns false.

Definition at line 1177 of file geometry.h.

References owl::ToBool().

◆ operator|()

TRect owl::TRect::operator| ( const TRect & other) const
inline

Returns the union of this rectangle and the other rectangle.

The calling rectangle object is unchanged.

Definition at line 1335 of file geometry.h.

References TRect().

◆ operator|=()

TRect & owl::TRect::operator|= ( const TRect & other)

Changes this rectangle to its union with the other rectangle.

This rectangle object is returned.

Definition at line 173 of file geometry.cpp.

References IsNull().

◆ Right()

int owl::TRect::Right ( ) const
inline

Returns the right value.

Definition at line 965 of file geometry.h.

◆ Set()

void owl::TRect::Set ( int _left,
int _top,
int _right,
int _bottom )
inline

Repositions and resizes this rectangle to the given values.

Definition at line 1087 of file geometry.h.

◆ SetEmpty()

void owl::TRect::SetEmpty ( )
inline

Empties this rectangle by setting left, top, right, and bottom to 0.

Definition at line 898 of file geometry.h.

References SetNull().

◆ SetNull()

void owl::TRect::SetNull ( )
inline

Sets the left, top, right, and bottom of the rectangle to 0.

Definition at line 1075 of file geometry.h.

◆ SetWH()

void owl::TRect::SetWH ( int _left,
int _top,
int w,
int h )
inline

Determines the rectangle, given its upperleft point, width, and height.

Definition at line 1099 of file geometry.h.

◆ Size()

TSize owl::TRect::Size ( ) const
inline

Returns the size of rectangle.

Definition at line 1057 of file geometry.h.

References Height(), and Width().

◆ Subtract()

int owl::TRect::Subtract ( const TRect & other,
TRect result[] ) const

Determines the parts of this rect that do not lie within "other" region.

The resulting rectangles are placed in the "result" array. Returns the resulting number of rectangles. This number will be 1, 2, 3, or 4.

Definition at line 194 of file geometry.cpp.

References Touches().

◆ Top()

int owl::TRect::Top ( ) const
inline

Returns the top value.

Definition at line 947 of file geometry.h.

◆ TopLeft() [1/2]

TPoint & owl::TRect::TopLeft ( )
inline

Returns the upperleft point.

Definition at line 992 of file geometry.h.

◆ TopLeft() [2/2]

const TPoint & owl::TRect::TopLeft ( ) const
inline

Returns the upperleft point.

Definition at line 983 of file geometry.h.

◆ TopRight()

TPoint owl::TRect::TopRight ( ) const
inline

Returns the upperright point.

Definition at line 1001 of file geometry.h.

◆ Touches()

bool owl::TRect::Touches ( const TRect & other) const
inline

Returns true if the other rectangle shares any interior points with this rectangle; otherwise, returns false.

Definition at line 1222 of file geometry.h.

References owl::ToBool().

◆ Width()

int owl::TRect::Width ( ) const
inline

Returns the width of this rectangle (right - left).

Definition at line 1039 of file geometry.h.

◆ X()

int owl::TRect::X ( ) const
inline

Returns the left value.

Definition at line 938 of file geometry.h.

◆ Y()

int owl::TRect::Y ( ) const
inline

Returns the top value.

Definition at line 956 of file geometry.h.


The documentation for this class was generated from the following files: