Make Point::with_margin function safe to use transitional_engine
authorunC0Rr
Tue, 03 Sep 2024 11:16:16 +0200
branchtransitional_engine
changeset 16027 d4675c190fa5
parent 16026 ce4b50823a95
child 16028 509ecce37522
Make Point::with_margin function safe to use
rust/integral-geometry/src/lib.rs
--- a/rust/integral-geometry/src/lib.rs	Thu Aug 29 17:09:39 2024 +0200
+++ b/rust/integral-geometry/src/lib.rs	Tue Sep 03 11:16:16 2024 +0200
@@ -496,7 +496,7 @@
 
     #[inline]
     pub fn with_margin(&self, margin: i32) -> Self {
-        let offset = Point::diag(margin);
+        let offset = Point::new(min(margin, self.width() as i32 / 2), min(margin, self.height() as i32 / 2));
         Self::new(self.top_left() + offset, self.bottom_right() - offset)
     }