From 6f9b7a9005f4d1c6b84192481d54e6c8bf91435e Mon Sep 17 00:00:00 2001 From: Andy Terra <152812+airstrike@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:32:37 -0500 Subject: [PATCH 1/2] Implement division operation for `Rectangle`, `Size` and `Vector` --- core/src/rectangle.rs | 29 +++++++++++++++++++++++++++++ core/src/size.rs | 14 ++++++++++++++ core/src/vector.rs | 11 +++++++++++ 3 files changed, 54 insertions(+) diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index 0a08bbe4..afc15cc8 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -354,6 +354,19 @@ impl std::ops::Mul for Rectangle { } } +impl std::ops::Div for Rectangle { + type Output = Self; + + fn div(self, scale: f32) -> Self { + Self { + x: self.x / scale, + y: self.y / scale, + width: self.width / scale, + height: self.height / scale, + } + } +} + impl From> for Rectangle { fn from(rectangle: Rectangle) -> Rectangle { Rectangle { @@ -410,3 +423,19 @@ where } } } + +impl std::ops::Div> for Rectangle +where + T: std::ops::Div + Copy, +{ + type Output = Rectangle; + + fn div(self, scale: Vector) -> Self { + Rectangle { + x: self.x / scale.x, + y: self.y / scale.y, + width: self.width / scale.x, + height: self.height / scale.y, + } + } +} diff --git a/core/src/size.rs b/core/src/size.rs index 539135bc..baa80b01 100644 --- a/core/src/size.rs +++ b/core/src/size.rs @@ -150,6 +150,20 @@ where } } +impl std::ops::Div for Size +where + T: std::ops::Div + Copy, +{ + type Output = Size; + + fn div(self, rhs: T) -> Self::Output { + Size { + width: self.width / rhs, + height: self.height / rhs, + } + } +} + impl std::ops::Mul> for Size where T: std::ops::Mul + Copy, diff --git a/core/src/vector.rs b/core/src/vector.rs index ff848c4f..4da0fa28 100644 --- a/core/src/vector.rs +++ b/core/src/vector.rs @@ -64,6 +64,17 @@ where } } +impl std::ops::Div for Vector +where + T: std::ops::Div + Copy, +{ + type Output = Self; + + fn div(self, scale: T) -> Self { + Self::new(self.x / scale, self.y / scale) + } +} + impl Default for Vector where T: Default, From e51d7c723c7b6c49d1d132bc7084eac95059aa3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 20 Nov 2025 02:03:01 +0100 Subject: [PATCH 2/2] Remove `Mul` and `Div` implementations for `Rectangle` --- core/src/rectangle.rs | 45 ------------------------------------------- 1 file changed, 45 deletions(-) diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index afc15cc8..e417d08d 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -354,19 +354,6 @@ impl std::ops::Mul for Rectangle { } } -impl std::ops::Div for Rectangle { - type Output = Self; - - fn div(self, scale: f32) -> Self { - Self { - x: self.x / scale, - y: self.y / scale, - width: self.width / scale, - height: self.height / scale, - } - } -} - impl From> for Rectangle { fn from(rectangle: Rectangle) -> Rectangle { Rectangle { @@ -407,35 +394,3 @@ where } } } - -impl std::ops::Mul> for Rectangle -where - T: std::ops::Mul + Copy, -{ - type Output = Rectangle; - - fn mul(self, scale: Vector) -> Self { - Rectangle { - x: self.x * scale.x, - y: self.y * scale.y, - width: self.width * scale.x, - height: self.height * scale.y, - } - } -} - -impl std::ops::Div> for Rectangle -where - T: std::ops::Div + Copy, -{ - type Output = Rectangle; - - fn div(self, scale: Vector) -> Self { - Rectangle { - x: self.x / scale.x, - y: self.y / scale.y, - width: self.width / scale.x, - height: self.height / scale.y, - } - } -}