Dualie
Loading...
Searching...
No Matches
Rect.hpp
1//
2// Created by caleb on 6/18/24.
3//
4
5#ifndef DUALIE_RECT_HPP
6#define DUALIE_RECT_HPP
7
8#include <Dualie/System/Vector2.hpp>
9
10namespace dl {
11
16 template<class T>
17 class Rect {
18 using FloatRect = Rect<float>;
19 public:
20 T left;
21 T top;
22 T width;
23 T height;
24
25 Rect() {
26
27 left = 0;
28 top = 0;
29 width = 0;
30 height = 0;
31
32 }
33
34 Rect(T left, T top, T width, T height) {
35
36 this->left = left;
37 this->top = top;
38 this->width = width;
39 this->height = height;
40 }
41 Rect(dl::Vector2<T> position, dl::Vector2<T> size) {
42
43 left = position.x;
44 top = position.y;
45 width = size.x;
46 height = size.y;
47 }
48
49 Rect(const dl::Rect<T> &rect) {
50 *this = rect;
51 }
52
58 bool intersects(Rect<T> rect){
59 return (this->left < rect.left + rect.width && this->left + this->width > rect.left &&
60 this->top < rect.top + rect.height && this->top + this->height > rect.top);
61 }
62
69 return (point.x > this->left && point.x < this->left + this->width && point.y > this->top && point.y < this->top + this->height);
70 }
71
72 };
73 using FloatRect = Rect<float>;
74}
75
76#endif //DUALIE_RECT_HPP
A class that represents a bounding box.
Definition Rect.hpp:17
bool intersects(Rect< T > rect)
Returns whether a rect intersects the bounds of this rect.
Definition Rect.hpp:58
bool contains(dl::Vector2< T > point)
Returns whether a point intersects the bounds of this rect.
Definition Rect.hpp:68
Used to contain a set of two numbers.
Definition Vector2.hpp:16