Skip to content

Commit b7b7d54

Browse files
committed
Add ostream Overload for Rectangle Class
1 parent 3864394 commit b7b7d54

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/app/Math/Rectangle.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ Rectangle::Rectangle(Vector c, Vector s) : center(c), size(s) {}
55
Rectangle::Rectangle(Vector s) : center(0.0f, 0.0f), size(s) {}
66

77
bool Rectangle::contains(Vector p) const {
8-
return (
9-
(p.x >= center.x - size.x && p.x <= center.x + size.x)
10-
&& (p.y >= center.y - size.y && p.y <= center.y + size.y)
8+
return !(
9+
p.x < center.x - size.x ||
10+
p.x > center.x + size.x ||
11+
p.y < center.y - size.y ||
12+
p.y > center.y + size.y
1113
);
1214
}
1315

@@ -29,3 +31,11 @@ int Rectangle::quadrant(Vector p) const {
2931
Rectangle Rectangle::operator*(float val) const {
3032
return {center, size * val};
3133
}
34+
35+
std::ostream& operator<<(std::ostream& os, Rectangle const& r) {
36+
os << "Rectangle(center: {"
37+
<< r.center.x << ", " << r.center.y
38+
<< "}, size: {" << r.size.x << ", " << r.size.y
39+
<< "})";
40+
return os;
41+
}

src/app/Math/Rectangle.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ class Rectangle {
2727
Vector center{0, 0};
2828
Vector size{0, 0};
2929
};
30+
31+
std::ostream& operator<<(std::ostream& os, Rectangle const&);

0 commit comments

Comments
 (0)