Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Phx::Rectangle< T > Class Template Reference

A class representing a 2D rectangle by two points. More...

#include <PhxRectangle.h>

List of all members.

Public Member Functions

 Rectangle (T x0, T y0, T x1, T y1)
x0 (void) const
y0 (void) const
x1 (void) const
y1 (void) const
left (void) const
right (void) const
top (void) const
bottom (void) const
width (void) const
height (void) const
void x0 (T x0)
void y0 (T y0)
void x1 (T x1)
void y1 (T y1)
area (void) const
 Returns the area of this rectangle.
perimeter (void) const
 Returns the perimeter of this rectangle.
bool empty (void) const
 Returns whether this rectangle is empty.
Rectangle intersection (const Rectangle &R) const
 Returns the "intersection" of two rectangles.
Rectangle cover (const Rectangle &R) const
 Returns the smallest rectangle containing two rectangles.
bool operator== (const Rectangle &r)
 Compares another rectangle with this one for equality.


Detailed Description

template<typename T = double>
class Phx::Rectangle< T >

A class representing a 2D rectangle by two points.

The rectangle is represented by two corner points (x0,y0) and (x1,y1). The corners may be at any location, and the width, height, and area of the rectangle is always considered to be positive. The "left" side of the rectangle is defined to be the minimum of x1 and x1; the "right" side is the maximum. The "top" of the rectangle is defined as the maximum of y0 and y1, and the "bottom" is the minimum. This choice of top and bottom is the opposite of some GUI/screen coordinate systems.

The template parameter is optional, allowing rectangles of different coordinate base types (e.g., one could have a rectangle with int-type coordinates). The default is double. Other types may be used, provided they support the appropriate arithmetic operations (addition, subtraction, multiplication, division) and comparison (less-than comparable). The type must also allow initialization to '0' for default construction.


Member Function Documentation

template<typename T = double>
T Phx::Rectangle< T >::area void   )  const [inline]
 

Returns the area of this rectangle.

Returns:
width()*height().

template<typename T = double>
Rectangle Phx::Rectangle< T >::cover const Rectangle< T > &  R  )  const [inline]
 

Returns the smallest rectangle containing two rectangles.

The returned rectangle is the smallest rectangle that includes the area in this rectangle and the rectangle R. This is the "cover" for two rectangles (it doesn't precisely correspond to the mathematical definition of a cover).

Parameters:
R The other rectangle that must be contained within the rectangle returned.
Returns:
The smallest rectangle that includes the area bounded by both R and *this.

template<typename T = double>
bool Phx::Rectangle< T >::empty void   )  const [inline]
 

Returns whether this rectangle is empty.

The rectangle is "empty" if its area is identically 0.

Returns:
(width() == 0) || (height() == 0).

template<typename T = double>
Rectangle Phx::Rectangle< T >::intersection const Rectangle< T > &  R  )  const [inline]
 

Returns the "intersection" of two rectangles.

The intersection of two disjoint rectangles is a zero-area rectangle. If the rectangles are disjoint along one axis, then the coordinates of the "intersection" on that axis are the mid-point between the nearest edges. e.g., if the right side of rectangle A is 0 and the left side of B is 1.0, then for C = A.intersection(B), we have C.x0() = C.x1() = 0.5. This ensures that C.area() is zero but that the intersection is a well-defined symmetric function of A and B.

Parameters:
R The rectangle to intersect with this.
Returns:
The intersection of this rectangle with R if the rectangles overlap. See the comment above about disjoint rectangles.

template<typename T = double>
bool Phx::Rectangle< T >::operator== const Rectangle< T > &  r  )  [inline]
 

Compares another rectangle with this one for equality.

Parameters:
r The rectangle to compare with.
Returns:
true precisely when r and *this have the same coordinates for x0,x1,y0,y1 (which is different from their having the same boundary).

template<typename T = double>
T Phx::Rectangle< T >::perimeter void   )  const [inline]
 

Returns the perimeter of this rectangle.

Returns:
width()*2 + height()*2.


The documentation for this class was generated from the following file:
Generated on Mon Jul 10 19:45:30 2006 for Phoenix OSFS by  doxygen 1.4.2