lab_inheritance
Insidious Inheritance
|
A subclass of a Shape that represents a triangle in 2D space. More...
#include <triangle.h>
Public Member Functions | |
Triangle (const cs225::HSLAPixel &color, const Vector2 &vertex1, const Vector2 &vertex2, const Vector2 &vertex3) | |
Constructs a new Triangle out of the 3 give Vector2s. More... | |
Triangle (const Triangle &other) | |
~Triangle () | |
Triangle & | operator= (const Triangle &rhs) |
int | area () const |
Computes and returns the area of the Triangle. More... | |
int | perimeter () const |
Computes and returns the perimeter of the Triangle. More... | |
bool | contains (const Vector2 &p) const |
Checks to see if the Vector2 p is contained inside of the Triangle. More... | |
void | draw (cs225::PNG *canvas) const |
Draws the Triangle to the canvas. More... | |
void | set_center (const Vector2 ¢er) |
Overridden set_center method that sets the center Vector2 of the Triangle. More... | |
Vector2 | vertex (int i) const |
Gets one of the Triangle's vertices. More... | |
void | set_vertex (int i, const Vector2 &value) |
Sets one of the Triangle's vertices. More... | |
Public Member Functions inherited from Shape | |
Shape () | |
Constructs a new Shape with a default color and center. More... | |
Shape (const Vector2 ¢er, 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... | |
cs225::HSLAPixel | color () const |
Gets the color of the Shape. More... | |
Public Member Functions inherited from Drawable | |
~Drawable () | |
Private Attributes | |
Vector2 ** | vertices_ |
Additional Inherited Members | |
Protected Attributes inherited from Shape | |
Vector2 | center_ |
A subclass of a Shape that represents a triangle in 2D space.
Triangle::Triangle | ( | const cs225::HSLAPixel & | color, |
const Vector2 & | vertex1, | ||
const Vector2 & | vertex2, | ||
const Vector2 & | vertex3 | ||
) |
Triangle::Triangle | ( | const Triangle & | other | ) |
Triangle::~Triangle | ( | ) |
int Triangle::area | ( | ) | const |
bool Triangle::contains | ( | const Vector2 & | p | ) | const |
|
virtual |
int Triangle::perimeter | ( | ) | const |
|
virtual |
void Triangle::set_vertex | ( | int | i, |
const Vector2 & | value | ||
) |
Sets one of the Triangle's vertices.
Crashes if an invalid vertex index is given (i.e. i < 0 or i > 2)
i | the vertex to change |
value | the new vertex |
Vector2 Triangle::vertex | ( | int | i | ) | const |
|
private |