From f13b68ebaded9f848485030b3baa2ed0e02acc23 Mon Sep 17 00:00:00 2001 From: Gleb Smirnov Date: Wed, 2 Oct 2024 21:22:42 +0300 Subject: [PATCH] Implement `Div` and `Mul` for `Insets` --- src/insets.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/insets.rs b/src/insets.rs index 03dd214a..b52a0b11 100644 --- a/src/insets.rs +++ b/src/insets.rs @@ -3,7 +3,7 @@ //! A description of the distances between the edges of two rectangles. -use core::ops::{Add, Neg, Sub}; +use core::ops::{Add, Div, Mul, Neg, Sub}; use crate::{Rect, Size}; @@ -279,6 +279,32 @@ impl Sub for Insets { } } +impl Mul for Insets { + type Output = Insets; + + fn mul(self, rhs: f64) -> Self::Output { + Self { + x0: self.x0 * rhs, + y0: self.y0 * rhs, + x1: self.x1 * rhs, + y1: self.y1 * rhs, + } + } +} + +impl Div for Insets { + type Output = Insets; + + fn div(self, rhs: f64) -> Self::Output { + Self { + x0: self.x0 / rhs, + y0: self.y0 / rhs, + x1: self.x1 / rhs, + y1: self.y1 / rhs, + } + } +} + impl Sub for Rect { type Output = Rect;