material_color_utilities/
dislike_analyzer.rs

1use crate::hct::Hct;
2
3pub fn is_disliked(hct: &Hct) -> bool {
4  let hue_passes = hct.hue().round() >= 90.0 && hct.hue().round() <= 111.0;
5  let chroma_passes = hct.chroma().round() > 16.0;
6  let tone_passes = hct.tone().round() < 65.0;
7  hue_passes && chroma_passes && tone_passes
8}
9
10pub fn fix_if_disliked(hct: Hct) -> Hct {
11  if is_disliked(&hct) {
12    Hct::from(hct.hue(), hct.chroma(), 70.0)
13  } else {
14    hct
15  }
16}
17
18#[cfg(test)]
19mod tests {
20  use super::*;
21
22  #[test]
23  fn likes_monk_skin_tone_scale_colors() {
24    let monk_skin_tone_scale_colors: [u32; 10] = [
25      0xfff6ede4, 0xfff3e7db, 0xfff7ead0, 0xffeadaba, 0xffd7bd96, 0xffa07e56, 0xff825c43,
26      0xff604134, 0xff3a312a, 0xff292420,
27    ];
28    for color in monk_skin_tone_scale_colors {
29      assert!(!is_disliked(&Hct::from_int(color)));
30    }
31  }
32
33  #[test]
34  fn dislikes_bile_colors() {
35    let unlikable: [u32; 5] = [0xff95884b, 0xff716b40, 0xffb08e00, 0xff4c4308, 0xff464521];
36    for color in unlikable {
37      assert!(is_disliked(&Hct::from_int(color)));
38    }
39  }
40
41  #[test]
42  fn makes_bile_colors_likable() {
43    let unlikable: [u32; 5] = [0xff95884b, 0xff716b40, 0xffb08e00, 0xff4c4308, 0xff464521];
44    for color in unlikable {
45      let hct = Hct::from_int(color);
46      assert!(is_disliked(&hct));
47      let likable = fix_if_disliked(hct);
48      assert!(!is_disliked(&likable));
49    }
50  }
51}