Added some doc comments
This commit is contained in:
@@ -29,10 +29,16 @@ pub const Dimension = enum {
|
||||
}
|
||||
};
|
||||
|
||||
// --------- Dimensions struct ---------
|
||||
|
||||
/// Holds the exponent of each SI base dimension for a given quantity (e.g. velocity = L¹T⁻¹).
|
||||
/// All values are `comptime_int` — no runtime storage.
|
||||
const Self = @This();
|
||||
|
||||
data: std.EnumArray(Dimension, comptime_int),
|
||||
|
||||
/// Create a `Dimensions` from an anonymous struct literal, e.g. `.{ .L = 1, .T = -1 }`.
|
||||
/// Unspecified dimensions default to 0.
|
||||
pub fn init(comptime init_val: anytype) Self {
|
||||
var s = Self{ .data = std.EnumArray(Dimension, comptime_int).initFill(0) };
|
||||
inline for (std.meta.fields(@TypeOf(init_val))) |f|
|
||||
@@ -52,6 +58,7 @@ pub fn set(comptime self: *Self, comptime key: Dimension, comptime val: i8) void
|
||||
self.data.set(key, val);
|
||||
}
|
||||
|
||||
/// Add exponents component-wise. Used internally by `mulBy`.
|
||||
pub fn add(comptime a: Self, comptime b: Self) Self {
|
||||
var result = Self.initFill(0);
|
||||
for (std.enums.values(Dimension)) |d|
|
||||
@@ -59,6 +66,7 @@ pub fn add(comptime a: Self, comptime b: Self) Self {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Subtract exponents component-wise. Used internally by `divBy`.
|
||||
pub fn sub(comptime a: Self, comptime b: Self) Self {
|
||||
@setEvalBranchQuota(10_000);
|
||||
var result = Self.initFill(0);
|
||||
@@ -67,6 +75,7 @@ pub fn sub(comptime a: Self, comptime b: Self) Self {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns true if every dimension exponent is equal. Used to enforce type compatibility in `add`, `sub`, `to`.
|
||||
pub fn eql(comptime a: Self, comptime b: Self) bool {
|
||||
inline for (std.enums.values(Dimension)) |d|
|
||||
if (a.get(d) != b.get(d)) return false;
|
||||
|
||||
Reference in New Issue
Block a user