For context, I'm learning Zig alongside Raylib in preparation for making a game engine. Things are mostly going great... Besides painstakingly large amounts of explicit type conversions that I'm running into. Something that should be as simple as:
rl.drawPixel(x, y,
rl.Color{ .r = 255, .b = 255, .g = 255,
.a = 255 * (1 - std.math.sqrt(x * x + y * y) / max_dist)
}
);
due to extremely verbose casting, turns into this mess:
rl.drawPixel(@as(u8, @intCast(x)), @as(u8, @intcast(y)),
rl.Color{ .r = 255, .g = 255, .b = 255,
.a = @as(u8, @intFromFloat(
255 * (1 - (
@as(f32, @floatFromInt(
std.math.sqrt(x * x + y * y)
))
/
@as(f32, @floatFromInt(max_dist)))
)
))
}
);
Am I really doing this in the intended way? I came to Zig for the ideals of readability and debugging code rather than the language... But this has been the opposite for me.