Compare regions, not four loose numbers

`PixelRegion` derives `PartialEq`, `Clone` and `Copy`, so `assert_corners!`
compares one against another instead of flattening both to a tuple whose
order there was nothing to check. A failure now prints two regions.
This commit is contained in:
iris committed 2026-09-13 21:42:21 -04:00
1 parent 0f9f379cec
commit 7cefc72f97
2 files changed
+9 -13

No files matched your search

+1 -1
View File
@@ -421,7 +421,7 @@ impl Display for UiRegion {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PixelRegion {
pub top_left: Vec2,
pub bot_right: Vec2,
+8 -12
View File
@@ -22,22 +22,18 @@ impl TaskQueue<DefaultRsc<HarnessState>> for Queue {
}
}
/// `assert_eq!` for where a frame put a widget, which `PixelRegion` cannot do
/// for itself: it neither compares nor prints.
/// `assert_eq!` for where a frame put a widget, written as its two corners.
#[macro_export]
macro_rules! assert_corners {
($harness:expr, $id:expr, ($x0:expr, $y0:expr), ($x1:expr, $y1:expr)) => {{
let region = $harness.region(&$id).expect("widget drew nothing");
($harness:expr, $id:expr, ($x0:expr, $y0:expr), ($x1:expr, $y1:expr)) => {
assert_eq!(
(
region.top_left.x,
region.top_left.y,
region.bot_right.x,
region.bot_right.y
),
($x0 as f32, $y0 as f32, $x1 as f32, $y1 as f32)
$harness.region(&$id).expect("widget drew nothing"),
$crate::core::PixelRegion {
top_left: $crate::core::util::Vec2::new($x0 as f32, $y0 as f32),
bot_right: $crate::core::util::Vec2::new($x1 as f32, $y1 as f32),
}
);
}};
};
}
pub use crate::assert_corners;