use rerun_0_28 as rerun;
use super::{Bivector, Rotor, Vector};
use crate::specialized::visualization::AsPosition;
impl From<Vector<f32>> for rerun::Vec3D {
#[inline]
fn from(v: Vector<f32>) -> Self {
rerun::Vec3D::new(v.x(), v.y(), v.z())
}
}
impl From<AsPosition<Vector<f32>>> for rerun::Position3D {
#[inline]
fn from(v: AsPosition<Vector<f32>>) -> Self {
rerun::Position3D::new(v.0.x(), v.0.y(), v.0.z())
}
}
impl From<Bivector<f32>> for rerun::Vec3D {
#[inline]
fn from(b: Bivector<f32>) -> Self {
rerun::Vec3D::new(b.rx(), -b.ry(), b.rz())
}
}
impl From<Rotor<f32>> for rerun::components::RotationQuat {
#[inline]
fn from(rotor: Rotor<f32>) -> Self {
let r = rotor.normalize();
let quat = rerun::Quaternion::from_xyzw([r.rx(), -r.ry(), r.rz(), r.s()]);
rerun::components::RotationQuat(quat)
}
}
impl From<Rotor<f32>> for rerun::Transform3D {
#[inline]
fn from(rotor: Rotor<f32>) -> Self {
let quat: rerun::components::RotationQuat = rotor.into();
rerun::Transform3D::from_rotation(quat)
}
}
#[cfg(test)]
mod tests {
use super::*;
use approx::abs_diff_eq;
use proptest::prelude::*;
const EPS: f32 = 1e-5;
proptest! {
#[test]
fn vector_to_vec3d_preserves_components(v in any::<Vector<f32>>()) {
let rerun_v: rerun::Vec3D = v.into();
prop_assert!(abs_diff_eq!(rerun_v.x(), v.x(), epsilon = EPS));
prop_assert!(abs_diff_eq!(rerun_v.y(), v.y(), epsilon = EPS));
prop_assert!(abs_diff_eq!(rerun_v.z(), v.z(), epsilon = EPS));
}
#[test]
fn as_position_to_position3d_preserves_components(v in any::<Vector<f32>>()) {
let pos: rerun::Position3D = AsPosition(v).into();
prop_assert!(abs_diff_eq!(pos.x(), v.x(), epsilon = EPS));
prop_assert!(abs_diff_eq!(pos.y(), v.y(), epsilon = EPS));
prop_assert!(abs_diff_eq!(pos.z(), v.z(), epsilon = EPS));
}
#[test]
fn bivector_to_vec3d_matches_dual(b in any::<Bivector<f32>>()) {
let rerun_v: rerun::Vec3D = b.into();
let dual = b.dual();
prop_assert!(abs_diff_eq!(rerun_v.x(), dual.x(), epsilon = EPS));
prop_assert!(abs_diff_eq!(rerun_v.y(), dual.y(), epsilon = EPS));
prop_assert!(abs_diff_eq!(rerun_v.z(), dual.z(), epsilon = EPS));
}
#[test]
fn rotor_to_quaternion_does_not_panic(r in any::<Rotor<f32>>()) {
let _quat: rerun::components::RotationQuat = r.into();
}
#[test]
fn rotor_to_transform3d_does_not_panic(r in any::<Rotor<f32>>()) {
let _t: rerun::Transform3D = r.into();
}
}
#[test]
fn rotor_z_rotation_converts() {
let rotor = Rotor::from_angle_plane(std::f32::consts::FRAC_PI_2, Bivector::unit_rz());
let _quat: rerun::components::RotationQuat = rotor.into();
}
}