1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::prelude::RGBA;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Copy, Clone, Default, Debug)]
pub struct ColorPair {
pub fg: RGBA,
pub bg: RGBA,
}
impl ColorPair {
#[inline]
#[must_use]
pub fn new<COLOR, COLOR2>(fg: COLOR, bg: COLOR2) -> Self
where
COLOR: Into<RGBA>,
COLOR2: Into<RGBA>,
{
Self {
fg: fg.into(),
bg: bg.into(),
}
}
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn make_rgb_pair() {
let cp = ColorPair::new(RGB::named(BLACK), RGB::named(BLACK));
assert!(cp.fg.r < std::f32::EPSILON);
assert!(cp.fg.g < std::f32::EPSILON);
assert!(cp.fg.b < std::f32::EPSILON);
assert!((cp.fg.a - 1.0).abs() < std::f32::EPSILON);
assert!(cp.bg.r < std::f32::EPSILON);
assert!(cp.bg.g < std::f32::EPSILON);
assert!(cp.bg.b < std::f32::EPSILON);
assert!((cp.bg.a - 1.0).abs() < std::f32::EPSILON);
}
#[test]
fn make_rgba_pair() {
let cp = ColorPair::new(RGBA::new(), RGBA::new());
assert!(cp.fg.r < std::f32::EPSILON);
assert!(cp.fg.g < std::f32::EPSILON);
assert!(cp.fg.b < std::f32::EPSILON);
assert!(cp.fg.a < std::f32::EPSILON);
assert!(cp.bg.r < std::f32::EPSILON);
assert!(cp.bg.g < std::f32::EPSILON);
assert!(cp.bg.b < std::f32::EPSILON);
assert!(cp.bg.a < std::f32::EPSILON);
}
}