Skip to content

Commit a424ede

Browse files
committed
src: Angle fixes and test cases
1 parent 08721d8 commit a424ede

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

docs/sources.tar

1.5 KB
Binary file not shown.

src/ff.zig

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,28 +388,57 @@ test "Rect.contains returns expected results" {
388388
/// can be created [from_degrees](#ff.Angle.from_degrees)
389389
/// and [from_radians](#ff.Angle.from_radians)
390390
pub const Angle = struct {
391-
radians: f32,
391+
radians: f32 = 0,
392392

393393
/// The 360° angle.
394-
pub const full_circle: Angle = Angle(tau);
394+
pub const full_circle: Angle = Angle{ .radians = tau };
395395
/// The 180° angle.
396-
pub const half_circle: Angle = Angle(pi);
396+
pub const half_circle: Angle = Angle{ .radians = pi };
397397
/// The 90° angle.
398-
pub const quarter_circle: Angle = Angle(pi / 2.0);
398+
pub const quarter_circle: Angle = Angle{ .radians = pi / 2.0 };
399399
/// The 0° angle.
400-
pub const zero: Angle = Angle(0.0);
400+
pub const zero: Angle = Angle{};
401401

402-
/// An angle in radians where Tau (doubled Pi) is the full circle.
402+
/// An Angle in radians where `tau` (doubled `pi`) is the full circle.
403403
pub fn from_radians(r: f32) Angle {
404-
return Angle{r};
404+
return Angle{ .radians = r };
405405
}
406406

407-
/// An angle in degrees where 360.0 is the full circle.
407+
/// An Angle in degrees where **360.0** is the full circle.
408408
pub fn from_degrees(d: f32) Angle {
409-
return Angle{d * pi / 180.0};
409+
return Angle{ .radians = d * pi / 180.0 };
410410
}
411411
};
412412

413+
test "Angle.full_circle returns expected value" {
414+
try std.testing.expectEqual(Angle{ .radians = tau }, Angle.full_circle);
415+
}
416+
417+
test "Angle.half_circle returns expected value" {
418+
try std.testing.expectEqual(Angle{ .radians = pi }, Angle.half_circle);
419+
}
420+
421+
test "Angle.quarter_circle returns expected value" {
422+
try std.testing.expectEqual(Angle{ .radians = pi / 2.0 }, Angle.quarter_circle);
423+
}
424+
425+
test "Angle.zero returns expected value" {
426+
try std.testing.expectEqual(Angle{}, Angle.zero);
427+
try std.testing.expectEqual(Angle{ .radians = 0 }, Angle.zero);
428+
}
429+
430+
test "Angle.from_radians returns expected value" {
431+
try std.testing.expectEqual(Angle{ .radians = pi }, Angle.from_radians(pi));
432+
try std.testing.expectEqual(Angle{ .radians = tau }, Angle.from_radians(tau));
433+
}
434+
435+
test "Angle.from_degrees returns expected value" {
436+
try std.testing.expectEqual(Angle{ .radians = tau }, Angle.from_degrees(360.0));
437+
try std.testing.expectEqual(Angle{ .radians = pi }, Angle.from_degrees(180.0));
438+
try std.testing.expectEqual(Angle{ .radians = -pi }, Angle.from_degrees(-180.0));
439+
try std.testing.expectEqual(Angle{ .radians = 0 }, Angle.from_degrees(0.0));
440+
}
441+
413442
/// RGB color value containing r, g, and b.
414443
///
415444
/// Can be created [from_hex](#ff.RGB.from_hex).

0 commit comments

Comments
 (0)