lab_inheritance
Insidious Inheritance
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...
 
int area () const
 
int perimeter () const
 
bool contains (const Vector2 &p) const
 
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...
 

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::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

◆ area()

int Rectangle::area ( ) const
virtual

Computes and returns the area of the Rectangle in pixels.

Returns
the area of the Rectangle in pixels

Implements Shape.

◆ contains()

bool Rectangle::contains ( const Vector2 p) const
virtual

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

Parameters
pVector2
Returns
true if p is inside of the Rectangle

Implements Shape.

◆ draw()

void Rectangle::draw ( cs225::PNG *  canvas) const
virtual

Draws the Rectangle onto the canvas.

Parameters
canvasto draw onto

Implements Drawable.

◆ height()

int Rectangle::height ( ) const

Gets the height of the Rectangle in pixels.

Returns
the height of the Rectangle in pixels

◆ perimeter()

int Rectangle::perimeter ( ) const
virtual

Computes and returns the perimeter of the Rectangle in pixels.

Returns
the perimeter of the Rectangle in pixels

Implements Shape.

◆ set_height()

void Rectangle::set_height ( int  height)

Sets the height of the Rectangle in pixels.

Parameters
heightthe new height of the Rectangle in pixels

◆ set_width()

void Rectangle::set_width ( int  width)

Sets the width of the Rectangle in pixels.

Parameters
widththe new width of the Rectangle in pixels

◆ width()

int Rectangle::width ( ) const

Gets the width of the Rectangle in pixels.

Returns
the width of the Rectangle in pixels

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