use ffi_helpers::null_pointer_check;
use nalgebra::{Matrix3, Quaternion, Rotation3, UnitQuaternion};
fn to_raw_pointer(rot: &Rotation3<f64>) -> *mut Rotation3<f64> {
Box::into_raw(Box::new(*rot))
}
#[no_mangle]
pub unsafe extern "C" fn viam_free_rotation_matrix_memory(ptr: *mut Rotation3<f64>) {
if ptr.is_null() {
return;
}
let _ = Box::from_raw(ptr);
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn free_rotation_matrix_memory(ptr: *mut Rotation3<f64>) {
viam_free_rotation_matrix_memory(ptr)
}
#[no_mangle]
pub unsafe extern "C" fn viam_new_rotation_matrix(
elements: *const [f64; 9],
) -> *mut Rotation3<f64> {
null_pointer_check!(elements);
let matrix = Matrix3::from_vec(Vec::from(*elements));
let rot = Rotation3::from_matrix_unchecked(matrix);
to_raw_pointer(&rot)
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn new_rotation_matrix(elements: *const [f64; 9]) -> *mut Rotation3<f64> {
viam_new_rotation_matrix(elements)
}
#[no_mangle]
pub unsafe extern "C" fn viam_rotation_matrix_from_quaternion(
quat: *const Quaternion<f64>,
) -> *mut Rotation3<f64> {
null_pointer_check!(quat);
let unit_quat = UnitQuaternion::new_normalize(*quat);
let rot = unit_quat.to_rotation_matrix();
to_raw_pointer(&rot)
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn rotation_matrix_from_quaternion(
quat: *const Quaternion<f64>,
) -> *mut Rotation3<f64> {
viam_rotation_matrix_from_quaternion(quat)
}