From 0d2c3acdc734751dca9097796adf777e2a0b1314 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Mon, 22 Nov 2021 00:24:16 +0100 Subject: [PATCH] Add debug assertion --- src/utils/geometry.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils/geometry.rs b/src/utils/geometry.rs index 50a84e2..80b6823 100644 --- a/src/utils/geometry.rs +++ b/src/utils/geometry.rs @@ -18,7 +18,7 @@ pub struct Buffer; pub struct Raw; pub trait Coordinate: - Sized + Add + Sub + PartialOrd + Default + Copy + std::fmt::Debug + Sized + Add + Sub + PartialOrd + Default + Copy + fmt::Debug { fn downscale(self, scale: Self) -> Self; fn upscale(self, scale: Self) -> Self; @@ -637,9 +637,16 @@ impl AddAssign for Size { } } -impl SubAssign for Size { +impl SubAssign for Size { #[inline] fn sub_assign(&mut self, rhs: Self) { + debug_assert!( + self.w >= rhs.w && self.h >= rhs.h, + "Attempting to subtract bigger from smaller size: {:?} - {:?}", + (&self.w, &self.h), + (&rhs.w, &rhs.h), + ); + self.w -= rhs.w; self.h -= rhs.h }