Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

TRectangle Class Reference

Describes a rectangle in the plane. More...

#include <rectangle.h>

List of all members.

Public Methods

 TRectangle (double x=0, double y=0, double w=0, double h=0)
 TRectangle (const TPoint &TopLeft, const TPoint &Size)
bool Contains (double x, double y, bool proper=false) const
bool Contains (const TPoint &Point, bool proper=false) const
double GetBottom () const
TPoint GetCenter () const
double GetHeight () const
int GetIntersectionPoints (const TLine &line, TPoint *one, TPoint *two) const
double GetLeft () const
double GetRight () const
TPoint GetSize () const
double GetTop () const
double GetWidth () const
double GetX () const
double GetY () const
bool Intersects (const TRectangle &r) const
bool IsValid () const
void MoveBy (double dx, double dy)
void MoveByX (double dx)
void MoveByY (double dy)
void MoveTo (double x, double y)
void MoveToX (double x)
void MoveToY (double y)
TRectangle Normalize () const
void SetBottom (double b)
void SetHeight (double h)
void SetLeft (double l)
void SetRect (double x, double y, double w, double h)
void SetRight (double r)
void SetSize (double w, double h)
void SetSize (const TPoint &Size)
void SetTop (double t)
void SetWidth (double w)
void SetX (double x)
void SetY (double y)
ostream & Write (ostream &Stream) const

Protected Attributes

double x1
double y1
double x2
double y2


Detailed Description

Describes a rectangle in the plane.

Author:
Marco Krohn, <marco.krohn@gmx.de>
Version:
Id:
rectangle.h,v 1.2 2001/10/31 19:52:12 mkrohn5 Exp
See also:
TPoint
The default coordinate system has origin (0,0) in the top left corner, the positive direction of the y axis is downwards and the positive x axis is from the left to the right. In contary to many other rectangle classes TRectangle uses double values for the representation of the rectangle.


Constructor & Destructor Documentation

TRectangle::TRectangle double    x = 0,
double    y = 0,
double    w = 0,
double    h = 0
 

Constructor for a rectangle with the top left corner at (x, y), the width w and the height h.

Parameters:
x  is the x-coordinate of the top left corner.
y  is the y-coordinate of the top left corner.
w  is the width of the rectangle.
h  is the height of the rectangle.

TRectangle::TRectangle const TPoint   TopLeft,
const TPoint   Size
 

Constructs a rectangle with topLeft as the top left corner and size as the rectangle size.

Parameters:
TopLeft  is the top left corner.
Size  is the size of the rectangle.


Member Function Documentation

bool TRectangle::Contains const TPoint   Point,
bool    proper = false
const
 

Checks whether or not this Rectangle contains the point (x, y). If the rectangle is not valid (see IsValid) the result is always false.

Parameters:
Point  contains the coordinates of the point.
proper  If proper is true, this function returns true only if p is inside (not on the edge).
Returns:
true in case the point is inside or on the edge of the rectangle. Otherwise returns false.
See also:
TRectangle::Intersects

bool TRectangle::Contains double    x,
double    y,
bool    proper = false
const
 

Checks whether or not this rectangle contains the point (x, y). If the rectangle is not valid (see IsValid()) the result is always false.

Parameters:
x  is the x-coordinate of the point.
y  is the y-coordinate of the point.
proper  If proper is true, this function returns true only if p is inside (not on the edge).
Returns:
true in case the point is inside or on the edge of the rectangle. Otherwise returns false.
See also:
TRectangle::Intersects

double TRectangle::GetBottom   const
 

Returns:
Returns the right coordinate.
See also:
TRectangle::GetTop

TPoint TRectangle::GetCenter   const
 

Returns:
Returns the center point of the rectangle, that is (x1+x2)/2, (y1+y2)/2.

double TRectangle::GetHeight   const
 

Returns:
Returns the height of the rectangle. Note that a non valid rectangle has negative height.
See also:
TRectangle::GetWidth, TRectangle::IsValid

int TRectangle::GetIntersectionPoints const TLine   line,
TPoint   one,
TPoint   two
const
 

FIXME Note: does only work for valid rectangles.

double TRectangle::GetLeft   const
 

Returns:
Returns the left coordinate. Identical to GetX().
See also:
TRectangle::GetRight, TRectangle::GetX

double TRectangle::GetRight   const
 

Returns:
Returns the right coordinate.
See also:
TRectangle::GetLeft

TPoint TRectangle::GetSize   const
 

Returns:
The size of the rectangle.
See also:
TRectangle::GetWidth, TRectangle::GetHeight

double TRectangle::GetTop   const
 

Returns:
Returns the top coordinate. Identical to GetY().
See also:
TRectangle::GetBottom, TRectangle::GetY

double TRectangle::GetWidth   const
 

Returns:
Returns the width of the rectangle. Note that a non valid rectangle has negative width.
See also:
TRectangle::GetHeight, TRectangle::IsValid

double TRectangle::GetX   const
 

Returns:
Returns the left coordinate. Identical to GetLeft().

double TRectangle::GetY   const
 

Returns:
Returns the top coordinate. Identical to GetTop().

bool TRectangle::Intersects const TRectangle &    r const
 

Parameters:
r  is the second rectangle.
Returns:
Returns true if this rectangle intersects with r (that means if there is at least one point which belongs to both rectangles).

