lab_inheritance
Insidious Inheritance
Shape Class Reference

An abstract base class that represents a Shape which has an area, perimeter, color, and can contain Vector2s. More...

#include <shape.h>

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

Public Member Functions

 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 ()
 

Protected Attributes

Vector2 center_
 

Private Attributes

cs225::HSLAPixel color_
 

Detailed Description

An abstract base class that represents a Shape which has an area, perimeter, color, and can contain Vector2s.

Shapes are also drawable, so they are expected to know how to draw themselves to a PNG.

Constructor & Destructor Documentation

◆ Shape() [1/2]

Shape::Shape ( )

Constructs a new Shape with a default color and center.

◆ Shape() [2/2]

Shape::Shape ( const Vector2 center,
const cs225::HSLAPixel color 
)

Constructs a new Shape with the given center and color.

Parameters
centerVector2 of the new Shape
colorof the new Shape

◆ ~Shape()

Shape::~Shape ( )
inline

Member Function Documentation

◆ area()

int Shape::area ( ) const

Computes and returns the area of the Shape in pixels.

Returns
the area (in pixels) of the Shape

◆ center()

Vector2 Shape::center ( ) const

Gets the center Vector2 of the Shape.

Returns
the center Vector2 of the Shape

◆ color()

HSLAPixel Shape::color ( ) const

Gets the color of the Shape.

Returns
the HSLAPixel representing the color of the Shape

◆ contains()

bool Shape::contains ( const Vector2 p) const

Checks to see if the Vector2 p is contained inside of the Shape.

Parameters
pVector2 to check if it is contained inside the Shape or not
Returns
true if Vector2 p is inside of the Shape

◆ draw()

void Shape::draw ( cs225::PNG canvas) const
virtual

This method will draw the object onto the canvas.

Parameters
canvasto draw onto.

Implements Drawable.

Reimplemented in Triangle.

◆ perimeter()

int Shape::perimeter ( ) const

Computes and returns the perimeter of the Shape in pixels.

Returns
the perimeter (in pixels) of the Shape

◆ set_center()

void Shape::set_center ( const Vector2 center)
virtual

Sets the center Vector2 of the Shape.

Parameters
centerthe new center Vector2 of the Shape

Reimplemented in Triangle.

Member Data Documentation

◆ center_

Vector2 Shape::center_
protected

◆ color_

cs225::HSLAPixel Shape::color_
private

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