diff --git a/core/src/vector.rs b/core/src/vector.rs index 4da0fa28..1c84d6ca 100644 --- a/core/src/vector.rs +++ b/core/src/vector.rs @@ -1,5 +1,5 @@ /// A 2D vector. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct Vector { /// The X component of the [`Vector`] pub x: T, @@ -42,6 +42,16 @@ where } } +impl std::ops::AddAssign for Vector +where + T: std::ops::AddAssign, +{ + fn add_assign(&mut self, b: Self) { + self.x += b.x; + self.y += b.y; + } +} + impl std::ops::Sub for Vector where T: std::ops::Sub, @@ -53,6 +63,16 @@ where } } +impl std::ops::SubAssign for Vector +where + T: std::ops::SubAssign, +{ + fn sub_assign(&mut self, b: Self) { + self.x -= b.x; + self.y -= b.y; + } +} + impl std::ops::Mul for Vector where T: std::ops::Mul + Copy, @@ -64,6 +84,16 @@ where } } +impl std::ops::MulAssign for Vector +where + T: std::ops::MulAssign + Copy, +{ + fn mul_assign(&mut self, scale: T) { + self.x *= scale; + self.y *= scale; + } +} + impl std::ops::Div for Vector where T: std::ops::Div + Copy, @@ -75,15 +105,13 @@ where } } -impl Default for Vector +impl std::ops::DivAssign for Vector where - T: Default, + T: std::ops::DivAssign + Copy, { - fn default() -> Self { - Self { - x: T::default(), - y: T::default(), - } + fn div_assign(&mut self, scale: T) { + self.x /= scale; + self.y /= scale; } } diff --git a/selector/src/find.rs b/selector/src/find.rs index 37ffd713..cfdba7b3 100644 --- a/selector/src/find.rs +++ b/selector/src/find.rs @@ -211,7 +211,7 @@ where state, }); - self.translation = self.translation - translation; + self.translation -= translation; self.viewport = visible_bounds.unwrap_or_default(); }