const Vec2i = @import("./Vec2i.zig"); const Vec2f = @import("./Vec2f.zig"); const Rectf = @import("./Rectf.zig"); const std = @import("std"); const Recti = @This(); x: i32, y: i32, w: i32, h: i32, a: Vec2i, b: Vec2i, pub fn from_xywh(x: i32, y: i32, w: i32, h: i32) Recti { return .{ .x = x, .y = y, .w = w, .h = h, .a = Vec2i.create(x, y), .b = Vec2i.create(x + w, y + h), }; } pub fn from_ab(a: Vec2i, b: Vec2i) Recti { const tlx = @min(a.x, b.x); const tly = @min(a.y, b.y); const brx = @max(a.x, b.x); const bry = @max(a.y, b.y); const width = brx - tlx; const height = bry - tly; return .{ .x = tlx, .y = tly, .w = width, .h = height, .a = Vec2i.create(tlx, tly), .b = Vec2i.create(brx, bry), }; } pub fn to_rectf(self: *const Recti) Rectf { return Rectf.from_xywh( @intCast(self.x), @intCast(self.y), @intCast(self.w), @intCast(self.h), ); } pub fn scalef(self: *const Recti, scale: Vec2f) Rectf { return Rectf.from_xywh( @as(f32, @floatFromInt(self.x)) / scale.x, @as(f32, @floatFromInt(self.y)) / scale.y, @as(f32, @floatFromInt(self.w)) / scale.x, @as(f32, @floatFromInt(self.h)) / scale.y, ); }