Skip to content

Commit

Permalink
Add Rectangle.cast
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed May 13, 2024
1 parent 28f7b89 commit 6ae4297
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/geometry.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const std = @import("std");
const assert = std.debug.assert;
const as = @import("meta.zig").as;
const Matrix = @import("matrix.zig").Matrix;
const Point2d = @import("point.zig").Point2d;
const svd = @import("svd.zig").svd;
Expand Down Expand Up @@ -37,6 +38,16 @@ pub fn Rectangle(comptime T: type) type {
}
}

/// Cast self's underlying type to U.
pub fn cast(self: Self, comptime U: type) Rectangle(U) {
return .{
.l = as(U, self.l),
.t = as(U, self.t),
.r = as(U, self.r),
.b = as(U, self.b),
};
}

pub fn width(self: Self) T {
return self.r - self.l + 1;
}
Expand Down

0 comments on commit 6ae4297

Please sign in to comment.