bms_rs/chart_process/
types.rs1use crate::bms::Decimal;
4use crate::chart_process::ChartEvent;
5use fraction::{BigUint, GenericDecimal};
6use std::str::FromStr;
7
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
12pub struct YCoordinate(pub Decimal);
13
14impl YCoordinate {
15 #[must_use]
17 pub const fn new(value: Decimal) -> Self {
18 Self(value)
19 }
20
21 #[must_use]
23 pub const fn value(&self) -> &Decimal {
24 &self.0
25 }
26
27 #[must_use]
29 pub fn as_f64(&self) -> f64 {
30 self.0.to_string().parse::<f64>().unwrap_or(0.0)
31 }
32}
33
34impl From<Decimal> for YCoordinate {
35 fn from(value: Decimal) -> Self {
36 Self(value)
37 }
38}
39
40impl From<f64> for YCoordinate {
41 fn from(value: f64) -> Self {
42 let decimal_str = value.to_string();
44 let decimal = GenericDecimal::from_str(&decimal_str).unwrap_or_else(|_| {
45 GenericDecimal::from(BigUint::from(0u32))
47 });
48 Self(decimal)
49 }
50}
51
52impl std::ops::Add for YCoordinate {
53 type Output = Self;
54
55 fn add(self, rhs: Self) -> Self::Output {
56 Self(self.0 + rhs.0)
57 }
58}
59
60impl std::ops::Sub for YCoordinate {
61 type Output = Self;
62
63 fn sub(self, rhs: Self) -> Self::Output {
64 Self(self.0 - rhs.0)
65 }
66}
67
68impl std::ops::Mul for YCoordinate {
69 type Output = Self;
70
71 fn mul(self, rhs: Self) -> Self::Output {
72 Self(self.0 * rhs.0)
73 }
74}
75
76impl std::ops::Div for YCoordinate {
77 type Output = Self;
78
79 fn div(self, rhs: Self) -> Self::Output {
80 Self(self.0 / rhs.0)
81 }
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
89pub struct DisplayRatio(pub Decimal);
90
91impl DisplayRatio {
92 #[must_use]
94 pub const fn new(value: Decimal) -> Self {
95 Self(value)
96 }
97
98 #[must_use]
100 pub const fn value(&self) -> &Decimal {
101 &self.0
102 }
103
104 #[must_use]
106 pub fn as_f64(&self) -> f64 {
107 self.0.to_string().parse::<f64>().unwrap_or(0.0)
108 }
109
110 #[must_use]
112 pub fn at_judgment_line() -> Self {
113 Self(Decimal::from(0))
114 }
115
116 #[must_use]
118 pub fn at_appearance() -> Self {
119 Self(Decimal::from(1))
120 }
121}
122
123impl From<Decimal> for DisplayRatio {
124 fn from(value: Decimal) -> Self {
125 Self(value)
126 }
127}
128
129impl From<f64> for DisplayRatio {
130 fn from(value: f64) -> Self {
131 let decimal_str = value.to_string();
133 let decimal = GenericDecimal::from_str(&decimal_str).unwrap_or_else(|_| {
134 GenericDecimal::from(BigUint::from(0u32))
136 });
137 Self(decimal)
138 }
139}
140
141#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
143pub struct WavId(pub usize);
144
145impl WavId {
146 #[must_use]
148 pub const fn new(id: usize) -> Self {
149 Self(id)
150 }
151
152 #[must_use]
154 pub const fn value(self) -> usize {
155 self.0
156 }
157}
158
159impl From<usize> for WavId {
160 fn from(value: usize) -> Self {
161 Self(value)
162 }
163}
164
165impl From<WavId> for usize {
166 fn from(id: WavId) -> Self {
167 id.0
168 }
169}
170
171#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
173pub struct BmpId(pub usize);
174
175impl BmpId {
176 #[must_use]
178 pub const fn new(id: usize) -> Self {
179 Self(id)
180 }
181
182 #[must_use]
184 pub const fn value(self) -> usize {
185 self.0
186 }
187}
188
189impl From<usize> for BmpId {
190 fn from(value: usize) -> Self {
191 Self(value)
192 }
193}
194
195impl From<BmpId> for usize {
196 fn from(id: BmpId) -> Self {
197 id.0
198 }
199}
200
201#[derive(Debug, Clone)]
205pub struct ChartEventWithPosition {
206 pub position: YCoordinate,
208 pub event: ChartEvent,
210}
211
212impl ChartEventWithPosition {
213 #[must_use]
215 pub const fn new(position: YCoordinate, event: ChartEvent) -> Self {
216 Self { position, event }
217 }
218
219 #[must_use]
221 pub const fn position(&self) -> &YCoordinate {
222 &self.position
223 }
224
225 #[must_use]
227 pub const fn event(&self) -> &ChartEvent {
228 &self.event
229 }
230
231 #[must_use]
233 pub fn into_tuple(self) -> (YCoordinate, ChartEvent) {
234 (self.position, self.event)
235 }
236}
237
238impl From<(YCoordinate, ChartEvent)> for ChartEventWithPosition {
239 fn from((position, event): (YCoordinate, ChartEvent)) -> Self {
240 Self::new(position, event)
241 }
242}
243
244impl From<ChartEventWithPosition> for (YCoordinate, ChartEvent) {
245 fn from(wrapper: ChartEventWithPosition) -> Self {
246 wrapper.into_tuple()
247 }
248}
249
250#[derive(Debug, Clone)]
254pub struct VisibleEvent {
255 pub position: YCoordinate,
257 pub event: ChartEvent,
259 pub display_ratio: DisplayRatio,
261}
262
263impl VisibleEvent {
264 #[must_use]
266 pub const fn new(
267 position: YCoordinate,
268 event: ChartEvent,
269 display_ratio: DisplayRatio,
270 ) -> Self {
271 Self {
272 position,
273 event,
274 display_ratio,
275 }
276 }
277
278 #[must_use]
280 pub const fn position(&self) -> &YCoordinate {
281 &self.position
282 }
283
284 #[must_use]
286 pub const fn event(&self) -> &ChartEvent {
287 &self.event
288 }
289
290 #[must_use]
292 pub const fn display_ratio(&self) -> &DisplayRatio {
293 &self.display_ratio
294 }
295
296 #[must_use]
298 pub fn into_tuple(self) -> (YCoordinate, ChartEvent, DisplayRatio) {
299 (self.position, self.event, self.display_ratio)
300 }
301}
302
303impl From<(YCoordinate, ChartEvent, DisplayRatio)> for VisibleEvent {
304 fn from((position, event, display_ratio): (YCoordinate, ChartEvent, DisplayRatio)) -> Self {
305 Self::new(position, event, display_ratio)
306 }
307}
308
309impl From<VisibleEvent> for (YCoordinate, ChartEvent, DisplayRatio) {
310 fn from(wrapper: VisibleEvent) -> Self {
311 wrapper.into_tuple()
312 }
313}