fix: seems like a lot more colors needed fixing

This commit is contained in:
lisk77 2025-03-14 00:18:30 +01:00
parent 81d3b2f714
commit dcd2d025ba
3 changed files with 8 additions and 5 deletions

View file

@ -58,11 +58,11 @@ impl Laba {
}
pub fn to_lcha(&self) -> Lcha {
let atan: f32 = self.b.atan2(self.a);
let hue: f32 = self.b.atan2(self.a).to_degrees();
Lcha::new(
self.lightness,
(self.a*self.a + self.b*self.b).sqrt(),
if atan >= 0.0 { atan } else { atan + 360.0 },
if hue < 0.0 { hue + 360.0 } else { hue },
self.alpha
)
}

View file

@ -78,10 +78,11 @@ impl Oklaba {
}
pub fn to_oklcha(&self) -> Oklcha {
let hue = self.b.atan2(self.a).to_degrees();
Oklcha::new(
self.lightness,
(self.a*self.a + self.b*self.b).sqrt(),
self.b.atan2(self.a),
if hue >= 0.0 { hue } else { hue + 360.0 },
self.alpha
)
}

View file

@ -10,6 +10,7 @@ pub struct Oklcha {
impl Oklcha {
pub fn new(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Self {
println!("lightness: {}, chroma: {}, hue: {}, alpha: {}", lightness, chroma, hue, alpha);
assert!((0.0..=1.0).contains(&lightness) && (0.0..=1.0).contains(&chroma) && (0.0..=360.0).contains(&hue) && (0.0..=1.0).contains(&alpha), "Ligthness needs to be in range 0..1\nChroma needs to be in range 0..1\nHue needs to be in range 0..360\nAlpha needs to be in range 0..1");
Self {
lightness,
@ -36,10 +37,11 @@ impl Oklcha {
}
pub fn from_oklaba(oklaba: Oklaba) -> Self {
let hue = oklaba.b().atan2(oklaba.a()).to_degrees();
Self {
lightness: oklaba.lightness(),
chroma: (oklaba.a()*oklaba.a() + oklaba.b()*oklaba.b()).sqrt(),
hue: oklaba.b().atan2(oklaba.a()),
chroma: (oklaba.a() * oklaba.a() + oklaba.b() * oklaba.b()).sqrt(),
hue: if hue >= 0.0 { hue } else { hue + 360.0 },
alpha: oklaba.alpha()
}
}