lab_inheritance
Insidious Inheritance
 All Classes Namespaces Files Functions Variables
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::Shape ( )

Constructs a new Shape with a default color and center.

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

Member Function Documentation

int Shape::area ( ) const

Computes and returns the area of the Shape in pixels.

Returns
the area (in pixels) of the Shape
Vector2 Shape::center ( ) const

Gets the center Vector2 of the Shape.

Returns
the center Vector2 of the Shape
HSLAPixel Shape::color ( ) const

Gets the color of the Shape.

Returns
the HSLAPixel representing the color of the Shape
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
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.

int Shape::perimeter ( ) const

Computes and returns the perimeter of the Shape in pixels.

Returns
the perimeter (in pixels) of the Shape
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

Vector2 Shape::center_
protected
cs225::HSLAPixel Shape::color_
private

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