SGL
Public Member Functions | Public Attributes | List of all members
GRectangle Struct Reference

This struct contains real-valued x, y, width, and height fields. More...

#include "gtypes.h"

Public Member Functions

 GRectangle(double x=0, double y=0, double width=0, double height=0)
 Creates a GRectangle object with the specified position and size. More...
 
 GRectangle(double x, double y, const GDimension &size)
 Creates a GRectangle object with the specified position and size. More...
 
 GRectangle(const GPoint &p, double width=0, double height=0)
 Creates a GRectangle object with the specified position and size. More...
 
 GRectangle(const GPoint &p, const GDimension &size)
 Creates a GRectangle object with the specified position and size. More...
 
bool contains(double x, double y) const
 Returns true if the rectangle contains the given point. More...
 
bool contains(const GPoint &pt) const
 Returns true if the rectangle contains the given point. More...
 
bool contains(const GRectangle &rect) const
 Returns true if this rectangle contains the given rectangle entirely. More...
 
GRectangle enlargedBy(double amount)
 Returns a new rectangle with its boundaries shifted outward by the given amount on all 4 sides. More...
 
bool intersects(const GRectangle &other) const
 Returns true if this rectangle and the given other rectangle overlap. More...
 
bool isEmpty() const
 Returns true if the rectangle is empty, meaning that it has a width and height that are both 0 or negative. More...
 
string toString() const
 Converts the GRectangle to a string in the form "(</code><i>x</i><code>,</code>&nbsp;<i>y</i><code>,</code> <i>width</i><code>,</code>&nbsp;<i>height</i><code>)". More...
 

Public Attributes

double height
 
double width
 
double x
 
double y
 

Detailed Description

This struct contains real-valued x, y, width, and height fields.

It is used to represent the bounding box of a graphical object.

Constructor & Destructor Documentation

◆ GRectangle() [1/4]

GRectangle ( double  x = 0,
double  y = 0,
double  width = 0,
double  height = 0 
)

Creates a GRectangle object with the specified position and size.

If these parameters are not supplied, the constructor sets these fields to 0.

◆ GRectangle() [2/4]

GRectangle ( double  x,
double  y,
const GDimension size 
)

Creates a GRectangle object with the specified position and size.

If these parameters are not supplied, the constructor sets these fields to 0.

◆ GRectangle() [3/4]

GRectangle ( const GPoint p,
double  width = 0,
double  height = 0 
)

Creates a GRectangle object with the specified position and size.

If these parameters are not supplied, the constructor sets these fields to 0.

◆ GRectangle() [4/4]

GRectangle ( const GPoint p,
const GDimension size 
)

Creates a GRectangle object with the specified position and size.

If these parameters are not supplied, the constructor sets these fields to 0.

Member Function Documentation

◆ contains() [1/3]

bool contains ( double  x,
double  y 
) const

Returns true if the rectangle contains the given point.

◆ contains() [2/3]

bool contains ( const GPoint pt) const

Returns true if the rectangle contains the given point.

◆ contains() [3/3]

bool contains ( const GRectangle rect) const

Returns true if this rectangle contains the given rectangle entirely.

◆ enlargedBy()

GRectangle enlargedBy ( double  amount)

Returns a new rectangle with its boundaries shifted outward by the given amount on all 4 sides.

e.g. a 10x10 rectangle at position (55, 42) enlarged by 1 will become a 12x12 rectangle at position (54, 41).

◆ intersects()

bool intersects ( const GRectangle other) const

Returns true if this rectangle and the given other rectangle overlap.

◆ isEmpty()

bool isEmpty ( ) const

Returns true if the rectangle is empty, meaning that it has a width and height that are both 0 or negative.

◆ toString()

string toString ( ) const

Converts the GRectangle to a string in the form "(</code><i>x</i><code>,</code>&nbsp;<i>y</i><code>,</code> <i>width</i><code>,</code>&nbsp;<i>height</i><code>)".

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const GRectangle r1,
const GRectangle r2 
)
friend

Compares two rectangles for inequality.

◆ operator<

bool operator< ( const GRectangle r1,
const GRectangle r2 
)
friend

Relational operators that compare rectangles by x, y, then width, then height.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const GRectangle rect 
)
friend

Writes the given rectangle to the given output stream.

◆ operator<=

bool operator<= ( const GRectangle r1,
const GRectangle r2 
)
friend

Relational operators that compare rectangles by x, y, then width, then height.

◆ operator==

bool operator== ( const GRectangle r1,
const GRectangle r2 
)
friend

Compares two rectangles for equality.

◆ operator>

bool operator> ( const GRectangle r1,
const GRectangle r2 
)
friend

Relational operators that compare rectangles by x, y, then width, then height.

◆ operator>=

bool operator>= ( const GRectangle r1,
const GRectangle r2 
)
friend

Relational operators that compare rectangles by x, y, then width, then height.

Member Data Documentation

◆ height

double height

◆ width

double width

◆ x

double x

◆ y

double y