Add SubAssign, Add and Sub to Pixel trait requirements
This commit is contained in:
1 parent
e75d56e23a
commit
26a03c002a
2 files changed
+61
-31
No files matched your search
+55
-31
@@ -26,43 +26,67 @@ fn impl_pixel(name: syn::Ident, fields: Vec<syn::Ident>) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::MulAssign<f32> for #name {
|
impl std::ops::SubAssign for #name {
|
||||||
fn mul_assign(&mut self, scalar: f32) {
|
fn sub_assign(&mut self, other: Self) {
|
||||||
#( self.#fields *= scalar; )*
|
#( self.#fields -= other.#fields; )*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::DivAssign<f32> for #name {
|
impl std::ops::MulAssign<f32> for #name {
|
||||||
fn div_assign(&mut self, scalar: f32) {
|
fn mul_assign(&mut self, scalar: f32) {
|
||||||
#( self.#fields /= scalar; )*
|
#( self.#fields *= scalar; )*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Mul<f32> for #name {
|
impl std::ops::DivAssign<f32> for #name {
|
||||||
type Output = Self;
|
fn div_assign(&mut self, scalar: f32) {
|
||||||
|
#( self.#fields /= scalar; )*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn mul(mut self, scalar: f32) -> Self {
|
impl std::ops::Add for #name {
|
||||||
self *= scalar;
|
type Output = Self;
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::ops::Div<f32> for #name {
|
fn add(mut self, other: Self) -> Self {
|
||||||
type Output = Self;
|
self += other;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn div(mut self, scalar: f32) -> Self {
|
impl std::ops::Sub for #name {
|
||||||
self /= scalar;
|
type Output = Self;
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::default::Default for #name {
|
fn sub(mut self, other: Self) -> Self {
|
||||||
fn default() -> Self {
|
self -= other;
|
||||||
Self {
|
self
|
||||||
#( #fields: Default::default(), )*
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
impl std::ops::Mul<f32> for #name {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(mut self, scalar: f32) -> Self {
|
||||||
|
self *= scalar;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Div<f32> for #name {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn div(mut self, scalar: f32) -> Self {
|
||||||
|
self /= scalar;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::default::Default for #name {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
#( #fields: Default::default(), )*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
@@ -36,8 +36,11 @@ pub trait Format<P> {
|
|||||||
|
|
||||||
pub trait Pixel:
|
pub trait Pixel:
|
||||||
std::ops::AddAssign
|
std::ops::AddAssign
|
||||||
|
+ std::ops::SubAssign
|
||||||
+ std::ops::MulAssign<f32>
|
+ std::ops::MulAssign<f32>
|
||||||
+ std::ops::DivAssign<f32>
|
+ std::ops::DivAssign<f32>
|
||||||
|
+ std::ops::Add<Output = Self>
|
||||||
|
+ std::ops::Sub<Output = Self>
|
||||||
+ std::ops::Mul<f32, Output = Self>
|
+ std::ops::Mul<f32, Output = Self>
|
||||||
+ std::ops::Div<f32, Output = Self>
|
+ std::ops::Div<f32, Output = Self>
|
||||||
+ Clone
|
+ Clone
|
||||||
@@ -51,8 +54,11 @@ pub trait Pixel:
|
|||||||
|
|
||||||
impl<P> Pixel for P where
|
impl<P> Pixel for P where
|
||||||
P: std::ops::AddAssign
|
P: std::ops::AddAssign
|
||||||
|
+ std::ops::SubAssign
|
||||||
+ std::ops::MulAssign<f32>
|
+ std::ops::MulAssign<f32>
|
||||||
+ std::ops::DivAssign<f32>
|
+ std::ops::DivAssign<f32>
|
||||||
|
+ std::ops::Add<Output = Self>
|
||||||
|
+ std::ops::Sub<Output = Self>
|
||||||
+ std::ops::Mul<f32, Output = Self>
|
+ std::ops::Mul<f32, Output = Self>
|
||||||
+ std::ops::Div<f32, Output = Self>
|
+ std::ops::Div<f32, Output = Self>
|
||||||
+ Clone
|
+ Clone
|
||||||
|
|||||||
Reference in new issue
Block a user