math: begin rewrite of mach.math
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
6b5a9990b9
commit
5b25db1025
7 changed files with 1449 additions and 1192 deletions
34
src/math/quat.zig
Normal file
34
src/math/quat.zig
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const std = @import("std");
|
||||
|
||||
const mach = @import("../main.zig");
|
||||
const testing = mach.testing;
|
||||
const math = mach.math;
|
||||
const vec = @import("vec.zig");
|
||||
|
||||
pub fn Quat(comptime Scalar: type) type {
|
||||
return struct {
|
||||
v: vec.Vec(4, Scalar),
|
||||
|
||||
/// The scalar type of this matrix, e.g. Mat3x3.T == f32
|
||||
pub const T = Vec.T;
|
||||
|
||||
/// The underlying Vec type, e.g. math.Vec4, math.Vec4h, math.Vec4d
|
||||
pub const Vec = vec.Vec(4, Scalar);
|
||||
|
||||
pub inline fn init(x: T, y: T, z: T, w: T) Quat(Scalar) {
|
||||
return .{ .v = math.vec4(x, y, z, w) };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test "zero_struct_overhead" {
|
||||
// Proof that using Quat is equal to @Vector(4, f32)
|
||||
try testing.expect(usize, @alignOf(@Vector(4, f32))).eql(@alignOf(math.Quat));
|
||||
try testing.expect(usize, @sizeOf(@Vector(4, f32))).eql(@sizeOf(math.Quat));
|
||||
}
|
||||
|
||||
test "init" {
|
||||
try testing.expect(math.Quat, math.quat(1, 2, 3, 4)).eql(math.Quat{
|
||||
.v = math.vec4(1, 2, 3, 4),
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue