Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Div<f64> and Mul<f64> for Insets #384

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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