From 0273e12902fee8f49485d124bd89449d00a170a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20D=2E=20Sch=C3=BCller?= Date: Tue, 3 Oct 2023 22:59:18 +0200 Subject: [PATCH] math: Implement function to determine Ray hit fallback precision --- src/math/ray.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/math/ray.zig b/src/math/ray.zig index 15211d5f..5d39cadc 100644 --- a/src/math/ray.zig +++ b/src/math/ray.zig @@ -5,7 +5,20 @@ const testing = mach.testing; const math = mach.math; const vec = @import("vec.zig"); -fn maxDim(v: math.Vec3) u32 { +// Determine the fallback precision for valid floating point precisions +// our Ray computations can have. Will return twice the input precision +fn floatFallbackPrecision(comptime float_precision: type) type { + switch (float_precision) { + f16 => return f32, + f32 => return f64, + f64 => return f128, + else => @compileError("Expected f16, f32, f64, found '" ++ + @typeName(float_precision) ++ "'"), + } +} + +// Determine the 3D vector dimension with the largest scalar value +fn maxDim(v: math.Vec3) u8 { if (v.v[0] > v.v[1]) { if (v.v[0] > v.v[2]) { return 0;