Skip to content

Commit

Permalink
Implement Div<f64> and Mul<f64> for Insets (#384)
Browse files Browse the repository at this point in the history
This can be useful, for example, for applying scaling factor to
`Insets`.
  • Loading branch information
liferooter authored Dec 7, 2024
1 parent 8f074e9 commit ebb8553
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/insets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -279,6 +279,32 @@ impl Sub<Rect> for Insets {
}
}

impl Mul<f64> 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<f64> 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<Insets> for Rect {
type Output = Rect;

Expand Down

0 comments on commit ebb8553

Please sign in to comment.