bool TRectangle::IsValid   const
 

A valid rectangle has a left() <= right() and top() <= bottom().

Returns:
true if the rectangle is valid, or false if it is invalid.

void TRectangle::MoveBy double    dx,
double    dy
 

Moves the rectangle dx along the X axis and dy along the Y axis, relative to the current position (Positive values moves the rectangle rightwards and/or downwards). The size of the rectangle does not change.

Parameters:
dx  is the relative movement in x direction.
dy  is the relative movement in y direction.
See also:
TRectangle::MoveByX, TRectangle::MoveByY, TRectangle::MoveTo

void TRectangle::MoveByX double    dx
 

Moves the rectangle dx along the X axis, relative to the current position. The size of the rectangle does not change.

Parameters:
dx  is the relative movement in x direction.
See also:
TRectangle::MoveBy, TRectangle::MoveByY, TRectangle::MoveToX

void TRectangle::MoveByY double    dy
 

Moves the rectangle dy along the Y axis, relative to the current position. The size of the rectangle does not change.

Parameters:
dy  is the relative movement in y direction.
See also:
TRectangle::MoveBy, TRectangle::MoveByX, TRectangle::MoveToY

void TRectangle::MoveTo double    x,
double    y
 

Moves the rectangle (or more precise the top left corner) to the absolute position (x, y) without changing the size of the rectangle.

Parameters:
x  is the new x position (left coordinate).
y  is the new y position (bottom coordinate).
See also:
TRectangle::MoveBy, TRectangle::MoveToX, TRectangle::MoveToY

void TRectangle::MoveToX double    x
 

Moves the rectangle (or more precise the top left corner) to the absolute position x without changing the size of the rectangle.

Parameters:
x  is the new x position (left coordinate).
See also:
TRectangle::MoveByX, TRectangle::MoveTo, TRectangle::MoveToY

void TRectangle::MoveToY double    y
 

Moves the rectangle (or more precise the top left corner) to the absolute position y without changing the size of the rectangle.

Parameters:
y  is the new y position (left coordinate).
See also:
TRectangle::MoveByY, TRectangle::MoveTo, TRectangle::MoveToX

TRectangle TRectangle::Normalize   const
 

Returns:
A normalized rectangle, i.e. one that has a non-negative width and height. It swaps left and right if GetLeft() > GetRight(), and swaps top and bottom if GetTop() > GetBottom().
See also:
TRectangle::isValid

void TRectangle::SetBottom double    b
 

Sets the bottom edge of the rectangle. May change the height, but will never change the top edge of the rectangle.

Parameters:
b  is the new bottom position.
See also:
TRectangle::GetBottom, TRectangle::SetTop, TRectangle::SetHeight

void TRectangle::SetHeight double    h
 

Sets the height of the rectangle to h. The top edge is not moved, but the bottom edge may be moved.

See also:
TRectangle::GetHeight, TRectangle::SetTop, TRectangle::SetBottom, TRectangle::SetSize

void TRectangle::SetLeft double    l
 

Sets the left edge of the rectangle. May change the width, but will never change the right edge of the rectangle. Identical to SetX().

Parameters:
l  the new value for the left edge.
See also:
TRectangle::GetLeft, TRectangle::SetTop, TRectangle::SetWidth

void TRectangle::SetRect double    x,
double    y,
double    w,
double    h
 

Sets the coordinates of the rectangle's top left corner to (x,y), and its size to (w,h).

void TRectangle::SetRight double    r
 

Sets the right edge of the rectangle. May change the width, but will never change the left edge of the rectangle.

See also:
TRectangle::GetRight, TRectangle::SetLeft, TRectangle::SetWidth

void TRectangle::SetSize const TPoint   Size
 

Sets the size of the rectangle to (Size.GetX(), Size.GetY()). The top left corner is not moved.

Parameters:
Size  which determines the size of the rectangle.
See also:
TRectangle::GetSize, TRectangle::SetWidth, TRectangle::SetHeight

void TRectangle::SetSize double    w,
double    h
 

Sets the size of the rectangle to (w, h). The top left corner is not moved.

Parameters:
w  is the width.
h  is the height.
See also:
TRectangle::GetSize, TRectangle::SetWidth, TRectangle::SetHeight

void TRectangle::SetTop double    t
 

Sets the top edge of the rectangle. May change the height, but will never change the bottom edge of the rectangle.

Parameters:
t  the new value for the left edge.

void TRectangle::SetWidth double    w
 

Sets the width of the rectangle to w. The right edge is changed, but not the left edge.

Parameters:
w  the new width.

void TRectangle::SetX double    x
 

Sets the x position of the rectangle (its left end). May change the width, but will never change the right edge of the rectangle. Identical to SetLeft().

See also:
TRectangle::GetX, TRectangle::SetY

void TRectangle::SetY double    y
 

Sets the y position of the rectangle (its top). May change the height, but will never change the bottom edge of the rectangle. Identical to SetTop().

See also:
TRectangle::GetX, TRectangle::SetY

ostream& TRectangle::Write ostream &    Stream const
 

Writes the current rectangle to a stream, using the following output format: (x1, y1, x2, y2).

Parameters:
Stream  is the output stream.
Returns:
a reference to the new stream.


The documentation for this class was generated from the following file:
Generated on Thu Jun 20 18:13:30 2002 for Stellar Legacy by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001