Refactor base float type to f64 for accuracy and add gravity

This commit is contained in:
Alex Selimov 2026-08-06 09:37:03 -04:00
parent e27ba9a558
commit d9e4e06c78
5 changed files with 183 additions and 158 deletions

15
src/forces.zig Normal file
View file

@ -0,0 +1,15 @@
const constants = @import("./constants.zig");
const vec3 = @import("./vec3.zig");
const std = @import("std");
pub fn gravity(mass: f64) vec3.Vec3F64 {
return .init(0, 0, mass * constants.g);
}
test "gravity is correct" {
const mass = 10;
const fg = gravity(mass);
try std.testing.expect(std.math.approxEqAbs(f64, fg.x(), 0, 1e-12));
try std.testing.expect(std.math.approxEqAbs(f64, fg.y(), 0, 1e-12));
try std.testing.expect(std.math.approxEqAbs(f64, fg.z(), constants.g * mass, 1e-12));
}