Implement some std::op traits for Pixel
This commit is contained in:
1 parent
25f2db9765
commit
bab002fefd
1 file changed
+62
@@ -44,6 +44,68 @@ impl Extent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pixel {
|
||||
pub fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
|
||||
Self { r, g, b, a }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign for Pixel {
|
||||
fn add_assign(&mut self, other: Pixel) {
|
||||
self.r += other.r;
|
||||
self.g += other.g;
|
||||
self.b += other.b;
|
||||
self.a += other.a;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::MulAssign<f32> for Pixel {
|
||||
fn mul_assign(&mut self, scalar: f32) {
|
||||
self.r *= scalar;
|
||||
self.g *= scalar;
|
||||
self.b *= scalar;
|
||||
self.a *= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<f32> for Pixel {
|
||||
fn div_assign(&mut self, scalar: f32) {
|
||||
self.r /= scalar;
|
||||
self.g /= scalar;
|
||||
self.b /= scalar;
|
||||
self.a /= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for Pixel {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> for Pixel {
|
||||
type Output = Self;
|
||||
|
||||
fn div(mut self, scalar: f32) -> Self {
|
||||
self /= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for Pixel {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
r: 0.0,
|
||||
g: 0.0,
|
||||
b: 0.0,
|
||||
a: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
Error::Io(error)
|
||||
|
||||
Reference in new issue
Block a user