use ffi_helpers::null_pointer_check;
use libc::c_double;
use nalgebra::Quaternion;
use crate::spatialmath::utils::OrientationVector;
fn to_raw_pointer(o_vec: &OrientationVector) -> *mut OrientationVector {
Box::into_raw(Box::new(*o_vec))
}
#[no_mangle]
pub unsafe extern "C" fn viam_free_orientation_vector_memory(ptr: *mut OrientationVector) {
if ptr.is_null() {
return;
}
let _ = Box::from_raw(ptr);
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn free_orientation_vector_memory(ptr: *mut OrientationVector) {
viam_free_orientation_vector_memory(ptr)
}
#[no_mangle]
pub unsafe extern "C" fn viam_new_orientation_vector(
o_x: f64,
o_y: f64,
o_z: f64,
theta: f64,
) -> *mut OrientationVector {
let o_vec = OrientationVector::new(o_x, o_y, o_z, theta);
to_raw_pointer(&o_vec)
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn new_orientation_vector(
o_x: f64,
o_y: f64,
o_z: f64,
theta: f64,
) -> *mut OrientationVector {
viam_new_orientation_vector(o_x, o_y, o_z, theta)
}
#[no_mangle]
pub unsafe extern "C" fn viam_orientation_vector_get_components(
ov_ptr: *const OrientationVector,
) -> *const c_double {
null_pointer_check!(ov_ptr);
let components: [c_double; 4] = [
(&(*ov_ptr)).o_vector.x,
(&(*ov_ptr)).o_vector.y,
(&(*ov_ptr)).o_vector.z,
(&(*ov_ptr)).theta,
];
Box::into_raw(Box::new(components)) as *const _
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn orientation_vector_get_components(
ov_ptr: *const OrientationVector,
) -> *const c_double {
viam_orientation_vector_get_components(ov_ptr)
}
#[no_mangle]
pub unsafe extern "C" fn viam_orientation_vector_from_quaternion(
quat_ptr: *const Quaternion<f64>,
) -> *mut OrientationVector {
null_pointer_check!(quat_ptr);
let o_vec: OrientationVector = (*quat_ptr).into();
to_raw_pointer(&o_vec)
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn orientation_vector_from_quaternion(
quat_ptr: *const Quaternion<f64>,
) -> *mut OrientationVector {
viam_orientation_vector_from_quaternion(quat_ptr)
}
#[no_mangle]
pub unsafe extern "C" fn viam_free_orientation_vector_components(ptr: *mut c_double) {
if ptr.is_null() {
return;
}
let ptr = ptr as *mut [c_double; 4];
let _: Box<[c_double; 4]> = Box::from_raw(ptr);
}
#[no_mangle]
#[deprecated]
pub unsafe extern "C" fn free_orientation_vector_components(ptr: *mut c_double) {
viam_free_orientation_vector_components(ptr)
}