42 lines
786 B
Zig
42 lines
786 B
Zig
const Vec2i = @import("./Vec2i.zig");
|
|
const Vec2f = @import("./Vec2f.zig");
|
|
const Rectf = @import("./Rectf.zig");
|
|
|
|
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.new(x, y),
|
|
.b = Vec2i.new(x + w, y + h),
|
|
};
|
|
}
|
|
|
|
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,
|
|
);
|
|
}
|