#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Color(pub u8, pub u8, pub u8);
impl Color {
pub const RED: Self = Self(255, 0, 0);
pub const GREEN: Self = Self(0, 255, 0);
pub const BLUE: Self = Self(0, 0, 255);
pub const WHITE: Self = Self(255, 255, 255);
pub const BLACK: Self = Self(0, 0, 0);
#[must_use]
pub const fn new(r: u8, g: u8, b: u8) -> Self {
Self(r, g, b)
}
#[must_use]
pub const fn from_index(index: usize) -> Self {
let color = COLORS[index % COLORS.len()];
Self(color[0], color[1], color[2])
}
#[must_use]
pub const fn from_pose_index(index: usize) -> Self {
let color = POSE_COLORS[index % POSE_COLORS.len()];
Self(color[0], color[1], color[2])
}
}
pub const COLORS: [[u8; 3]; 20] = [
[4, 42, 255], [11, 219, 235], [243, 243, 243], [0, 223, 183], [17, 31, 104], [255, 111, 221], [255, 68, 79], [204, 237, 0], [0, 243, 68], [189, 0, 255], [0, 180, 255], [221, 0, 186], [0, 255, 255], [38, 192, 0], [1, 255, 179], [125, 36, 255], [123, 0, 104], [255, 27, 108], [252, 109, 47], [162, 255, 11], ];
pub const POSE_COLORS: [[u8; 3]; 20] = [
[255, 128, 0], [255, 153, 51], [255, 178, 102], [230, 230, 0], [255, 153, 255], [153, 204, 255], [255, 102, 255], [255, 51, 255], [102, 178, 255], [51, 153, 255], [255, 153, 153], [255, 102, 102], [255, 51, 51], [153, 255, 153], [102, 255, 102], [51, 255, 51], [0, 255, 0], [0, 0, 255], [255, 0, 0], [255, 255, 255], ];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_color_constants() {
assert_eq!(Color::RED, Color(255, 0, 0));
assert_eq!(Color::GREEN, Color(0, 255, 0));
assert_eq!(Color::BLUE, Color(0, 0, 255));
assert_eq!(Color::WHITE, Color(255, 255, 255));
assert_eq!(Color::BLACK, Color(0, 0, 0));
}
#[test]
fn test_color_new() {
let c = Color::new(10, 20, 30);
assert_eq!(c.0, 10);
assert_eq!(c.1, 20);
assert_eq!(c.2, 30);
}
#[test]
fn test_from_index() {
let c1 = Color::from_index(0);
assert_eq!(c1, Color(4, 42, 255));
let c2 = Color::from_index(COLORS.len());
assert_eq!(c2, Color(4, 42, 255));
}
#[test]
fn test_from_pose_index() {
let c1 = Color::from_pose_index(0);
assert_eq!(c1, Color(255, 128, 0));
let c2 = Color::from_pose_index(POSE_COLORS.len());
assert_eq!(c2, Color(255, 128, 0));
}
}