kornia_3d/
vector.rs

1/// Simple 3D vector with x, y, and z coordinates as single precision floats.
2#[derive(Debug, Clone)]
3pub struct Vec3 {
4    /// x coordinate
5    pub x: f32,
6    /// y coordinate
7    pub y: f32,
8    /// z coordinate
9    pub z: f32,
10}
11
12impl Vec3 {
13    /// Create a new Vec3 from an array of 3 f32 values.
14    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/// Simple 3D vector with x, y, and z coordinates as double precision floats.
24#[derive(Debug, Clone)]
25pub struct DVec3 {
26    /// x coordinate
27    pub x: f64,
28    /// y coordinate
29    pub y: f64,
30    /// z coordinate
31    pub z: f64,
32}
33
34impl DVec3 {
35    /// Create a new DVec3 from an array of 3 f64 values.
36    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}