diff --git a/geometry/src/rect.rs b/geometry/src/rect.rs index e8c1194e..858c2712 100644 --- a/geometry/src/rect.rs +++ b/geometry/src/rect.rs @@ -12,7 +12,7 @@ use crate::vector::{IntoVector2F, Vector2F, Vector2I}; use pathfinder_simd::default::{F32x4, I32x4}; -use std::ops::{Add, Mul}; +use std::ops::{Add, Mul, Sub}; #[derive(Clone, Copy, Debug, PartialEq, Default)] pub struct RectF(pub F32x4); @@ -198,6 +198,14 @@ impl Add for RectF { } } +impl Add for RectF { + type Output = RectF; + #[inline] + fn add(self, other: f32) -> RectF { + RectF::new(self.origin() + other, self.size()) + } +} + impl Mul for RectF { type Output = RectF; #[inline] @@ -214,6 +222,22 @@ impl Mul for RectF { } } +impl Sub for RectF { + type Output = RectF; + #[inline] + fn sub(self, other: Vector2F) -> RectF { + RectF::new(self.origin() - other, self.size()) + } +} + +impl Sub for RectF { + type Output = RectF; + #[inline] + fn sub(self, other: f32) -> RectF { + RectF::new(self.origin() - other, self.size()) + } +} + /// NB: The origin is inclusive, while the lower right point is exclusive. #[derive(Clone, Copy, Debug, PartialEq, Default)] pub struct RectI(pub I32x4); diff --git a/geometry/src/vector.rs b/geometry/src/vector.rs index 77550c7b..a2031e25 100644 --- a/geometry/src/vector.rs +++ b/geometry/src/vector.rs @@ -200,6 +200,14 @@ impl Sub for Vector2F { } } +impl Sub for Vector2F { + type Output = Vector2F; + #[inline] + fn sub(self, other: f32) -> Vector2F { + self - Vector2F::splat(other) + } +} + impl Mul for Vector2F { type Output = Vector2F; #[inline]