Function degreesToRadians [src]
Converts an angle in degrees to radians. T must be a float or comptime number or a vector of floats.
Prototype
pub fn degreesToRadians(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime_float else @TypeOf(ang)
Example
test degreesToRadians {
const ninety: f32 = 90;
const neg_two_seventy: f32 = -270;
const three_sixty: f32 = 360;
try std.testing.expectApproxEqAbs(@as(f32, pi / 2.0), degreesToRadians(ninety), 1e-6);
try std.testing.expectApproxEqAbs(@as(f32, -3 * pi / 2.0), degreesToRadians(neg_two_seventy), 1e-6);
try std.testing.expectApproxEqAbs(@as(f32, 2 * pi), degreesToRadians(three_sixty), 1e-6);
const result = degreesToRadians(@Vector(3, f32){
ninety,
neg_two_seventy,
three_sixty,
});
try std.testing.expectApproxEqAbs(@as(f32, pi / 2.0), result[0], 1e-6);
try std.testing.expectApproxEqAbs(@as(f32, -3 * pi / 2.0), result[1], 1e-6);
try std.testing.expectApproxEqAbs(@as(f32, 2 * pi), result[2], 1e-6);
}
Source
pub fn degreesToRadians(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime_float else @TypeOf(ang) {
const T = @TypeOf(ang);
switch (@typeInfo(T)) {
.float, .comptime_float, .comptime_int => return ang * rad_per_deg,
.vector => |V| if (@typeInfo(V.child) == .float) return ang * @as(T, @splat(rad_per_deg)),
else => {},
}
@compileError("Input must be float or a comptime number, or a vector of floats.");
}