-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape.cpp
More file actions
73 lines (58 loc) · 1.57 KB
/
Copy pathshape.cpp
File metadata and controls
73 lines (58 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file shape.cpp
* Implementation of the Shape class.
*/
#include "shape.h"
#include "color.h"
#include "line.h"
using cs225::PNG;
using cs225::HSLAPixel;
const Vector2 DEFAULT_CENTER(64, 64);
const HSLAPixel DEFAULT_COLOR = color::BLACK;
Shape::Shape() : center_(DEFAULT_CENTER), color_(DEFAULT_COLOR)
{
/* Nothing. See initialization list. */
}
Shape::Shape(const Vector2& pcenter, const HSLAPixel& pcolor)
: center_(pcenter), color_(pcolor)
{
/* Nothing. See initialization list. */
}
int Shape::area() const
{
/* Shape's don't have an area since they cannot be made */
return 0;
}
int Shape::perimeter() const
{
/* Shape's don't have a perimeter since they cannot be made */
return 0;
}
bool Shape::contains(const Vector2& p) const
{
/* Default shapes don't contain any points */
return false;
}
Vector2 Shape::center() const
{
return this->center_;
}
void Shape::set_center(const Vector2& pcenter)
{
this->center_ = pcenter;
}
HSLAPixel Shape::color() const
{
return this->color_;
}
void Shape::draw(PNG* canvas) const
{
const Vector2 top_left(this->center().x() - 8, this->center().y() - 8);
const Vector2 top_right(this->center().x() + 8, this->center().y() - 8);
const Vector2 bottom_left(this->center().x() - 8, this->center().y() + 8);
const Vector2 bottom_right(this->center().x() + 8, this->center().y() + 8);
const Line foward_slash(bottom_left, top_right, color::RED);
foward_slash.draw(canvas);
const Line backward_slash(top_left, bottom_right, color::RED);
backward_slash.draw(canvas);
}