cityjson_types/backend/default/
appearance.rs1use std::{fmt, write};
2
3#[allow(clippy::upper_case_acronyms)]
4#[repr(transparent)]
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct RGB([f32; 3]);
7
8impl RGB {
9 #[must_use]
10 pub fn new(red: f32, green: f32, blue: f32) -> Self {
11 Self([red, green, blue])
12 }
13
14 #[must_use]
15 pub fn to_array(self) -> [f32; 3] {
16 self.0
17 }
18}
19
20impl From<[f32; 3]> for RGB {
21 fn from(value: [f32; 3]) -> Self {
22 Self(value)
23 }
24}
25
26impl From<RGB> for [f32; 3] {
27 fn from(value: RGB) -> Self {
28 value.0
29 }
30}
31
32impl fmt::Display for RGB {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 write!(f, "[{}, {}, {}]", self.0[0], self.0[1], self.0[2])
35 }
36}
37
38#[allow(clippy::upper_case_acronyms)]
39#[repr(transparent)]
40#[derive(Clone, Copy, Debug, Default, PartialEq)]
41pub struct RGBA([f32; 4]);
42
43impl RGBA {
44 #[must_use]
45 pub fn new(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
46 Self([red, green, blue, alpha])
47 }
48
49 #[must_use]
50 pub fn to_array(self) -> [f32; 4] {
51 self.0
52 }
53}
54
55impl From<[f32; 4]> for RGBA {
56 fn from(value: [f32; 4]) -> Self {
57 Self(value)
58 }
59}
60
61impl From<RGBA> for [f32; 4] {
62 fn from(value: RGBA) -> Self {
63 value.0
64 }
65}
66
67impl fmt::Display for RGBA {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 write!(
70 f,
71 "[{}, {}, {}, {}]",
72 self.0[0], self.0[1], self.0[2], self.0[3]
73 )
74 }
75}
76
77#[repr(C)]
78#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
79#[non_exhaustive]
80pub enum ImageType {
81 #[default]
82 Png,
83 Jpg,
84}
85
86impl fmt::Display for ImageType {
87 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88 match self {
89 ImageType::Png => write!(f, "PNG"),
90 ImageType::Jpg => write!(f, "JPG"),
91 }
92 }
93}
94
95#[repr(C)]
96#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
97#[non_exhaustive]
98pub enum WrapMode {
99 Wrap,
100 Mirror,
101 Clamp,
102 Border,
103 #[default]
104 None,
105}
106
107impl fmt::Display for WrapMode {
108 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109 match self {
110 WrapMode::Wrap => write!(f, "wrap"),
111 WrapMode::Mirror => write!(f, "mirror"),
112 WrapMode::Clamp => write!(f, "clamp"),
113 WrapMode::Border => write!(f, "border"),
114 WrapMode::None => write!(f, "none"),
115 }
116 }
117}
118
119#[repr(C)]
120#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
121#[non_exhaustive]
122pub enum TextureType {
123 #[default]
124 Unknown,
125 Specific,
126 Typical,
127}
128
129impl fmt::Display for TextureType {
130 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
131 match self {
132 TextureType::Unknown => write!(f, "unknown"),
133 TextureType::Specific => write!(f, "specific"),
134 TextureType::Typical => write!(f, "typical"),
135 }
136 }
137}