+ return (other.x + other.width) > x && other.x < (x + width) &&
+ (other.y + other.height) > y && other.y < (y + height);
+ }
+
+ /**
+ * @brief Intersects this rectangle and the specified rectangle.
+ * The result of the intersection is stored in this rectangle.
+ *
+ * @SINCE_1_9.18
+ * @param[in] rect The other rectangle to intersect with
+ * @return True if the rectangles intersect
+ */
+ bool Intersect(const Rect<T>& rect)
+ {
+ const int left = std::max(rect.x, x);
+ const int top = std::max(rect.y, y);
+ const int right = std::min(rect.x + rect.width, x + width);
+ const int bottom = std::min(rect.y + rect.height, y + height);
+
+ const int width = right - left;
+ const int height = bottom - top;
+ if(!(width < 0 || height < 0))
+ {
+ x = left;
+ y = top;
+ this->width = width;
+ this->height = height;
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @brief Merges this rectangle and the specified rectangle.
+ * The result of the merge is stored in this rectangle.
+ *
+ * @SINCE_1_9.18
+ * @param[in] rect The other rectangle to merge with
+ */
+ void Merge(const Rect<T>& rect)
+ {
+ const int left = std::min(rect.x, x);
+ const int top = std::min(rect.y, y);
+ const int right = std::max(rect.x + rect.width, x + width);
+ const int bottom = std::max(rect.y + rect.height, y + height);
+ x = left;
+ y = top;
+ width = right - left;
+ height = bottom - top;
+ }
+
+ /**
+ * @brief Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards.
+ * If dx is negative, then the sides are moved outwards.
+ * The result of the inset is stored in this rectangle.
+ * @SINCE_1_9.18
+ */
+ void Inset(T dx, T dy)
+ {
+ const int left = x - dx;
+ const int top = y - dy;
+ const int right = x + width + dx;
+ const int bottom = y + height + dy;
+ x = left;
+ y = top;
+ width = right - left;
+ height = bottom - top;