Add some more operators to rects and vectors

This commit is contained in:
Patrick Walton 2020-04-02 11:59:11 -07:00
parent 542d2c27fa
commit 404d536254
2 changed files with 33 additions and 1 deletions

View File

@ -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<Vector2F> for RectF {
}
}
impl Add<f32> for RectF {
type Output = RectF;
#[inline]
fn add(self, other: f32) -> RectF {
RectF::new(self.origin() + other, self.size())
}
}
impl Mul<Vector2F> for RectF {
type Output = RectF;
#[inline]
@ -214,6 +222,22 @@ impl Mul<f32> for RectF {
}
}
impl Sub<Vector2F> for RectF {
type Output = RectF;
#[inline]
fn sub(self, other: Vector2F) -> RectF {
RectF::new(self.origin() - other, self.size())
}
}
impl Sub<f32> 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);

View File

@ -200,6 +200,14 @@ impl Sub<Vector2F> for Vector2F {
}
}
impl Sub<f32> for Vector2F {
type Output = Vector2F;
#[inline]
fn sub(self, other: f32) -> Vector2F {
self - Vector2F::splat(other)
}
}
impl Mul<Vector2F> for Vector2F {
type Output = Vector2F;
#[inline]