cityjson_types/backend/default/
metadata.rs1use crate::prelude::StringStorage;
2use std::fmt::{Display, Formatter};
3
4#[repr(C)]
15#[derive(Clone, Copy, Debug, PartialEq)]
16pub struct BBox {
17 values: [f64; 6],
18}
19
20impl BBox {
21 #[must_use]
22 pub fn new(min_x: f64, min_y: f64, min_z: f64, max_x: f64, max_y: f64, max_z: f64) -> Self {
23 Self {
24 values: [min_x, min_y, min_z, max_x, max_y, max_z],
25 }
26 }
27
28 #[must_use]
29 pub fn as_slice(&self) -> &[f64] {
30 &self.values
31 }
32
33 #[must_use]
34 pub fn min_x(&self) -> f64 {
35 self.values[0]
36 }
37
38 #[must_use]
39 pub fn min_y(&self) -> f64 {
40 self.values[1]
41 }
42
43 #[must_use]
44 pub fn min_z(&self) -> f64 {
45 self.values[2]
46 }
47
48 #[must_use]
49 pub fn max_x(&self) -> f64 {
50 self.values[3]
51 }
52
53 #[must_use]
54 pub fn max_y(&self) -> f64 {
55 self.values[4]
56 }
57
58 #[must_use]
59 pub fn max_z(&self) -> f64 {
60 self.values[5]
61 }
62
63 #[must_use]
65 pub fn width(&self) -> f64 {
66 self.max_x() - self.min_x()
67 }
68
69 #[must_use]
71 pub fn length(&self) -> f64 {
72 self.max_y() - self.min_y()
73 }
74
75 #[must_use]
77 pub fn height(&self) -> f64 {
78 self.max_z() - self.min_z()
79 }
80}
81
82impl Default for BBox {
83 fn default() -> Self {
84 Self {
85 values: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
86 }
87 }
88}
89
90impl From<[f64; 6]> for BBox {
91 fn from(values: [f64; 6]) -> Self {
92 Self { values }
93 }
94}
95
96impl From<BBox> for [f64; 6] {
97 fn from(bbox: BBox) -> Self {
98 bbox.values
99 }
100}
101
102impl Display for BBox {
103 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
104 write!(
105 f,
106 "[{}, {}, {}, {}, {}, {}]",
107 self.min_x(),
108 self.min_y(),
109 self.min_z(),
110 self.max_x(),
111 self.max_y(),
112 self.max_z()
113 )
114 }
115}
116
117#[repr(C)]
126#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)]
127pub struct CityModelIdentifier<SS: StringStorage>(SS::String);
128
129impl<SS: StringStorage> CityModelIdentifier<SS> {
130 pub fn new(value: SS::String) -> Self {
131 Self(value)
132 }
133
134 pub fn into_inner(self) -> SS::String {
135 self.0
136 }
137}
138
139impl<SS: StringStorage> Display for CityModelIdentifier<SS> {
140 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
141 write!(f, "{}", self.0)
142 }
143}
144
145#[repr(C)]
157#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)]
158pub struct Date<SS: StringStorage>(SS::String);
159
160impl<SS: StringStorage> Date<SS> {
161 pub fn new(value: SS::String) -> Self {
162 Self(value)
163 }
164
165 pub fn into_inner(self) -> SS::String {
166 self.0
167 }
168}
169
170impl<SS: StringStorage> Display for Date<SS> {
171 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
172 write!(f, "{}", self.0)
173 }
174}
175
176#[repr(C)]
188#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)]
189pub struct CRS<SS: StringStorage>(SS::String);
190
191impl<SS: StringStorage> CRS<SS> {
192 pub fn new(value: SS::String) -> Self {
193 Self(value)
194 }
195
196 pub fn into_inner(self) -> SS::String {
197 self.0
198 }
199}
200
201impl<SS: StringStorage> Display for CRS<SS> {
202 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
203 write!(f, "{}", self.0)
204 }
205}