diff --git a/graphene/src/vec2.rs b/graphene/src/vec2.rs index dbfd937c8dd5..d8a2e59fb386 100644 --- a/graphene/src/vec2.rs +++ b/graphene/src/vec2.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::fmt; +use std::{fmt, ops}; use glib::translate::*; @@ -52,3 +52,83 @@ impl Default for Vec2 { Self::zero() } } + +// addition/subtraction +impl ops::Add for Vec2 { + type Output = Vec2; + + fn add(self, rhs: Vec2) -> Self::Output { + (&self).add(&rhs) + } +} +impl ops::AddAssign for Vec2 { + fn add_assign(&mut self, rhs: Vec2) { + *self = *self + rhs; + } +} +impl ops::Sub for Vec2 { + type Output = Vec2; + + fn sub(self, rhs: Vec2) -> Self::Output { + (&self).subtract(&rhs) + } +} +impl ops::SubAssign for Vec2 { + fn sub_assign(&mut self, rhs: Vec2) { + *self = *self - rhs; + } +} +impl ops::Neg for Vec2 { + type Output = Vec2; + + fn neg(self) -> Self::Output { + (&self).negate() + } +} + +// scalar multiplication +impl ops::Mul for Vec2 { + type Output = Vec2; + + fn mul(self, rhs: f32) -> Self::Output { + (&self).scale(rhs) + } +} +impl ops::MulAssign for Vec2 { + fn mul_assign(&mut self, rhs: f32) { + *self = *self * rhs; + } +} +impl ops::Mul for f32 { + type Output = Vec2; + + fn mul(self, rhs: Vec2) -> Self::Output { + rhs * self + } +} + +// Component-wise multiplication/division +impl ops::Mul for Vec2 { + type Output = Vec2; + + fn mul(self, rhs: Vec2) -> Self::Output { + (&self).multiply(&rhs) + } +} +impl ops::MulAssign for Vec2 { + fn mul_assign(&mut self, rhs: Vec2) { + *self = *self * rhs; + } +} +impl ops::Div for Vec2 { + type Output = Vec2; + + fn div(self, rhs: Vec2) -> Self::Output { + (&self).divide(&rhs) + } +} +impl ops::DivAssign for Vec2 { + fn div_assign(&mut self, rhs: Vec2) { + *self = *self / rhs; + } +} \ No newline at end of file diff --git a/graphene/src/vec3.rs b/graphene/src/vec3.rs index fc73ab5b0f8f..602033f765cf 100644 --- a/graphene/src/vec3.rs +++ b/graphene/src/vec3.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::fmt; +use std::{fmt, ops}; use glib::translate::*; @@ -53,3 +53,83 @@ impl Default for Vec3 { Self::zero() } } + +// addition/subtraction +impl ops::Add for Vec3 { + type Output = Vec3; + + fn add(self, rhs: Vec3) -> Self::Output { + (&self).add(&rhs) + } +} +impl ops::AddAssign for Vec3 { + fn add_assign(&mut self, rhs: Vec3) { + *self = *self + rhs; + } +} +impl ops::Sub for Vec3 { + type Output = Vec3; + + fn sub(self, rhs: Vec3) -> Self::Output { + (&self).subtract(&rhs) + } +} +impl ops::SubAssign for Vec3 { + fn sub_assign(&mut self, rhs: Vec3) { + *self = *self - rhs; + } +} +impl ops::Neg for Vec3 { + type Output = Vec3; + + fn neg(self) -> Self::Output { + (&self).negate() + } +} + +// scalar multiplication +impl ops::Mul for Vec3 { + type Output = Vec3; + + fn mul(self, rhs: f32) -> Self::Output { + (&self).scale(rhs) + } +} +impl ops::MulAssign for Vec3 { + fn mul_assign(&mut self, rhs: f32) { + *self = *self * rhs; + } +} +impl ops::Mul for f32 { + type Output = Vec3; + + fn mul(self, rhs: Vec3) -> Self::Output { + rhs * self + } +} + +// Component-wise multiplication/division +impl ops::Mul for Vec3 { + type Output = Vec3; + + fn mul(self, rhs: Vec3) -> Self::Output { + (&self).multiply(&rhs) + } +} +impl ops::MulAssign for Vec3 { + fn mul_assign(&mut self, rhs: Vec3) { + *self = *self * rhs; + } +} +impl ops::Div for Vec3 { + type Output = Vec3; + + fn div(self, rhs: Vec3) -> Self::Output { + (&self).divide(&rhs) + } +} +impl ops::DivAssign for Vec3 { + fn div_assign(&mut self, rhs: Vec3) { + *self = *self / rhs; + } +} diff --git a/graphene/src/vec4.rs b/graphene/src/vec4.rs index 7fcaa481f775..c71b2de03c78 100644 --- a/graphene/src/vec4.rs +++ b/graphene/src/vec4.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::fmt; +use std::{fmt, ops}; use glib::translate::*; @@ -76,3 +76,83 @@ impl Default for Vec4 { Self::zero() } } + +// addition/subtraction +impl ops::Add for Vec4 { + type Output = Vec4; + + fn add(self, rhs: Vec4) -> Self::Output { + (&self).add(&rhs) + } +} +impl ops::AddAssign for Vec4 { + fn add_assign(&mut self, rhs: Vec4) { + *self = *self + rhs; + } +} +impl ops::Sub for Vec4 { + type Output = Vec4; + + fn sub(self, rhs: Vec4) -> Self::Output { + (&self).subtract(&rhs) + } +} +impl ops::SubAssign for Vec4 { + fn sub_assign(&mut self, rhs: Vec4) { + *self = *self - rhs; + } +} +impl ops::Neg for Vec4 { + type Output = Vec4; + + fn neg(self) -> Self::Output { + (&self).negate() + } +} + +// scalar multiplication +impl ops::Mul for Vec4 { + type Output = Vec4; + + fn mul(self, rhs: f32) -> Self::Output { + (&self).scale(rhs) + } +} +impl ops::MulAssign for Vec4 { + fn mul_assign(&mut self, rhs: f32) { + *self = *self * rhs; + } +} +impl ops::Mul for f32 { + type Output = Vec4; + + fn mul(self, rhs: Vec4) -> Self::Output { + rhs * self + } +} + +// Component-wise multiplication/division +impl ops::Mul for Vec4 { + type Output = Vec4; + + fn mul(self, rhs: Vec4) -> Self::Output { + (&self).multiply(&rhs) + } +} +impl ops::MulAssign for Vec4 { + fn mul_assign(&mut self, rhs: Vec4) { + *self = *self * rhs; + } +} +impl ops::Div for Vec4 { + type Output = Vec4; + + fn div(self, rhs: Vec4) -> Self::Output { + (&self).divide(&rhs) + } +} +impl ops::DivAssign for Vec4 { + fn div_assign(&mut self, rhs: Vec4) { + *self = *self / rhs; + } +}