1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
pub mod bub;
pub mod oao;
pub mod wav;
use std::convert::TryInto;
#[derive(Clone, Debug, Default, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub struct BubbleField(Vec<Vec<Vec<u8>>>);
impl From<Vec<Vec<Vec<u8>>>> for BubbleField {
fn from(bub_field: Vec<Vec<Vec<u8>>>) -> Self {
BubbleField(bub_field)
}
}
impl Into<Vec<Vec<Vec<u8>>>> for BubbleField {
fn into(self) -> Vec<Vec<Vec<u8>>> {
self.0
}
}
#[derive(Clone, Copy, Debug, Default, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub struct BubbleFieldSize {
pub length: u8,
pub width: u8,
pub height: u8,
}
impl From<(u8, u8, u8)> for BubbleFieldSize {
fn from((length, width, height): (u8, u8, u8)) -> Self {
Self {
length,
width,
height
}
}
}
impl Into<(u8, u8, u8)> for BubbleFieldSize {
fn into(self) -> (u8, u8, u8) {
(self.length, self.width, self.height)
}
}
impl From<(usize, usize, usize)> for BubbleFieldSize {
fn from((length, width, height): (usize, usize, usize)) -> Self {
Self {
length: (length as f32).log2() as u8,
width: (width as f32).log2() as u8,
height: (height as f32).log2() as u8
}
}
}
impl TryInto<(usize, usize, usize)> for BubbleFieldSize {
type Error = &'static str;
fn try_into(self) -> Result<(usize, usize, usize), Self::Error> {
let (length, a) = 2usize.overflowing_pow(self.length as u32);
let (width, b) = 2usize.overflowing_pow(self.width as u32);
let (height, c) = 2usize.overflowing_pow(self.height as u32);
if a || b || c {
Err("One of the following: length, width and height is overflowing.")
} else {
Ok((length, width, height))
}
}
}
#[derive(Clone, Copy, Debug, Default, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub struct Color{
pub red: u8,
pub green: u8,
pub blue: u8
}
impl From<(u8, u8, u8)> for Color {
fn from((red, blue, green): (u8, u8, u8)) -> Self {
Self {
red,
blue,
green
}
}
}
impl Into<(u8, u8, u8)> for Color {
fn into(self) -> (u8, u8, u8) {
(self.red, self.green, self.blue)
}
}
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub enum Sample {
Float32(f32),
Float64(f64)
}
impl From<f32> for Sample {
fn from(sample: f32) -> Self {
Sample::Float32(sample)
}
}
impl Into<f32> for Sample {
fn into(self) -> f32 {
match self {
Self::Float32(n) => n,
Self::Float64(n) => n as f32
}
}
}
impl From<f64> for Sample {
fn from(sample: f64) -> Self {
Sample::Float64(sample)
}
}
impl Into<f64> for Sample {
fn into(self) -> f64 {
match self {
Self::Float32(n) => n as f64,
Self::Float64(n) => n
}
}
}