fix issues
This commit is contained in:
27
src/numz.zig
27
src/numz.zig
@@ -8,9 +8,9 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type {
|
|||||||
|
|
||||||
const Self = @This();
|
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;
|
var m: [rows][cols]T = undefined;
|
||||||
for (0..rows) |i| {
|
for (0..rows) |i| {
|
||||||
for (0..cols) |j| {
|
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 {
|
fn dot(self: Self, other: Self) T {
|
||||||
return self.t().mul(other).get(.x);
|
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 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 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 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 {
|
pub fn splat(s: T) Self {
|
||||||
var result: Self = .{ .mat = undefined };
|
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 {
|
pub fn scale(self: Self, scalar: T) Self {
|
||||||
const result: Self = .{ .mat = undefined };
|
var result: Self = .{ .mat = undefined };
|
||||||
inline for (&result.mat, self.mat) |r_row, s_row| {
|
inline for (&result.mat, self.mat) |*r_row, s_row| {
|
||||||
inline for (r_row, s_row) |r, s| {
|
inline for (r_row, s_row) |*r, s| {
|
||||||
r.* = s * scalar;
|
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 {
|
pub fn scaleInv(self: Self, scalar: T) Self {
|
||||||
const result: Self = .{ .mat = undefined };
|
var result: Self = .{ .mat = undefined };
|
||||||
inline for (&result.mat, self.mat) |r_row, s_row| {
|
inline for (&result.mat, self.mat) |*r_row, s_row| {
|
||||||
inline for (r_row, s_row) |r, s| {
|
inline for (r_row, s_row) |*r, s| {
|
||||||
r.* = s / scalar;
|
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 {
|
pub fn neg(self: Self) Self {
|
||||||
const result: Self = .{ .mat = undefined };
|
var result: Self = .{ .mat = undefined };
|
||||||
inline for (&result.mat, self.mat) |r_row, s_row| {
|
inline for (&result.mat, self.mat) |*r_row, s_row| {
|
||||||
inline for (r_row, s_row) |r, s| {
|
inline for (r_row, s_row) |*r, s| {
|
||||||
r.* = -s;
|
r.* = -s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user