#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Vector3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
impl Vector3 {
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);
}
}