audionimbus 0.13.0

A safe wrapper around Steam Audio that provides spatial audio capabilities with realistic occlusion, reverb, and HRTF effects, accounting for physical attributes and scene geometry.
Documentation
/// A point or vector in 3D space.
///
/// Steam Audio uses a right-handed coordinate system, with the positive x-axis pointing right, the positive y-axis pointing up, and the negative z-axis pointing ahead.
/// Position and direction data obtained from a game engine or audio engine must be properly transformed before being passed to any Steam Audio API function.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Vector3 {
    /// The x-coordinate.
    pub x: f32,

    /// The y-coordinate.
    pub y: f32,

    /// The z-coordinate.
    pub z: f32,
}

impl Vector3 {
    /// Creates a new 3D vector given `x`, `y` and `z` components.
    pub const fn new(x: f32, y: f32, z: f32) -> Self {
        Self { x, y, z }
    }
}

impl Default for Vector3 {
    fn default() -> Self {
        Self {
            x: 0.0,
            y: 0.0,
            z: 0.0,
        }
    }
}

impl From<[f32; 3]> for Vector3 {
    fn from(vector: [f32; 3]) -> Self {
        Self {
            x: vector[0],
            y: vector[1],
            z: vector[2],
        }
    }
}

impl From<Vector3> for audionimbus_sys::IPLVector3 {
    fn from(vector: Vector3) -> Self {
        Self {
            x: vector.x,
            y: vector.y,
            z: vector.z,
        }
    }
}

impl From<audionimbus_sys::IPLVector3> for Vector3 {
    fn from(vector: audionimbus_sys::IPLVector3) -> Self {
        Self {
            x: vector.x,
            y: vector.y,
            z: vector.z,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_vector3_new() {
        let v = Vector3::new(1.0, 2.0, 3.0);
        assert_eq!(
            v,
            Vector3 {
                x: 1.0,
                y: 2.0,
                z: 3.0,
            }
        );
    }

    #[test]
    fn test_vector3_from_array() {
        let v = Vector3::from([4.0, 5.0, 6.0]);
        assert_eq!(
            v,
            Vector3 {
                x: 4.0,
                y: 5.0,
                z: 6.0,
            }
        );
    }

    #[test]
    fn test_vector3_equality() {
        let v1 = Vector3::new(1.0, 2.0, 3.0);
        let v2 = Vector3::new(1.0, 2.0, 3.0);
        let v3 = Vector3::new(1.0, 2.0, 4.0);

        assert_eq!(v1, v2);
        assert_ne!(v1, v3);
    }
}