21 : position(position), size(size)
30 std::pair<U, U>(
static_cast<U
>(position.first),
static_cast<U
>(position.second)),
31 std::pair<U, U>(
static_cast<U
>(size.first),
static_cast<U
>(size.second))
38 return point.first > position.first && point.first < (position.first + size.first) &&
39 point.second > position.second && point.second < (position.second + size.second);
45 T x_intersection_min = std::max(position.first, rect.
position.first);
46 T y_intersection_min = std::max(position.second, rect.
position.second);
47 T x_intersection_max = std::min(position.first + size.first, rect.
position.first + rect.
size.first);
48 T y_intersection_max = std::min(position.second + size.second, rect.
position.second + rect.
size.second);
50 if (x_intersection_min < x_intersection_max && y_intersection_min < y_intersection_max) {
51 PRETTY_INFO <<
"Intersection found, returning new rect instance." << std::endl;
53 std::pair<T, T>(x_intersection_min, y_intersection_min),
54 std::pair<T, T>(x_intersection_max - x_intersection_min, y_intersection_max - y_intersection_min)
65 return { position.first + size.first / 2, position.second + size.second / 2 };
#define PRETTY_INFO
Info log with details and colour.
#define PRETTY_WARNING
Warning log with details and colour.
Defines a rectangle class (Rect) mimicking sf::Rect without relying on SFML.
A generic 2D rectangle class that holds position and size as pairs.
std::pair< T, T > size
The size of the rectangle (width, height)
Rect()
Default constructor, initializes the rectangle with default values (0, 0) for position and size.
std::optional< Rect< T > > findIntersection(const Rect< T > &rect) const
Finds the intersection between this rectangle and another.
constexpr bool contains(std::pair< T, T > point) const
Checks if a point is inside the rectangle (non-inclusive).
std::pair< T, T > getCenter() const
Gets the center of the rectangle.
std::pair< T, T > position
the position (top and left corner)
constexpr bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operators for the Rect.
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...
constexpr bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Overload that allows the user to check if 2 rect instances are identical.