1#[derive(Debug, Clone)]
3pub struct Vec3 {
4 pub x: f32,
6 pub y: f32,
8 pub z: f32,
10}
11
12impl Vec3 {
13 pub fn from_array(array: &[f32; 3]) -> Self {
15 Self {
16 x: array[0],
17 y: array[1],
18 z: array[2],
19 }
20 }
21}
22
23#[derive(Debug, Clone)]
25pub struct DVec3 {
26 pub x: f64,
28 pub y: f64,
30 pub z: f64,
32}
33
34impl DVec3 {
35 pub fn from_array(array: &[f64; 3]) -> Self {
37 Self {
38 x: array[0],
39 y: array[1],
40 z: array[2],
41 }
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_vec3_from_array() {
51 let array = [1.0, 2.0, 3.0];
52 let vec = Vec3::from_array(&array);
53 assert_eq!(vec.x, 1.0);
54 assert_eq!(vec.y, 2.0);
55 assert_eq!(vec.z, 3.0);
56 }
57
58 #[test]
59 fn test_dvec3_from_array() {
60 let array = [1.0, 2.0, 3.0];
61 let vec = DVec3::from_array(&array);
62 assert_eq!(vec.x, 1.0);
63 assert_eq!(vec.y, 2.0);
64 assert_eq!(vec.z, 3.0);
65 }
66}