From d604eea08e4794f8bf0ad57900926bd3809789f5 Mon Sep 17 00:00:00 2001 From: Robert H Date: Mon, 31 Aug 2026 03:58:48 -0500 Subject: [PATCH] fix issues --- src/numz.zig | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/numz.zig b/src/numz.zig index aa023de..0f02e79 100644 --- a/src/numz.zig +++ b/src/numz.zig @@ -8,9 +8,9 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type { const Self = @This(); - const zero: Self = .splat(0); + pub const zero: Self = .splat(0); - const ident: Self = blk: { + pub const ident: Self = blk: { var m: [rows][cols]T = undefined; for (0..rows) |i| { for (0..cols) |j| { @@ -35,11 +35,16 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type { fn dot(self: Self, other: Self) T { return self.t().mul(other).get(.x); } + + fn array(self: Self) [self.rows]T { + return @bitCast(self.mat); + } }; pub const get = if (cols == 1) vector.get else @compileError("Not a vector"); pub const swizzle = if (cols == 1) vector.swizzle else @compileError("Not a vector"); pub const dot = if (cols == 1) vector.dot else @compileError("Not a vector"); + pub const array = if (cols == 1) vector.array else @compileError("Not a vector"); pub fn splat(s: T) Self { var result: Self = .{ .mat = undefined }; @@ -58,9 +63,9 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type { } pub fn scale(self: Self, scalar: T) Self { - const result: Self = .{ .mat = undefined }; - inline for (&result.mat, self.mat) |r_row, s_row| { - inline for (r_row, s_row) |r, s| { + var result: Self = .{ .mat = undefined }; + inline for (&result.mat, self.mat) |*r_row, s_row| { + inline for (r_row, s_row) |*r, s| { r.* = s * scalar; } } @@ -68,9 +73,9 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type { } pub fn scaleInv(self: Self, scalar: T) Self { - const result: Self = .{ .mat = undefined }; - inline for (&result.mat, self.mat) |r_row, s_row| { - inline for (r_row, s_row) |r, s| { + var result: Self = .{ .mat = undefined }; + inline for (&result.mat, self.mat) |*r_row, s_row| { + inline for (r_row, s_row) |*r, s| { r.* = s / scalar; } } @@ -78,9 +83,9 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type { } pub fn neg(self: Self) Self { - const result: Self = .{ .mat = undefined }; - inline for (&result.mat, self.mat) |r_row, s_row| { - inline for (r_row, s_row) |r, s| { + var result: Self = .{ .mat = undefined }; + inline for (&result.mat, self.mat) |*r_row, s_row| { + inline for (r_row, s_row) |*r, s| { r.* = -s; } }