51 Rect(T _x, T _y, T _width, T _height)
97 T minX = std::min(
x, static_cast<T>(
x +
width));
98 T maxX = std::max(
x, static_cast<T>(
x +
width));
99 T minY = std::min(
y, static_cast<T>(
y +
height));
100 T maxY = std::max(
y, static_cast<T>(
y +
height));
102 return (_x >= minX) && (_x < maxX) && (_y >= minY) && (_y < maxY);
133 T r1MinX = std::min(
x, static_cast<T>(
x +
width));
134 T r1MaxX = std::max(
x, static_cast<T>(
x +
width));
135 T r1MinY = std::min(
y, static_cast<T>(
y +
height));
136 T r1MaxY = std::max(
y, static_cast<T>(
y +
height));
138 T r2MinX = std::min(rect.
x, static_cast<T>(rect.
x + rect.
width));
139 T r2MaxX = std::max(rect.
x, static_cast<T>(rect.
x + rect.
width));
140 T r2MinY = std::min(rect.
y, static_cast<T>(rect.
y + rect.
height));
141 T r2MaxY = std::max(rect.
y, static_cast<T>(rect.
y + rect.
height));
143 T interLeft = std::max(r1MinX, r2MinX);
144 T interTop = std::max(r1MinY, r2MinY);
145 T interRight = std::min(r1MaxX, r2MaxX);
146 T interBottom = std::min(r1MaxY, r2MaxY);
148 return interLeft < interRight && interTop < interBottom;
162 T r1MinX = std::min(
x, static_cast<T>(
x +
width));
163 T r1MaxX = std::max(
x, static_cast<T>(
x +
width));
164 T r1MinY = std::min(
y, static_cast<T>(
y +
height));
165 T r1MaxY = std::max(
y, static_cast<T>(
y +
height));
167 T r2MinX = std::min(rect.
x, static_cast<T>(rect.
x + rect.
width));
168 T r2MaxX = std::max(rect.
x, static_cast<T>(rect.
x + rect.
width));
169 T r2MinY = std::min(rect.
y, static_cast<T>(rect.
y + rect.
height));
170 T r2MaxY = std::max(rect.
y, static_cast<T>(rect.
y + rect.
height));
172 T interLeft = std::max(r1MinX, r2MinX);
173 T interTop = std::max(r1MinY, r2MinY);
174 T interRight = std::min(r1MaxX, r2MaxX);
175 T interBottom = std::min(r1MaxY, r2MaxY);
177 if(interLeft < interRight && interTop < interBottom) {
178 if(interRight - interLeft < interBottom - interTop) {
227 #endif // GK_RECT_HPP_
Rect()=default
Default constructor.
Rect(const Rect< U > &rect)
Construct the rectangle from another type of rectangle.
Rect(T _x, T _y, T _width, T _height)
Construct the rectangle from its coordinates.
bool contains(const Vector2< T > &point) const
Check if a point is inside the rectangle's area.
bool operator==(const Rect< T > &rect) const
Overload of binary operator ==.
T y
Top coordinate of the rectangle.
bool operator!=(const Rect< T > &rect) const
Overload of binary operator !=.
Utility class for manipulating 2D axis aligned rectangles.
bool contains(T _x, T _y) const
Check if a point is inside the rectangle's area.
T x
Left coordinate of the rectangle.
T intersectionDirection(const Rect< T > &rect) const
Check the intersection direction between two rectangles.
bool intersects(const Rect< T > &rect) const
Check the intersection between two rectangles.
T width
Width of the rectangle.
T height
Height of the rectangle.
Rect(const Vector2< T > &position, const Vector2< T > &size)
Construct the rectangle from position and size.