Rect

Defines geometric entity known as a rectangle.

A four-sided plane figure with four right angles.  http://dictionary.com

Operators

  • Rect == Rect
  • ostream& << Rect
Summary
Defines geometric entity known as a rectangle.
Initializes rectangle at (0,0) with size of 0.
Initializing constructor, creates rectangle from top left point, width and height.
Initializing constructor, creates from top left and bottom right points.
Default destructor, exists to make Rect inheritance safe.
move rectangle to new location.
move rectangle relative to current position.
set new size for rectangle.
set new size for rectangle, relative to current size.
Check for intersection between two Rects.
Check for intersection between the Rect and Circle.
Check if a point is contained within the Rect.
Check if another rectangle is entirely contained within the Rect.
calculates & returns the intersection of two rectangles.
Get x coord of rectangle.
Get y coord of rectangle.
Get y coord of top side of rectangle.
Get x coord of left side of rectangle.
Get y coord of bottom side of rectangle.
Get x coord of right side of rectangle.
Get width of rectangle.
Get height of rectangle.
Get top left corner of rectangle.
Get top right corner of rectangle.
Get bottom left corner of rectangle.
Get bottom right corner of rectangle.

(Con/ De)structors

Rect

Rect()

Initializes rectangle at (0,0) with size of 0.

Rect

Rect(const Point2 &topleft,
scalar width,
scalar height)

Initializing constructor, creates rectangle from top left point, width and height.

Parameters

topleftPoint describing top left corner.
widthWidth of new rectangle.
heightHeight of new rectangle.

Rect

Rect(const Point2 &topleft,
const Point2 &bottomright)

Initializing constructor, creates from top left and bottom right points.

Parameters

topleftPoint describing top left corner.
bottomrightPoint describing bottom right corner.

~Rect

virtual ~Rect()

Default destructor, exists to make Rect inheritance safe.

Movement/ Scaling

moveTo

void moveTo(const Point2 &topleft)

move rectangle to new location.

Parameters

topleftPoint describing new top left corner.

moveRel

void moveRel(scalar xMove,
scalar yMove)

move rectangle relative to current position.

Parameters

xMoveDistance to move horizontally.
yMoveDistance to move vertically.

resize

void resize(scalar width,
scalar height)

set new size for rectangle.

Parameters

widthNew width for rectangle.
heightNew height for rectangle.

resizeRel

void resizeRel(scalar widthDelta,
scalar heightDelta)

set new size for rectangle, relative to current size.

Parameters

widthDeltaChange to be applied to width of rectangle.
heightDeltaChange to be applied to height of rectangle.

Geometry

intersects

bool intersects(const Rect &rect) const

Check for intersection between two Rects.

Parameters

rectRect with which to check for intersection.

Returns

True if Rect intersects rect, false otherwise.

intersects

bool intersects(const Circle &circle) const

Check for intersection between the Rect and Circle.

Parameters

circleCircle with which to check for intersection.

Returns

True if Rect intersects circle, false otherwise.

contains

bool contains(const Point2 &point) const

Check if a point is contained within the Rect.

Parameters

pointPoint to check containment of.

Returns

True if Rect contains point, false if not.

contains

bool contains(const Rect &rect) const

Check if another rectangle is entirely contained within the Rect.

Parameters

rectRect to check if the Rect contains.

Returns

True if rect is entirely contained within, false if all or part is outside.

calcIntersection

Rect calcIntersection(const Rect &rect) const

calculates & returns the intersection of two rectangles.

Parameters

rectRectangle to find & calculate area of intersection with.

Returns

Rectangle defining area of intersection between the two rectangles.

If intersects is false, the rectangle will have a width & height of zero.

Accessors

getX

scalar getX() const

Get x coord of rectangle.  (top left corner)

Returns

Returns x coord of top left corner of rectangle.

getY

scalar getY() const

Get y coord of rectangle.  (top left corner)

Returns

Returns y coord of top left corner of rectangle.

getTop

scalar getTop() const

Get y coord of top side of rectangle.

Returns

Returns y coord of top side of rectangle.

getLeft

scalar getLeft() const

Get x coord of left side of rectangle.

Returns

Returns x coord of left side rectangle.

getBottom

scalar getBottom() const

Get y coord of bottom side of rectangle.

Returns

Returns y coord of bottom side of rectangle.

getRight

scalar getRight() const

Get x coord of right side of rectangle.

Returns

Returns x coord of right side rectangle.

getWidth

scalar getWidth() const

Get width of rectangle.

Returns

Returns width of rectangle.

getHeight

scalar getHeight() const

Get height of rectangle.

Returns

Height of rectangle.

getTopLeft

Point2 getTopLeft() const

Get top left corner of rectangle.

Returns

Top left corner of rectangle.

getTopRight

Point2 getTopRight() const

Get top right corner of rectangle.

Returns

Top right corner of rectangle.

getBottomLeft

Point2 getBottomLeft() const

Get bottom left corner of rectangle.

Returns

Bottom left corner of rectangle.

getBottomRight

Point2 getBottomRight() const

Get bottom right corner of rectangle.

Returns

Bottom right corner of rectangle.

Rect()
Initializes rectangle at (0,0) with size of 0.
virtual ~Rect()
Default destructor, exists to make Rect inheritance safe.
void moveTo(const Point2 &topleft)
move rectangle to new location.
void moveRel(scalar xMove,
scalar yMove)
move rectangle relative to current position.
void resize(scalar width,
scalar height)
set new size for rectangle.
void resizeRel(scalar widthDelta,
scalar heightDelta)
set new size for rectangle, relative to current size.
bool intersects(const Rect &rect) const
Check for intersection between two Rects.
Defines geometric entity known as a circle.
bool contains(const Point2 &point) const
Check if a point is contained within the Rect.
Rect calcIntersection(const Rect &rect) const
calculates & returns the intersection of two rectangles.
scalar getX() const
Get x coord of rectangle.
scalar getY() const
Get y coord of rectangle.
scalar getTop() const
Get y coord of top side of rectangle.
scalar getLeft() const
Get x coord of left side of rectangle.
scalar getBottom() const
Get y coord of bottom side of rectangle.
scalar getRight() const
Get x coord of right side of rectangle.
scalar getWidth() const
Get width of rectangle.
scalar getHeight() const
Get height of rectangle.
Point2 getTopLeft() const
Get top left corner of rectangle.
Point2 getTopRight() const
Get top right corner of rectangle.
Point2 getBottomLeft() const
Get bottom left corner of rectangle.
Point2 getBottomRight() const
Get bottom right corner of rectangle.