# HG changeset patch # User unC0Rr # Date 1725354976 -7200 # Node ID d4675c190fa5c7eacee7f722d17e6f10368d9dcf # Parent ce4b50823a95e5b40ea2ebf1c1452d6a7e2c99cf Make Point::with_margin function safe to use diff -r ce4b50823a95 -r d4675c190fa5 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) }