lab_inheritance
Insidious Inheritance
Triangle Class Reference

A subclass of a Shape that represents a triangle in 2D space. More...

#include <triangle.h>

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

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 ()
 
Triangleoperator= (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 &center)
 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 &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...
 
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_
 

Detailed Description

A subclass of a Shape that represents a triangle in 2D space.

Constructor & Destructor Documentation

◆ Triangle() [1/2]

Triangle::Triangle ( const cs225::HSLAPixel color,
const Vector2 vertex1,
const Vector2 vertex2,
const Vector2 vertex3 
)

Constructs a new Triangle out of the 3 give Vector2s.

Parameters
colorof the new Triangle
vertex1first Vector2 of the Triangle
vertex2second Vector2 of the Triangle
vertex3third Vector2 of the Triangle

◆ Triangle() [2/2]

Triangle::Triangle ( const Triangle other)

◆ ~Triangle()

Triangle::~Triangle ( )

Member Function Documentation

◆ area()

int Triangle::area ( ) const

Computes and returns the area of the Triangle.

Returns
the area of the Triangle in pixels

◆ contains()

bool Triangle::contains ( const Vector2 p) const

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

Parameters
pVector2
Returns
true if the Vector2 p is inside of the Triangle

◆ draw()

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

Draws the Triangle to the canvas.

Parameters
canvasPNG to draw onto

Reimplemented from Shape.

◆ operator=()

Triangle & Triangle::operator= ( const Triangle rhs)

◆ perimeter()

int Triangle::perimeter ( ) const

Computes and returns the perimeter of the Triangle.

Returns
the perimeter of the Triangle in pixels

◆ set_center()

void Triangle::set_center ( const Vector2 center)
virtual

Overridden set_center method that sets the center Vector2 of the Triangle.

Parameters
centerthe new center Vector2

Reimplemented from Shape.

◆ set_vertex()

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)

Parameters
ithe vertex to change
valuethe new vertex

◆ vertex()

Vector2 Triangle::vertex ( int  i) const

Gets one of the Triangle's vertices.

Crashes if an invalid vertex index is given (i.e. i < 0 or i > 2)

Parameters
iVertex to get. Either 0, 1, or 2
Returns
The Triangle's i'th vertex

Member Data Documentation

◆ vertices_

Vector2** Triangle::vertices_
private

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