lab_inheritance
Insidious Inheritance
 All Classes Namespaces Files Functions Variables
Rectangle Class Reference

A subclass of Shape that represents a rectangle in 2D space. More...

#include <rectangle.h>

Inheritance diagram for Rectangle:
[legend]
Collaboration diagram for Rectangle:
[legend]

Public Member Functions

 Rectangle (const Vector2 &center, const cs225::HSLAPixel &color, int width, int height)
 Constructs a new Rectangle with the given center, color, height, and width. More...
 
int area () const
 Computes and returns the area of the Rectangle in pixels. More...
 
int perimeter () const
 Computes and returns the perimeter of the Rectangle in pixels. More...
 
bool contains (const Vector2 &p) const
 Checks to see if the given Vector2 p is inside of the Rectangle. More...
 
void draw (cs225::PNG *canvas) const
 Draws the Rectangle onto the canvas. More...
 
int width () const
 Gets the width of the Rectangle in pixels. More...
 
void set_width (int width)
 Sets the width of the Rectangle in pixels. More...
 
int height () const
 Gets the height of the Rectangle in pixels. More...
 
void set_height (int height)
 Sets the height of the Rectangle in pixels. More...
 
- Public Member Functions inherited from Shape
 Shape ()
 Constructs a new Shape with a default color and center. More...
 
 Shape (const Vector2 &center, const cs225::HSLAPixel &color)
 Constructs a new Shape with the given center and color. More...
 
 ~Shape ()
 
int area () const
 Computes and returns the area of the Shape in pixels. More...
 
int perimeter () const
 Computes and returns the perimeter of the Shape in pixels. More...
 
bool contains (const Vector2 &p) const
 Checks to see if the Vector2 p is contained inside of the Shape. More...
 
Vector2 center () const
 Gets the center Vector2 of the Shape. More...
 
virtual void set_center (const Vector2 &center)
 Sets the center Vector2 of the Shape. More...
 
cs225::HSLAPixel color () const
 Gets the color of the Shape. More...
 
void draw (cs225::PNG *canvas) const
 This method will draw the object onto the canvas. More...
 
- Public Member Functions inherited from Drawable
 ~Drawable ()
 

Private Attributes

int width_
 
int height_
 

Additional Inherited Members

- Protected Attributes inherited from Shape
Vector2 center_
 

Detailed Description

A subclass of Shape that represents a rectangle in 2D space.

Constructor & Destructor Documentation

Rectangle::Rectangle ( const Vector2 center,
const cs225::HSLAPixel color,
int  width,
int  height 
)

Constructs a new Rectangle with the given center, color, height, and width.

Parameters
centerthe center of the Rectangle
colorthe color of the Rectangle
widththe width of the Rectangle in pixels
heightthe height of the Rectangle in pixels

Member Function Documentation

int Rectangle::area ( ) const

Computes and returns the area of the Rectangle in pixels.

Returns
the area of the Rectangle in pixels
bool Rectangle::contains ( const Vector2 p) const

Checks to see if the given Vector2 p is inside of the Rectangle.

Parameters
pVector2
Returns
true if p is inside of the Rectangle
void Rectangle::draw ( cs225::PNG canvas) const
virtual

Draws the Rectangle onto the canvas.

Parameters
canvasto draw onto

Implements Drawable.

int Rectangle::height ( ) const

Gets the height of the Rectangle in pixels.

Returns
the height of the Rectangle in pixels
int Rectangle::perimeter ( ) const

Computes and returns the perimeter of the Rectangle in pixels.

Returns
the perimeter of the Rectangle in pixels
void Rectangle::set_height ( int  height)

Sets the height of the Rectangle in pixels.

Parameters
heightthe new height of the Rectangle in pixels
void Rectangle::set_width ( int  width)

Sets the width of the Rectangle in pixels.

Parameters
widththe new width of the Rectangle in pixels
int Rectangle::width ( ) const

Gets the width of the Rectangle in pixels.

Returns
the width of the Rectangle in pixels

Member Data Documentation

int Rectangle::height_
private
int Rectangle::width_
private

The documentation for this class was generated from the following files: