R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Rect.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** Rect.hpp
6*/
7
17#pragma once
18
19#include <utility>
20#include <iostream>
21#include <optional>
22#include <algorithm>
23
24#include "Log.hpp"
25#include "LogMacros.hpp"
26
27namespace Recoded
28{
37 template <typename T>
38 class Rect {
39 public:
43 Rect();
44
53 Rect(std::pair<T, T> position, std::pair<T, T> size);
54
63 template <typename U>
64 constexpr explicit operator Rect<U>() const;
65
75 constexpr bool contains(std::pair<T, T> point) const;
76
86 std::optional<Rect<T>> findIntersection(const Rect<T> &rect) const;
87
95 std::pair<T, T> getCenter() const;
96
97 std::pair<T, T> position{};
98 std::pair<T, T> size{};
99 };
100
111 template <typename T>
112 inline std::ostream &operator<<(std::ostream &os, const Rect<T> &rectangle)
113 {
114 os << "( x: " << myToString(rectangle.position.first)
115 << ", y: " << myToString(rectangle.position.second)
116 << ", width: " << myToString(rectangle.size.first)
117 << ", height: " << myToString(rectangle.size.second) + ")";
118 return os;
119 };
120
132 template <typename T>
133 constexpr bool operator==(const Rect<T> &lhs, const Rect<T> &rhs);
134
146 template <typename T>
147 constexpr bool operator!=(const Rect<T> &lhs, const Rect<T> &rhs);
148
154
160
166
172
178
184
190
196
222 template <typename RectType>
223 const std::string myToString(const Rect<RectType> &rectangle)
224 {
225 std::string result = "( x: " + myToString(rectangle.position.first);
226 result += ", y: " + myToString(rectangle.position.second);
227 result += ", width: " + myToString(rectangle.size.first);
228 result += ", height: " + myToString(rectangle.size.second) + ")";
229 return result;
230 };
231}
Macro definitions for logging messages with varying levels of detail and formatting.
This is the file in charge of containing the Log class (the one in charge of outputing info only when...
A generic 2D rectangle class that holds position and size as pairs.
Definition Rect.hpp:38
std::pair< T, T > size
The size of the rectangle (width, height)
Definition Rect.hpp:98
Rect()
Default constructor, initializes the rectangle with default values (0, 0) for position and size.
Definition Rect.cpp:17
std::optional< Rect< T > > findIntersection(const Rect< T > &rect) const
Finds the intersection between this rectangle and another.
Definition Rect.cpp:43
constexpr bool contains(std::pair< T, T > point) const
Checks if a point is inside the rectangle (non-inclusive).
Definition Rect.cpp:36
std::pair< T, T > getCenter() const
Gets the center of the rectangle.
Definition Rect.cpp:63
std::pair< T, T > position
the position (top and left corner)
Definition Rect.hpp:97
Rect< unsigned long long int > ULLIntRect
The Rect element cast as an unsigned long long int.
Definition Rect.hpp:183
Rect< double > DoubleRect
The Rect element cast as a double.
Definition Rect.hpp:195
Rect< long int > LIntRect
The Rect element cast as a long int.
Definition Rect.hpp:159
constexpr bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operators for the Rect.
Definition Rect.cpp:75
Rect< unsigned int > UIntRect
The Rect element cast as an unsigned int.
Definition Rect.hpp:171
Rect< unsigned long int > ULIntRect
The Rect element cast as an unsigned long int.
Definition Rect.hpp:177
Rect< int > IntRect
The Rect element cast as an int.
Definition Rect.hpp:153
Rect< long long int > LLIntRect
The Rect element cast as a long long int.
Definition Rect.hpp:165
Rect< float > FloatRect
the Rect element cast as a float
Definition Rect.hpp:189
std::ostream & operator<<(std::ostream &os, const Rect< T > &rectangle)
Operator in charge of outputing the values contained in the _rect when it is passed through a << oper...
Definition Rect.hpp:112
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.
Definition Rect.hpp:223
constexpr bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Overload that allows the user to check if 2 rect instances are identical.
Definition Rect.cpp:69