**@@ 30,3 30,6 @@ Full list of methods I added:**
* `Rectangle.bottom`
* `Rectangle.containsPoint`
* `Rectangle.overlaps`
+* `Rectangle.overlapRect`
+* `Rectangle.add`
+* `Rectangle.subtract`

**@@ 138,6 138,33 @@ pub const Rectangle = extern struct {**
pub fn overlaps(a: Rectangle, b: Rectangle) bool {
return (a.x + a.width > b.x and a.x < b.x + b.width and a.y + a.height > b.y and a.y < b.y + b.height);
}
+ pub fn overlapRect(a: Rectangle, b: Rectangle) Rectangle {
+ const overlapLeft = @max(a.x, b.x);
+ const overlapRight = @min(a.right(), b.right());
+ const overlapTop = @max(a.y, b.y);
+ const overlapBottom = @min(a.bottom(), b.bottom());
+ if (overlapLeft < overlapRight and overlapTop < overlapBottom) {
+ return .{
+ .x = overlapLeft,
+ .y = overlapTop,
+ .width = overlapRight - overlapLeft,
+ .height = overlapBottom - overlapTop,
+ };
+ }
+ return .{ .x = 0, .y = 0, .width = 0, .height = 0 };
+ }
+ pub fn add(r: Rectangle, v: Vector2) Rectangle {
+ var copy = r;
+ copy.x += v.x;
+ copy.y += v.y;
+ return copy;
+ }
+ pub fn subtract(r: Rectangle, v: Vector2) Rectangle {
+ var copy = r;
+ copy.x -= v.x;
+ copy.y -= v.y;
+ return copy;
+ }
};
pub const Image = extern struct {