forked from IvannnZ/hck2d2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMisc.cpp
121 lines (71 loc) · 1.54 KB
/
Misc.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "Rectangle.h"
#include "Color.h"
#include "Shape.h"
using namespace hck2d2024;
Rectangle::Rectangle(Point topLeft, Point bottomRight)
: topLeft_(topLeft), bottomRight_(bottomRight) {
}
Point Rectangle::bottomRight() const {
return bottomRight_;
}
Point Rectangle::topLeft() const {
return topLeft_;
}
Shape::Shape(std::initializer_list<Point> pts)
: points_(pts) {
}
Shape::Shape(const Shape &s)
: points_(s.points_) {
}
Shape::Shape(Shape &&s)
: points_(std::move(s.points_)) {
}
Shape::Shape(const std::vector<Point> &pts)
: points_(pts) {
}
size_t Shape::numVertices() const { return points_.size(); }
Point &Shape::operator[](size_t idx) {
return points_[idx];
}
Shape &Shape::operator=(const Shape &shape) {
points_ = shape.points_;
return *this;
}
Shape::Shape(std::vector<Point> &&pts)
: points_(std::move(pts)) {}
Color::Color(uint8_t r, uint8_t g, uint8_t b)
: r_(r), g_(g), b_(b) {
}
uint8_t Color::r() const {
return r_;
}
uint8_t Color::g() const {
return g_;
}
uint8_t Color::b() const {
return b_;
}
Color &Color::operator=(const Color &c) {
r_ = c.r();
g_ = c.g();
b_ = c.b();
return *this;
}
Point::Point(double x, double y)
: x_(x), y_(y) {}
Point::Point(const Point &p)
: x_(p.x()), y_(p.y()) {}
double Point::x() const {
return x_;
}
double Point::y() const {
return y_;
}
Point &Point::operator=(Point pt) {
x_ = pt.x();
y_ = pt.y();
return *this;
}
bool Point::operator==(Point pt) {
return x_ == pt.x() && y_ == pt.y();
}