1use serde::{Deserialize, Serialize};
2use std::hash::{Hash, Hasher};
3
4#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
6pub struct Color([f32; 3]);
7
8impl Color {
9 pub fn new(r: f32, g: f32, b: f32) -> Self {
11 Self([r, g, b])
12 }
13}
14
15impl From<Color> for [f32; 3] {
17 fn from(color: Color) -> Self {
18 color.0
19 }
20}
21
22impl Hash for Color {
23 fn hash<H: Hasher>(&self, state: &mut H) {
24 (self.0[0] as u32).hash(state);
25 (self.0[1] as u32).hash(state);
26 (self.0[2] as u32).hash(state);
27 }
28}
29
30impl PartialEq for Color {
31 fn eq(&self, other: &Self) -> bool {
32 (self.0[0] == other.0[0]) && (self.0[1] == other.0[1]) && (self.0[2] == other.0[2])
33 }
34}