diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2a92f8b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,65 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'material_colors'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=material-colors" + ], + "filter": { + "name": "material_colors", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'theme'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=theme", + "--package=material-colors" + ], + "filter": { + "name": "theme", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'image'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=image", + "--package=material-colors" + ], + "filter": { + "name": "image", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d8e9b..c9a2eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,25 +8,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - **added**: Add tests for: - - 🟢 `mod:blend` - - 🟢 `mod:contrast` - - 🟢 `mod:dislike` - - 🟢 `mod:dynamic_color/dynamic_scheme` - - ⭕ `mod:dynamic_color` - - 🟢 `mod:hct/cam16` - - 🟢 `mod:hct` - - 🟢 `mod:hct/viewing_conditions` - - ⭕ `mod:palette/core` - - ⭕ `mod:palette/tonal` - - 🟢 `mod:quantize/quantizer_celebi` - - 🟢 `mod:quantize/quantizer_wsmeans` - - 🟢 `mod:quantize/quantizer_wu` - - 🟢 `mod:scheme/content` - - 🟢 `mod:utils/math` - -(Tests marked with a empty red circle are currently failing) - -- **fixed**: Fix stack overflow in QuantizerWu creation + - `mod:blend` + - `mod:contrast` + - `mod:dislike` + - `mod:dynamic_color/dynamic_scheme` + - `mod:dynamic_color` + - `mod:hct/cam16` + - `mod:hct` + - `mod:hct/viewing_conditions` + - `mod:palette/core` + - `mod:palette/tonal` + - `mod:quantize/quantizer_celebi` + - `mod:quantize/quantizer_wsmeans` + - `mod:quantize/quantizer_wu` + - `mod:scheme/content` + - `mod:utils/math` + +- **fixed**: Fix stack overflow in `struct:QuantizerWu` creation +- **fixed**: Fix `func:on_secondary_container` in `struct:MaterialDynamicColors` +- **fixed**: Fix `func:critical_plane_below` and `func:critical_plane_above` in `struct:HctSolver` ## 0.3.2 (May 8th, 2024) @@ -70,7 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **added:** Add support for the serde with the `serde` feature - **changed:** Update dependencies - **changed:** Update tests -- **fixed:** Fix `secondary_container` color in dynamic colors +- **fixed:** Fix `func:secondary_container` in `struct:MaterialDynamicColors` ## 0.1.6 (February 2nd, 2024) diff --git a/src/dynamic_color/material_dynamic_colors.rs b/src/dynamic_color/material_dynamic_colors.rs index 924ebf7..f8618bd 100644 --- a/src/dynamic_color/material_dynamic_colors.rs +++ b/src/dynamic_color/material_dynamic_colors.rs @@ -322,7 +322,13 @@ impl MaterialDynamicColors { define_key! { background secondary_container => secondary_palette; - [tone, scheme] => if _is_monochrome(scheme) { if scheme.is_dark { 30.0 } else { 85.0 } } else if _is_fidelity(scheme) { if scheme.is_dark { 30.0 } else { 90.0 } } else { Self::_find_desired_chroma_by_tone(scheme.secondary_palette.hue(), scheme.secondary_palette.chroma(), if scheme.is_dark { 30.0 } else { 90.0 }, !scheme.is_dark) }; + [tone, scheme] => { + let initial_tone = if scheme.is_dark { 30.0 } else { 90.0 }; + + if _is_monochrome(scheme) { if scheme.is_dark { 30.0 } else { 90.0 } } + else if !_is_fidelity(scheme) { initial_tone } + else { Self::_find_desired_chroma_by_tone(scheme.secondary_palette.hue(), scheme.secondary_palette.chroma(), initial_tone, !scheme.is_dark) } + }; [background, scheme] => Self::highest_surface(scheme); [contrast_curve] => ContrastCurve { low: 1.0, normal: 1.0, medium: 3.0, high: 4.5 }; [tone_delta_pair, _scheme] => ToneDeltaPair::new(Self::secondary_container(), Self::secondary(), 10.0, TonePolarity::Nearer, false); @@ -330,8 +336,14 @@ impl MaterialDynamicColors { define_key! { on_secondary_container => secondary_palette; - [tone, scheme] => if _is_fidelity(scheme) { DynamicColor::foreground_tone(Self::secondary_container().get_tone(scheme), 4.5) } else if scheme.is_dark { 90.0 } else { 10.0 }; - [background, scheme] => Self::highest_surface(scheme); + [tone, scheme] => if _is_fidelity(scheme) { + DynamicColor::foreground_tone((Self::secondary_container().tone)(scheme), 4.5) + } else if scheme.is_dark { + 90.0 + } else { + 10.0 + }; + [background, _scheme] => Self::secondary_container(); [contrast_curve] => ContrastCurve { low: 4.5, normal: 7.0, medium: 11.0, high: 21.0 }; } diff --git a/src/hct/solver.rs b/src/hct/solver.rs index d3a62ea..61944bc 100644 --- a/src/hct/solver.rs +++ b/src/hct/solver.rs @@ -494,12 +494,12 @@ impl HctSolver { ] } - fn critical_plane_below(x: f64) -> u8 { - (x - 0.5).floor() as u8 + fn critical_plane_below(x: f64) -> i16 { + (x - 0.5).floor() as i16 } - fn critical_plane_above(x: f64) -> u8 { - (x - 0.5).ceil() as u8 + fn critical_plane_above(x: f64) -> i16 { + (x - 0.5).ceil() as i16 } /// Finds a color with the given Y and hue on the boundary of the @@ -528,10 +528,11 @@ impl HctSolver { }; for _ in 0..8 { - if (i16::from(r_plane) - i16::from(l_plane)).abs() <= 1 { + if (r_plane - l_plane).abs() <= 1 { break; } - let m_plane = ((f32::from(l_plane) + f32::from(r_plane)) / 2.0).floor() as u8; + + let m_plane = ((f64::from(l_plane) + f64::from(r_plane)) / 2.0).floor() as i16; let mid_plane_coordinate = CRITICAL_PLANES[m_plane as usize]; let mid = Self::set_coordinate(left, mid_plane_coordinate, right, axis); let mid_hue = Self::hue_of(mid); @@ -660,6 +661,7 @@ impl HctSolver { } let [red, green, blue] = Self::bisect_to_limit(y, hue_radians); + let linrgb = LinearRgb { red, green, blue }; linrgb.into() diff --git a/src/quantize/quantizer_wu.rs b/src/quantize/quantizer_wu.rs index e9fd11f..f1ebeae 100644 --- a/src/quantize/quantizer_wu.rs +++ b/src/quantize/quantizer_wu.rs @@ -414,7 +414,7 @@ impl QuantizerWu { } } - pub fn volume(cube: &Cube, moment: &Box<[i64; TOTAL_SIZE]>) -> i64 { + pub fn volume(cube: &Cube, moment: &[i64; TOTAL_SIZE]) -> i64 { moment[Self::get_index::(cube.r(1), cube.g(1), cube.b(1))] - moment[Self::get_index::(cube.r(1), cube.g(1), cube.b(0))] - moment[Self::get_index::(cube.r(1), cube.g(0), cube.b(1))] @@ -425,7 +425,7 @@ impl QuantizerWu { - moment[Self::get_index::(cube.r(0), cube.g(0), cube.b(0))] } - pub fn bottom(cube: &Cube, direction: &Direction, moment: &Box<[i64; TOTAL_SIZE]>) -> i64 { + pub fn bottom(cube: &Cube, direction: &Direction, moment: &[i64; TOTAL_SIZE]) -> i64 { match direction { Direction::Red => { -moment[Self::get_index::(cube.r(0), cube.g(1), cube.b(1))] @@ -448,7 +448,12 @@ impl QuantizerWu { } } - pub fn top(cube: &Cube, direction: &Direction, position: i32, moment: &Box<[i64; TOTAL_SIZE]>) -> i64 { + pub fn top( + cube: &Cube, + direction: &Direction, + position: i32, + moment: &[i64; TOTAL_SIZE], + ) -> i64 { match direction { Direction::Red => { moment[Self::get_index(position as usize, cube.g(1), cube.b(1))]