mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-22 19:08:39 +00:00
Merge pull request #3683 from Silvertree2010/fix/h1324-color-to-hsb-returns-hue-360-for
Wrap to_hsb hue of 360 back to 0 for near-red colours
This commit is contained in:
1 file changed
+8
@@ -146,6 +146,8 @@ impl Color {
|
|||||||
} else {
|
} else {
|
||||||
60.0 * ((r - g) / d + 4.0)
|
60.0 * ((r - g) / d + 4.0)
|
||||||
};
|
};
|
||||||
|
// f32 rounding in rem_euclid can yield exactly 360; wrap back to 0.
|
||||||
|
let h = if h >= 360.0 { 0.0 } else { h };
|
||||||
let s = if max <= 0.0 { 0.0 } else { d / max };
|
let s = if max <= 0.0 { 0.0 } else { d / max };
|
||||||
[h, s, max]
|
[h, s, max]
|
||||||
}
|
}
|
||||||
@@ -438,6 +440,12 @@ impl Paint {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hue_below_360() {
|
||||||
|
let h = Color::Rgb { r: 1.0, g: 0.0, b: 1e-7 }.to_hsb()[0];
|
||||||
|
assert!((0.0..360.0).contains(&h), "hue {h}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hex_roundtrip() {
|
fn hex_roundtrip() {
|
||||||
let c = Color::from_hex("#ff8000").unwrap();
|
let c = Color::from_hex("#ff8000").unwrap();
|
||||||
|
|||||||
Reference in new issue
Block a user