This commit is contained in:
Vivianne 2022-07-19 03:41:40 -07:00
parent 7ab7bfcff1
commit fbaa4846b6

View file

@ -88,11 +88,11 @@ pub fn Vec(comptime nelem: comptime_int, comptime T: anytype) type {
// 3-element operations // 3-element operations
pub usingnamespace if (nelem >= 3) struct { pub usingnamespace if (nelem >= 3) struct {
pub inline fn sum3(self: Self) f32 { pub inline fn sum3(self: Self) T {
return self.x + self.y + self.z; return self.x + self.y + self.z;
} }
pub inline fn dot3(a: Self, b: Self) f32 { pub inline fn dot3(a: Self, b: Self) T {
return a.mul(b).sum3(); return a.mul(b).sum3();
} }
@ -136,8 +136,8 @@ pub fn Vec(comptime nelem: comptime_int, comptime T: anytype) type {
return zxy(sub(mul(zxy(a), b), mul(a, zxy(b)))); return zxy(sub(mul(zxy(a), b), mul(a, zxy(b))));
} }
pub inline fn length3(self: Self) f32 { pub inline fn length3(self: Self) T {
return @sqrt(@maximum(std.math.f32_epsilon, self.dot3(self))); return @sqrt(@maximum(std.math.epsilon(T), self.dot3(self)));
} }
pub inline fn normalize3(self: Self) Self { pub inline fn normalize3(self: Self) Self {