From 6103094473a7b947957214016fb45d38b0aeb2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Mon, 13 May 2024 22:15:12 +0900 Subject: [PATCH] Add Rectangle tests --- src/geometry.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/geometry.zig b/src/geometry.zig index 76c1680..5cd0535 100644 --- a/src/geometry.zig +++ b/src/geometry.zig @@ -66,6 +66,18 @@ pub fn Rectangle(comptime T: type) type { }; } +test "Rectangle" { + const irect = Rectangle(isize){ .l = 0, .t = 0, .r = 639, .b = 479 }; + try expectEqual(irect.width(), 640); + try expectEqual(irect.height(), 480); + const frect = Rectangle(f64){ .l = 0, .t = 0, .r = 639, .b = 479 }; + try expectEqual(frect.width(), 640); + try expectEqual(frect.height(), 480); + try expectEqual(frect.contains(640 / 2, 480 / 2), true); + try expectEqual(irect.contains(640, 480), false); + try expectEqualDeep(frect.cast(isize), irect); +} + /// Applies a projective transform to a point. By default, it will be initialized to the identity /// function. Use the fit method to update the transform to map between two sets of points. pub fn ProjectiveTransform(comptime T: type) type {