lab_inheritance
Insidious Inheritance
Shape Class Referenceabstract

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...
 
virtual int area () const =0
 Computes and returns the area of the Shape in pixels. More...
 
int area () const
 
virtual int perimeter () const =0
 Computes and returns the perimeter of the Shape in pixels. More...
 
int perimeter () const
 
virtual bool contains (const Vector2 &p) const =0
 Checks to see if the Vector2 p is contained inside of the Shape. More...
 
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...
 

Protected Attributes

Vector2 center_
 

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

Member Function Documentation

◆ area()

int Shape::area ( ) const
pure virtual

Computes and returns the area of the Shape in pixels.

Returns
the area (in pixels) of the Shape

Implemented in Triangle, Rectangle, and Circle.

◆ 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
pure virtual

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

Implemented in Triangle, Rectangle, and Circle.

◆ 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
pure virtual

Computes and returns the perimeter of the Shape in pixels.

Returns
the perimeter (in pixels) of the Shape

Implemented in Triangle, Rectangle, and Circle.

◆ 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.


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