feat: added to_linear as a function of the Color trait

This commit is contained in:
lisk77 2025-04-26 20:10:11 +02:00
parent 6afa254e9d
commit 3a4090a6ec
11 changed files with 36 additions and 0 deletions

View file

@ -106,6 +106,10 @@ impl Color for Hsla {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.hue, self.saturation, self.lightness, self.alpha)
}

View file

@ -103,6 +103,9 @@ impl Color for Hsva {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.hue, self.saturation, self.value, self.alpha)

View file

@ -166,6 +166,9 @@ impl Color for Hwba {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.hue, self.whiteness, self.blackness, self.alpha)

View file

@ -147,6 +147,9 @@ impl Color for Laba {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.lightness, self.a, self.b, self.alpha)

View file

@ -97,6 +97,9 @@ impl Color for Lcha {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.lightness, self.chroma, self.hue, self.alpha)

View file

@ -24,6 +24,7 @@ mod oklcha;
pub trait Color: Copy {
fn to_wgpu(&self) -> wgpu::Color;
fn to_linear(&self) -> LinearRgba;
fn to_vec(&self) -> v4;
fn from_vec(color: v4) -> Self;
}

View file

@ -136,6 +136,10 @@ impl Color for LinearRgba {
}
}
fn to_linear(&self) -> LinearRgba {
self.clone()
}
fn to_vec(&self) -> v4 {
v4::new(self.red, self.green, self.blue, self.alpha)
}

View file

@ -117,6 +117,9 @@ impl Color for Oklaba {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.lightness, self.a, self.b, self.alpha)

View file

@ -96,6 +96,9 @@ impl Color for Oklcha {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.lightness, self.chroma, self.hue, self.alpha)

View file

@ -348,6 +348,9 @@ impl Color for sRgba<f32> {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.red, self.green, self.blue, self.alpha)
@ -362,6 +365,9 @@ impl Color for sRgba<u8> {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(

View file

@ -113,6 +113,9 @@ impl Color for Xyza {
fn to_wgpu(&self) -> wgpu::Color {
self.to_linear().to_wgpu()
}
fn to_linear(&self) -> LinearRgba {
self.to_linear()
}
fn to_vec(&self) -> v4 {
v4::new(self.x, self.y, self.z, self.alpha)