#include "gtypes.h"

class GRectangle

This class represents a rectangle on the graphics plane and is conventionally used to denote the bounding box for an object.
Constructor
GRectangle()
GRectangle(x, y, width, height) 
Creates a GRectangle object with the specified components.
Methods
getX() Returns the x component of the rectangle.
getY() Returns the y component of the rectangle.
getWidth() Returns the width component of the rectangle.
getHeight() Returns the height component of the rectangle.
isEmpty() Returns true if the rectangle is empty.
contains(pt)
contains(x, y) 
Returns true if the rectangle contains the given point, which may be specified either as a point or as distinct coordinates.
toString() Converts the GRectangle to a string in the form "(x, y, width, height)".

Constructor detail


GRectangle();
GRectangle(double x, double y, double width, double height);
Creates a GRectangle object with the specified components. If these parameters are not supplied, the default constructor sets these fields to 0.

Usage:

GRectangle empty;
GRectangle r(x, y, width, height);

Method detail


double getX();
Returns the x component of the rectangle.

Usage:

double x = r.getX();

double getY();
Returns the y component of the rectangle.

Usage:

double y = pt.getY();

double getWidth();
Returns the width component of the rectangle.

Usage:

double width = r.getWidth();

double getHeight();
Returns the height component of the rectangle.

Usage:

double height = pt.getHeight();

bool isEmpty();
Returns true if the rectangle is empty.

Usage:

if (r.isEmpty()) . . .

bool contains(GPoint pt);
bool contains(double x, double y);
Returns true if the rectangle contains the given point, which may be specified either as a point or as distinct coordinates.

Usage:

if (r.contains(pt)) . . .
if (r.contains(x, y)) . . .

string toString();
Converts the GRectangle to a string in the form "(x, y, width, height)".

Usage:

string str = r.toString();