Implement derive macro for Pixel
This commit is contained in:
1 parent
689144db8f
commit
e75d56e23a
7 files changed
+179
-164
No files matched your search
+4
-111
@@ -1,4 +1,6 @@
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
use ccvl_proc_macros::Pixel;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pixel)]
|
||||
pub struct SRGBA {
|
||||
pub r: f32,
|
||||
pub g: f32,
|
||||
@@ -6,7 +8,7 @@ pub struct SRGBA {
|
||||
pub a: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pixel)]
|
||||
pub struct SRGB {
|
||||
pub r: f32,
|
||||
pub g: f32,
|
||||
@@ -18,117 +20,8 @@ impl SRGBA {
|
||||
Self { r, g, b, a }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign for SRGBA {
|
||||
fn add_assign(&mut self, other: SRGBA) {
|
||||
self.r += other.r;
|
||||
self.g += other.g;
|
||||
self.b += other.b;
|
||||
self.a += other.a;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::MulAssign<f32> for SRGBA {
|
||||
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 SRGBA {
|
||||
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 SRGBA {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> for SRGBA {
|
||||
type Output = Self;
|
||||
|
||||
fn div(mut self, scalar: f32) -> Self {
|
||||
self /= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for SRGBA {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
r: 0.0,
|
||||
g: 0.0,
|
||||
b: 0.0,
|
||||
a: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SRGB {
|
||||
pub fn new(r: f32, g: f32, b: f32) -> Self {
|
||||
Self { r, g, b }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign for SRGB {
|
||||
fn add_assign(&mut self, other: SRGB) {
|
||||
self.r += other.r;
|
||||
self.g += other.g;
|
||||
self.b += other.b;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::MulAssign<f32> for SRGB {
|
||||
fn mul_assign(&mut self, scalar: f32) {
|
||||
self.r *= scalar;
|
||||
self.g *= scalar;
|
||||
self.b *= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<f32> for SRGB {
|
||||
fn div_assign(&mut self, scalar: f32) {
|
||||
self.r /= scalar;
|
||||
self.g /= scalar;
|
||||
self.b /= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for SRGB {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> for SRGB {
|
||||
type Output = Self;
|
||||
|
||||
fn div(mut self, scalar: f32) -> Self {
|
||||
self /= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for SRGB {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
r: 0.0,
|
||||
g: 0.0,
|
||||
b: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user