~yujiri/raylib-zig

cdccd0d3f83475762a757c9357572c3b2b2ae1fc — Evin Yulo 5 months ago 2eb613d
add more Rectangle methods
2 files changed, 30 insertions(+), 0 deletions(-)

M README.md
M binding.zig
M README.md => README.md +3 -0
@@ 30,3 30,6 @@ Full list of methods I added:
* `Rectangle.bottom`
* `Rectangle.containsPoint`
* `Rectangle.overlaps`
* `Rectangle.overlapRect`
* `Rectangle.add`
* `Rectangle.subtract`

M binding.zig => binding.zig +27 -0
@@ 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 {