This commit is contained in:
2025-12-25 22:47:48 +01:00
parent 63f7068b91
commit 9b7155d39d
2 changed files with 39 additions and 7 deletions

View File

@@ -79,5 +79,5 @@ pub inline fn wideMulDivFloor(a: i32, mul: i32, div: i32) i32 {
}
pub inline fn wideMulDivCeil(a: i32, mul: i32, div: i32) i32 {
return @intCast(@divFloor(@as(i64, a) * @as(i64, mul) + @as(i64, div) - 1, div));
return @intCast(@divFloor(@as(i64, a) * @as(i64, mul) + @as(i64, div) - std.math.sign(div), div));
}

View File

@@ -1,12 +1,44 @@
const std = @import("std");
const c = @import("const.zig");
const Materials = @import("assets/Materials.zig");
pub const Orientation = enum(u3) {
negative_x,
positive_x,
negative_y,
positive_y,
negative_z,
positive_z,
negative_x = 0b111,
positive_x = 0b000,
negative_y = 0b110,
positive_y = 0b001,
negative_z = 0b101,
positive_z = 0b010,
pub fn initSignIndex(sign: i2, index: u2) Orientation {
std.debug.assert(sign == -1 or sign == 1);
std.debug.assert(index < 3);
const value: u3 = (if (sign > 0) @as(u3, 0b100) else @as(u3, 0b000)) | index;
return @enumFromInt(value);
}
/// 0 for ±X
/// 1 for ±Y
/// 2 for ±Z
pub fn getIndex(self: Orientation) u2 {
return if (@intFromEnum(self) & 0b100 != 0) @intCast(~@intFromEnum(self)) else @intCast(@intFromEnum(self));
}
/// +1 for positive
/// -1 for negative
pub fn getSign(self: Orientation) i2 {
return if (@intFromEnum(self) & 0b100 != 0) -1 else 1;
}
pub fn getOffsetVx(self: Orientation) i32 {
return if (@intFromEnum(self) & 0b100 != 0) 1 else 0;
}
pub fn getOffsetSv(self: Orientation) i32 {
return if (@intFromEnum(self) & 0b100 != 0) c.sv_per_vx else 0;
}
};
pub const Transform = enum(u3) {