diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45420a1..ba69324 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -96,6 +96,7 @@ jobs: run: | cp target/${{ matrix.target }}/release/libviam_rust_utils.dylib builds/libviam_rust_utils-${{ matrix.platform }}.dylib cp target/${{ matrix.target }}/release/libviam_rust_utils.a builds/libviam_rust_utils-${{ matrix.platform }}.a + cp viam_rust_utils.h builds/viam_rust_utils-${{ matrix.platform }}.h - name: Correct install path run: | install_name_tool -id "@rpath/libviam_rust_utils.dylib" builds/libviam_rust_utils-${{ matrix.platform }}.dylib @@ -195,6 +196,7 @@ jobs: run: | cp target/${{ matrix.target }}/release/libviam_rust_utils.so builds/libviam_rust_utils-${{ matrix.platform }}.so cp target/${{ matrix.target }}/release/libviam_rust_utils.a builds/libviam_rust_utils-${{ matrix.platform }}.a + cp viam_rust_utils.h builds/viam_rust_utils-${{ matrix.platform }}.h - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -228,15 +230,47 @@ jobs: run: | cp target/release/viam_rust_utils.dll builds/libviam_rust_utils-${{ matrix.platform }}.dll cp target/release/viam_rust_utils.lib builds/viam_rust_utils-${{ matrix.platform }}.lib + cp viam_rust_utils.h builds/viam_rust_utils-${{ matrix.platform }}.h - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: builds-${{ matrix.platform }} path: builds/* - merge: + create_canonical_header: needs: [build_macos, build_linux, build_windows] runs-on: ubuntu-latest + steps: + # pick one arbitrarily as the canonical header file + - name: create canonical header + run: mv builds/viam_rust_utils-macosx_arm64.h builds/viam_rust_utils.h + + compare_headers: + needs: [create_canonical_header] + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + include: + - platform: macosx_x86_64 + - platform: linux_aarch64 + - platform: linux_x86_64 + - platform: musllinux_x86_64 + - platform: musllinux_aarch64 + - platform: linux_armv6l + - platform: musllinux_armv6l + - platform: musllinux_armv7l + - platform: musllinux_x86 + - platform: windows_x86_64 + steps: + - name: compare files + run: cmp builds/viam_rust_utils.h builds/viam_rust_utils-${{ matrix.platform }}.h + - name: remove duplicate header + run: rm builds/viam_rust_utils-${{ matrix.platform }}.h + + merge: + needs: [build_macos, build_linux, build_windows, compare_headers] + runs-on: ubuntu-latest steps: - name: Merge artifacts uses: actions/upload-artifact/merge@v4 diff --git a/.gitignore b/.gitignore index 6d9c0d0..3ea66c0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ bin/ # goutils tests/goutils/ + +viam_rust_utils.h diff --git a/Cargo.lock b/Cargo.lock index 62bc9f5..5504162 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,6 +609,25 @@ dependencies = [ "cipher", ] +[[package]] +name = "cbindgen" +version = "0.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "befbfd072a8e81c02f8c507aefce431fe5e7d051f83d48a23ffc9b9fe5a11799" +dependencies = [ + "clap", + "heck 0.5.0", + "indexmap 2.12.0", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.106", + "tempfile", + "toml", +] + [[package]] name = "cc" version = "1.2.36" @@ -1341,7 +1360,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.11.0", + "indexmap 2.12.0", "slab", "tokio", "tokio-util", @@ -1362,9 +1381,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hashbrown" -version = "0.15.5" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "heck" @@ -1651,12 +1670,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" dependencies = [ "equivalent", - "hashbrown 0.15.5", + "hashbrown 0.16.0", ] [[package]] @@ -2247,7 +2266,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.11.0", + "indexmap 2.12.0", ] [[package]] @@ -2945,10 +2964,11 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ + "serde_core", "serde_derive", ] @@ -2962,11 +2982,20 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -2985,13 +3014,22 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392" +dependencies = [ + "serde_core", +] + [[package]] name = "serde_yaml" version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.11.0", + "indexmap 2.12.0", "itoa", "ryu", "serde", @@ -3428,6 +3466,45 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" +dependencies = [ + "indexmap 2.12.0", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2" + [[package]] name = "tonic" version = "0.9.2" @@ -3767,6 +3844,7 @@ dependencies = [ "base64 0.13.1", "byteorder", "bytes", + "cbindgen", "chrono", "clap", "dashmap", @@ -4560,6 +4638,12 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" +[[package]] +name = "winnow" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" + [[package]] name = "wit-bindgen" version = "0.45.1" diff --git a/Cargo.toml b/Cargo.toml index 5342d96..d1ff0c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,3 +67,4 @@ env_logger = "0.9.0" [build-dependencies] tonic-build = {version = "0.9.2",features = ["prost"]} +cbindgen = "0.29.2" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..18dc193 --- /dev/null +++ b/build.rs @@ -0,0 +1,88 @@ +extern crate cbindgen; + +use std::{collections::HashMap, env}; + +use cbindgen::{Config, ExportConfig, FunctionConfig, ParseConfig, RenameRule, StructConfig}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + // mangled nalgebra type outputs, mapped to a prefixed snake case variant + let nalgebra_types = vec![ + ("ArrayStorage_f64__3__1", "nalgebra_array_storage_f64__3__1"), + ( + "Matrix_f64__U3__U1__ArrayStorage_f64__3__1", + "nalgebra_matrix_f64_3_1", + ), + ("Vector3_f64", "nalgebra_vector3_f64"), + ("ArrayStorage_f64__4__1", "nalgebra_array_storage_f64__4__1"), + ( + "Matrix_f64__U4__U1__ArrayStorage_f64__4__1", + "nalgebra_matrix_f64_4_1", + ), + ("Vector4_f64", "nalgebra_vector4_f64"), + ("Quaternion_f64", "nalgebra_quaternion_f64"), + ( + "Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1", + "nalgebra_unit_matrix_f64_3_1", + ), + ("UnitVector3_f64", "nalgebra_unit_vector3_f64"), + ("Rotation_f64__3", "nalgebra_rotation_f64_3"), + ( + "Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3", + "nalgebra_matrix_f64_3_3", + ), + ("ArrayStorage_f64__3__3", "nalgebra_array_storage_f64__3__3"), + ("SMatrix_f64__3__3", "nalgebra_smatrix_f64_3_3"), + ("Rotation_f64__3", "nalgebra_rotation_f64_3"), + ("Rotation3_f64", "nalgebra_rotation3_f64"), + ]; + + // mangled viam type outputs, mapped to a prefixed snake case variant + let viam_types = vec![ + ("DialFfi", "viam_dial_ffi"), + ("AxisAngle", "viam_axis_angle"), + ("EulerAngles", "viam_euler_angles"), + ("OrientationVector", "viam_orientation_vector"), + ]; + + let rename = vec![nalgebra_types, viam_types] + .into_iter() + .flatten() + .map(|(a, b)| (a.to_string(), b.to_string())) + .collect::>(); + + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_config(Config { + parse: ParseConfig { + parse_deps: true, + include: Some(vec!["nalgebra".to_string()]), + ..Default::default() + }, + export: ExportConfig { + rename, + ..Default::default() + }, + structure: StructConfig { + rename_associated_constant: RenameRule::SnakeCase, + rename_fields: RenameRule::SnakeCase, + ..Default::default() + }, + function: FunctionConfig { + deprecated: Some( + "/// @deprecated please use `viam_`-prefixed function instead".to_string(), + ), + ..Default::default() + }, + ..Default::default() + }) + .with_cpp_compat(true) + .with_language(cbindgen::Language::C) + .with_autogen_warning( + "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */", + ) + .generate() + .expect("Unable to generate bindings") + .write_to_file("viam_rust_utils.h"); // Output to target directory +} diff --git a/doc/dependency_decisions.yml b/doc/dependency_decisions.yml index f3498f0..09580fe 100644 --- a/doc/dependency_decisions.yml +++ b/doc/dependency_decisions.yml @@ -65,3 +65,9 @@ :why: :versions: [] :when: 2025-04-14 14:25:17.811988000 Z +- - :permit + - BSD-zero-clause + - :who: + :why: + :versions: [] + :when: 2025-11-04 16:20:20.790232000 Z diff --git a/src/ffi/dial_ffi.rs b/src/ffi/dial_ffi.rs index 22dd1b2..762b8e5 100644 --- a/src/ffi/dial_ffi.rs +++ b/src/ffi/dial_ffi.rs @@ -66,11 +66,17 @@ impl DialFfi { /// Initialize a tokio runtime to run a gRPC client/sever, user should call this function before trying to dial to a Robot /// Returns a pointer to a [`DialFfi`] #[no_mangle] -pub extern "C" fn init_rust_runtime() -> Box { +pub extern "C" fn viam_init_rust_runtime() -> Box { let _ = tracing_subscriber::fmt::try_init(); Box::new(DialFfi::new()) } +#[no_mangle] +#[deprecated] +pub extern "C" fn init_rust_runtime() -> Box { + viam_init_rust_runtime() +} + fn dial_without_cred( uri: String, allow_insec: bool, @@ -119,7 +125,7 @@ fn dial_with_cred( /// * `c_timeout` a float, set how many seconds we should try to dial before timing out /// * `rt_ptr` a pointer to a rust runtime previously obtained with init_rust_runtime #[no_mangle] -pub unsafe extern "C" fn dial( +pub unsafe extern "C" fn viam_dial( c_uri: *const c_char, c_entity: *const c_char, c_type: *const c_char, @@ -273,6 +279,28 @@ pub unsafe extern "C" fn dial( path.into_raw() } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn dial( + c_uri: *const c_char, + c_entity: *const c_char, + c_type: *const c_char, + c_payload: *const c_char, + c_allow_insec: bool, + c_timeout: f32, + rt_ptr: Option<&mut DialFfi>, +) -> *mut c_char { + viam_dial( + c_uri, + c_entity, + c_type, + c_payload, + c_allow_insec, + c_timeout, + rt_ptr, + ) +} + /// This function must be used to free the path returned by the [`dial`] function /// # Safety /// @@ -280,7 +308,7 @@ pub unsafe extern "C" fn dial( /// # Arguments /// * `c_char` a pointer to the string returned by [`dial`] #[no_mangle] -pub unsafe extern "C" fn free_string(s: *mut c_char) { +pub unsafe extern "C" fn viam_free_string(s: *mut c_char) { if s.is_null() { return; } @@ -288,6 +316,12 @@ pub unsafe extern "C" fn free_string(s: *mut c_char) { let _ = CString::from_raw(s); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn free_string(s: *mut c_char) { + viam_free_string(s) +} + /// This function must be used the free a rust runtime returned by [`init_rust_runtime`] the function will signal any /// opened server to shutdown. Further transaction on any proxy will not work anymore. /// # Safety @@ -296,7 +330,7 @@ pub unsafe extern "C" fn free_string(s: *mut c_char) { /// # Arguments /// * `rt_prt` a pointer to the string returned by [`init_rust_runtime`] #[no_mangle] -pub extern "C" fn free_rust_runtime(rt_ptr: Option>) -> i32 { +pub extern "C" fn viam_free_rust_runtime(rt_ptr: Option>) -> i32 { let mut ctx = match rt_ptr { Some(ctx) => ctx, None => { @@ -323,3 +357,9 @@ pub extern "C" fn free_rust_runtime(rt_ptr: Option>) -> i32 { log::debug!("Freeing rust runtime"); 0 } + +#[no_mangle] +#[deprecated] +pub extern "C" fn free_rust_runtime(rt_ptr: Option>) -> i32 { + viam_free_rust_runtime(rt_ptr) +} diff --git a/src/ffi/spatialmath/axis_angle.rs b/src/ffi/spatialmath/axis_angle.rs index 66b6d5a..91646d1 100644 --- a/src/ffi/spatialmath/axis_angle.rs +++ b/src/ffi/spatialmath/axis_angle.rs @@ -21,13 +21,18 @@ fn to_raw_pointer(aa: &AxisAngle) -> *mut AxisAngle { /// Outer processes that work with axis angles via the FFI interface MUST remember /// to call this function when finished with an axis angle instance #[no_mangle] -pub unsafe extern "C" fn free_axis_angles_memory(ptr: *mut AxisAngle) { +pub unsafe extern "C" fn viam_free_axis_angles_memory(ptr: *mut AxisAngle) { if ptr.is_null() { return; } let _ = Box::from_raw(ptr); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn free_axis_angles_memory(ptr: *mut AxisAngle) { + viam_free_axis_angles_memory(ptr) +} /// Initialize axis angle from raw components and retrieve the C pointer /// to its address. /// @@ -37,10 +42,16 @@ pub unsafe extern "C" fn free_axis_angles_memory(ptr: *mut AxisAngle) { /// the caller must remember to free the axis angle memory using the /// free_axis_angles_memory FFI function #[no_mangle] -pub extern "C" fn new_axis_angle(x: f64, y: f64, z: f64, theta: f64) -> *mut AxisAngle { +pub extern "C" fn viam_new_axis_angle(x: f64, y: f64, z: f64, theta: f64) -> *mut AxisAngle { to_raw_pointer(&AxisAngle::new(x, y, z, theta)) } +#[no_mangle] +#[deprecated] +pub extern "C" fn new_axis_angle(x: f64, y: f64, z: f64, theta: f64) -> *mut AxisAngle { + viam_new_axis_angle(x, y, z, theta) +} + /// Converts a quaternion into an R4 axis angle. The return value is a pointer /// to a list of [x, y, x, theta], where (x,y,z) are the axis vector components /// and theta is the rotation about the axis in radians. A zero quaternion returns @@ -54,7 +65,7 @@ pub extern "C" fn new_axis_angle(x: f64, y: f64, z: f64, theta: f64) -> *mut Axi /// free_quaternion_memory FFI function and the axis angle memory using /// the free_array_memory function #[no_mangle] -pub unsafe extern "C" fn axis_angle_from_quaternion( +pub unsafe extern "C" fn viam_axis_angle_from_quaternion( quat: *const Quaternion, ) -> *mut AxisAngle { null_pointer_check!(quat); @@ -64,3 +75,11 @@ pub unsafe extern "C" fn axis_angle_from_quaternion( }; to_raw_pointer(&axis_angle) } + +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn axis_angle_from_quaternion( + quat: *const Quaternion, +) -> *mut AxisAngle { + viam_axis_angle_from_quaternion(quat) +} diff --git a/src/ffi/spatialmath/euler_angles.rs b/src/ffi/spatialmath/euler_angles.rs index e7b52fc..ee30463 100644 --- a/src/ffi/spatialmath/euler_angles.rs +++ b/src/ffi/spatialmath/euler_angles.rs @@ -23,13 +23,19 @@ fn to_raw_pointer(ea: &EulerAngles) -> *mut EulerAngles { /// Outer processes that work with EulerAngles via the FFI interface MUST remember /// to call this function when finished with a euler angles instance #[no_mangle] -pub unsafe extern "C" fn free_euler_angles_memory(ptr: *mut EulerAngles) { +pub unsafe extern "C" fn viam_free_euler_angles_memory(ptr: *mut EulerAngles) { if ptr.is_null() { return; } let _ = Box::from_raw(ptr); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn free_euler_angles_memory(ptr: *mut EulerAngles) { + viam_free_euler_angles_memory(ptr) +} + /// Initialize euler angles from raw components and retrieve the C pointer /// to its address. /// @@ -39,10 +45,16 @@ pub unsafe extern "C" fn free_euler_angles_memory(ptr: *mut EulerAngles) { /// the caller must remember to free the euler angles memory using the /// free_euler_angles_memory FFI function #[no_mangle] -pub extern "C" fn new_euler_angles(roll: f64, pitch: f64, yaw: f64) -> *mut EulerAngles { +pub extern "C" fn viam_new_euler_angles(roll: f64, pitch: f64, yaw: f64) -> *mut EulerAngles { to_raw_pointer(&EulerAngles::new(roll, pitch, yaw)) } +#[no_mangle] +#[deprecated] +pub extern "C" fn new_euler_angles(roll: f64, pitch: f64, yaw: f64) -> *mut EulerAngles { + viam_new_euler_angles(roll, pitch, yaw) +} + /// Converts a quaternion into euler angles (in radians). The euler angles are /// represented according to the Tait-Bryan formalism and applied /// in the Z-Y'-X" order (where Z -> yaw, Y -> pitch, X -> roll). @@ -54,10 +66,18 @@ pub extern "C" fn new_euler_angles(roll: f64, pitch: f64, yaw: f64) -> *mut Eule /// free_quaternion_memory FFI function and the euler angles memory using /// the free_euler_angles_memory function #[no_mangle] -pub unsafe extern "C" fn euler_angles_from_quaternion( +pub unsafe extern "C" fn viam_euler_angles_from_quaternion( quat_ptr: *const Quaternion, ) -> *mut EulerAngles { null_pointer_check!(quat_ptr); let euler_angles: EulerAngles = (*quat_ptr).into(); to_raw_pointer(&euler_angles) } + +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn euler_angles_from_quaternion( + quat_ptr: *const Quaternion, +) -> *mut EulerAngles { + viam_euler_angles_from_quaternion(quat_ptr) +} diff --git a/src/ffi/spatialmath/orientation_vector.rs b/src/ffi/spatialmath/orientation_vector.rs index ff37f74..1fd37d4 100644 --- a/src/ffi/spatialmath/orientation_vector.rs +++ b/src/ffi/spatialmath/orientation_vector.rs @@ -29,13 +29,19 @@ fn to_raw_pointer(o_vec: &OrientationVector) -> *mut OrientationVector { /// /// # Safety #[no_mangle] -pub unsafe extern "C" fn free_orientation_vector_memory(ptr: *mut OrientationVector) { +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) +} + /// Initialize an orientation vector from raw components and retrieve the C pointer /// to its address. /// @@ -45,7 +51,7 @@ pub unsafe extern "C" fn free_orientation_vector_memory(ptr: *mut OrientationVec /// the caller must remember to free the orientation vector memory using the /// free_orientation_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn new_orientation_vector( +pub unsafe extern "C" fn viam_new_orientation_vector( o_x: f64, o_y: f64, o_z: f64, @@ -55,6 +61,17 @@ pub unsafe extern "C" fn new_orientation_vector( 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) +} + /// Get the components of an orientation vector as a list of C doubles, the order of the /// components will be (o_x, o_y, o_z, theta). /// @@ -64,7 +81,7 @@ pub unsafe extern "C" fn new_orientation_vector( /// the caller must remember to free the orientation_vector memory using the /// free_orientation_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn orientation_vector_get_components( +pub unsafe extern "C" fn viam_orientation_vector_get_components( ov_ptr: *const OrientationVector, ) -> *const c_double { null_pointer_check!(ov_ptr); @@ -77,6 +94,14 @@ pub unsafe extern "C" fn orientation_vector_get_components( 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) +} + /// Converts a quaternion into an orientation vector. /// /// # Safety @@ -86,7 +111,7 @@ pub unsafe extern "C" fn orientation_vector_get_components( /// free_quaternion_memory FFI function and the orientation-vector memory using /// the free_orientation_vector_memory function #[no_mangle] -pub unsafe extern "C" fn orientation_vector_from_quaternion( +pub unsafe extern "C" fn viam_orientation_vector_from_quaternion( quat_ptr: *const Quaternion, ) -> *mut OrientationVector { null_pointer_check!(quat_ptr); @@ -94,6 +119,14 @@ pub unsafe extern "C" fn orientation_vector_from_quaternion( to_raw_pointer(&o_vec) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn orientation_vector_from_quaternion( + quat_ptr: *const Quaternion, +) -> *mut OrientationVector { + viam_orientation_vector_from_quaternion(quat_ptr) +} + /// Free memory of an array of orientation vector components at the given address. /// /// # Safety @@ -101,7 +134,7 @@ pub unsafe extern "C" fn orientation_vector_from_quaternion( /// Outer processes that request the components of a orientation vector should call this function /// to free the memory allocated to the array once finished #[no_mangle] -pub unsafe extern "C" fn free_orientation_vector_components(ptr: *mut c_double) { +pub unsafe extern "C" fn viam_free_orientation_vector_components(ptr: *mut c_double) { if ptr.is_null() { return; } @@ -109,3 +142,9 @@ pub unsafe extern "C" fn free_orientation_vector_components(ptr: *mut c_double) 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) +} diff --git a/src/ffi/spatialmath/quaternion.rs b/src/ffi/spatialmath/quaternion.rs index 230bbec..a20f3fa 100644 --- a/src/ffi/spatialmath/quaternion.rs +++ b/src/ffi/spatialmath/quaternion.rs @@ -29,10 +29,16 @@ fn to_raw_pointer(quat: &Quaternion) -> *mut Quaternion { /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub extern "C" fn new_quaternion(real: f64, i: f64, j: f64, k: f64) -> *mut Quaternion { +pub extern "C" fn viam_new_quaternion(real: f64, i: f64, j: f64, k: f64) -> *mut Quaternion { to_raw_pointer(&Quaternion::new(real, i, j, k)) } +#[no_mangle] +#[deprecated] +pub extern "C" fn new_quaternion(real: f64, i: f64, j: f64, k: f64) -> *mut Quaternion { + viam_new_quaternion(real, i, j, k) +} + /// Initialize a quaternion from a real part and a C pointer to a Vector3 /// and retrieve the C pointer to its address. /// @@ -42,7 +48,7 @@ pub extern "C" fn new_quaternion(real: f64, i: f64, j: f64, k: f64) -> *mut Quat /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn new_quaternion_from_vector( +pub unsafe extern "C" fn viam_new_quaternion_from_vector( real: f64, imag_ptr: *const Vector3, ) -> *mut Quaternion { @@ -55,6 +61,15 @@ pub unsafe extern "C" fn new_quaternion_from_vector( )) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn new_quaternion_from_vector( + real: f64, + imag_ptr: *const Vector3, +) -> *mut Quaternion { + viam_new_quaternion_from_vector(real, imag_ptr) +} + /// Free memory at the address of the quaternion pointer. /// /// # Safety @@ -62,13 +77,19 @@ pub unsafe extern "C" fn new_quaternion_from_vector( /// Outer processes that work with Quaternions via the FFI interface MUST remember /// to call this function when finished with a quaternion #[no_mangle] -pub unsafe extern "C" fn free_quaternion_memory(ptr: *mut Quaternion) { +pub unsafe extern "C" fn viam_free_quaternion_memory(ptr: *mut Quaternion) { if ptr.is_null() { return; } let _ = Box::from_raw(ptr); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn free_quaternion_memory(ptr: *mut Quaternion) { + viam_free_quaternion_memory(ptr) +} + /// Get the components of a quaternion as a list of C doubles, the order of the /// components will be (real, i, j, k). /// @@ -78,7 +99,7 @@ pub unsafe extern "C" fn free_quaternion_memory(ptr: *mut Quaternion) { /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_get_components( +pub unsafe extern "C" fn viam_quaternion_get_components( quat_ptr: *const Quaternion, ) -> *const c_double { null_pointer_check!(quat_ptr); @@ -91,6 +112,14 @@ pub unsafe extern "C" fn quaternion_get_components( Box::into_raw(Box::new(components)) as *const _ } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_get_components( + quat_ptr: *const Quaternion, +) -> *const c_double { + viam_quaternion_get_components(quat_ptr) +} + /// Set the real component of an existing quaternion stored at the address /// of a pointer. /// @@ -100,11 +129,17 @@ pub unsafe extern "C" fn quaternion_get_components( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_set_real(quat_ptr: *mut Quaternion, real: f64) { +pub unsafe extern "C" fn viam_quaternion_set_real(quat_ptr: *mut Quaternion, real: f64) { null_pointer_check!(quat_ptr); (&mut (*quat_ptr)).w = real; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_set_real(quat_ptr: *mut Quaternion, real: f64) { + viam_quaternion_set_real(quat_ptr, real) +} + /// Set the i component of an existing quaternion stored at the address /// of a pointer. /// @@ -114,11 +149,17 @@ pub unsafe extern "C" fn quaternion_set_real(quat_ptr: *mut Quaternion, rea /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_set_i(quat_ptr: *mut Quaternion, i: f64) { +pub unsafe extern "C" fn viam_quaternion_set_i(quat_ptr: *mut Quaternion, i: f64) { null_pointer_check!(quat_ptr); (&mut (*quat_ptr)).i = i; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_set_i(quat_ptr: *mut Quaternion, i: f64) { + viam_quaternion_set_i(quat_ptr, i) +} + /// Set the j component of an existing quaternion stored at the address /// of a pointer. /// @@ -128,11 +169,17 @@ pub unsafe extern "C" fn quaternion_set_i(quat_ptr: *mut Quaternion, i: f64 /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_set_j(quat_ptr: *mut Quaternion, j: f64) { +pub unsafe extern "C" fn viam_quaternion_set_j(quat_ptr: *mut Quaternion, j: f64) { null_pointer_check!(quat_ptr); (&mut (*quat_ptr)).j = j; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_set_j(quat_ptr: *mut Quaternion, j: f64) { + viam_quaternion_set_j(quat_ptr, j) +} + /// Set the k component of an existing quaternion stored at the address /// of a pointer. /// @@ -142,11 +189,17 @@ pub unsafe extern "C" fn quaternion_set_j(quat_ptr: *mut Quaternion, j: f64 /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_set_k(quat_ptr: *mut Quaternion, k: f64) { +pub unsafe extern "C" fn viam_quaternion_set_k(quat_ptr: *mut Quaternion, k: f64) { null_pointer_check!(quat_ptr); (&mut (*quat_ptr)).k = k; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_set_k(quat_ptr: *mut Quaternion, k: f64) { + viam_quaternion_set_k(quat_ptr, k) +} + /// Set all of the components of an existing quaternion stored at the address /// of a pointer /// @@ -156,7 +209,7 @@ pub unsafe extern "C" fn quaternion_set_k(quat_ptr: *mut Quaternion, k: f64 /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_set_components( +pub unsafe extern "C" fn viam_quaternion_set_components( quat_ptr: *mut Quaternion, real: f64, i: f64, @@ -170,6 +223,18 @@ pub unsafe extern "C" fn quaternion_set_components( (&mut (*quat_ptr)).k = k; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_set_components( + quat_ptr: *mut Quaternion, + real: f64, + i: f64, + j: f64, + k: f64, +) { + viam_quaternion_set_components(quat_ptr, real, i, j, k) +} + /// Set the imaginary components of an existing quaternion stored at /// the address of a pointer (quat_ptr) from the components of a 3-vector /// (stored at vec_ptr). The convention is x -> i, y -> j, z -> k @@ -181,7 +246,7 @@ pub unsafe extern "C" fn quaternion_set_components( /// free_quaternion_memory FFI function (the same applies for the vector /// stored at vec_ptr) #[no_mangle] -pub unsafe extern "C" fn quaternion_set_imag_from_vector( +pub unsafe extern "C" fn viam_quaternion_set_imag_from_vector( quat_ptr: *mut Quaternion, vec_ptr: *const Vector3, ) { @@ -192,6 +257,15 @@ pub unsafe extern "C" fn quaternion_set_imag_from_vector( (&mut (*quat_ptr)).k = (&(*vec_ptr)).z; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_set_imag_from_vector( + quat_ptr: *mut Quaternion, + vec_ptr: *const Vector3, +) { + viam_quaternion_set_imag_from_vector(quat_ptr, vec_ptr) +} + /// Copies the imaginary components to a 3-vector (using x -> i, y -> j /// z -> k) and returns a pointer to the memory address of the resulting /// vector @@ -202,7 +276,7 @@ pub unsafe extern "C" fn quaternion_set_imag_from_vector( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_get_imaginary_vector( +pub unsafe extern "C" fn viam_quaternion_get_imaginary_vector( quat_ptr: *const Quaternion, ) -> *mut Vector3 { null_pointer_check!(quat_ptr); @@ -211,6 +285,14 @@ pub unsafe extern "C" fn quaternion_get_imaginary_vector( vec_to_raw_pointer(imag_vec) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_get_imaginary_vector( + quat_ptr: *const Quaternion, +) -> *mut Vector3 { + viam_quaternion_get_imaginary_vector(quat_ptr) +} + /// Normalizes an existing quaternion stored at the address of /// a pointer (quat_ptr) /// @@ -220,11 +302,17 @@ pub unsafe extern "C" fn quaternion_get_imaginary_vector( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn normalize_quaternion(quat_ptr: *mut Quaternion) { +pub unsafe extern "C" fn viam_normalize_quaternion(quat_ptr: *mut Quaternion) { null_pointer_check!(quat_ptr); (*quat_ptr).normalize_mut(); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn normalize_quaternion(quat_ptr: *mut Quaternion) { + viam_normalize_quaternion(quat_ptr) +} + /// Initializes a normalized copy of a quaternion stored at the /// address of a pointer (quat_ptr) and returns a pointer to the /// memory of the result @@ -235,13 +323,21 @@ pub unsafe extern "C" fn normalize_quaternion(quat_ptr: *mut Quaternion) { /// *both* the input and output quaternions when finished with them /// using the free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_get_normalized( +pub unsafe extern "C" fn viam_quaternion_get_normalized( quat_ptr: *const Quaternion, ) -> *mut Quaternion { null_pointer_check!(quat_ptr); to_raw_pointer(&(*quat_ptr).normalize()) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_get_normalized( + quat_ptr: *const Quaternion, +) -> *mut Quaternion { + viam_quaternion_get_normalized(quat_ptr) +} + /// Returns the result of rotating a vector by a quaternion /// /// # Safety @@ -250,7 +346,7 @@ pub unsafe extern "C" fn quaternion_get_normalized( /// the memory of both vectors when finished with them using the /// free_quaternion_memory and free_vector_memory FFI functions #[no_mangle] -pub unsafe extern "C" fn quaternion_rotate_vector( +pub unsafe extern "C" fn viam_quaternion_rotate_vector( quat_ptr: *const Quaternion, vec_ptr: *const Vector3, ) -> *mut Vector3 { @@ -260,6 +356,15 @@ pub unsafe extern "C" fn quaternion_rotate_vector( vec_to_raw_pointer(rotated) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_rotate_vector( + quat_ptr: *const Quaternion, + vec_ptr: *const Vector3, +) -> *mut Vector3 { + viam_quaternion_rotate_vector(quat_ptr, vec_ptr) +} + /// Converts from euler angles (in radians) to a quaternion. The euler angles are expected to /// be represented according to the Tait-Bryan formalism and applied in the Z-Y'-X" /// order (where Z -> yaw, Y -> pitch, X -> roll) @@ -270,7 +375,7 @@ pub unsafe extern "C" fn quaternion_rotate_vector( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_from_euler_angles( +pub unsafe extern "C" fn viam_quaternion_from_euler_angles( roll: f64, pitch: f64, yaw: f64, @@ -280,6 +385,16 @@ pub unsafe extern "C" fn quaternion_from_euler_angles( to_raw_pointer(quat) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_from_euler_angles( + roll: f64, + pitch: f64, + yaw: f64, +) -> *mut Quaternion { + viam_quaternion_from_euler_angles(roll, pitch, yaw) +} + /// Converts from an axis angle given by a vector's x, y, z components /// and a rotation theta (in radians) about the vector into a quaternion /// @@ -289,7 +404,7 @@ pub unsafe extern "C" fn quaternion_from_euler_angles( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_from_axis_angle( +pub unsafe extern "C" fn viam_quaternion_from_axis_angle( x: f64, y: f64, z: f64, @@ -301,6 +416,17 @@ pub unsafe extern "C" fn quaternion_from_axis_angle( to_raw_pointer(unit_quat.quaternion()) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_from_axis_angle( + x: f64, + y: f64, + z: f64, + theta: f64, +) -> *mut Quaternion { + viam_quaternion_from_axis_angle(x, y, z, theta) +} + /// Converts from an axis angle whose vector is given by a pointer /// to a nalgebra::Vector3 instance and a rotation theta (in radians) /// about the vector to a quaternion @@ -312,7 +438,7 @@ pub unsafe extern "C" fn quaternion_from_axis_angle( /// free_quaternion_memory FFI function. Similarly the free_vector_memory should /// be called when finished with the axis angle vector #[no_mangle] -pub unsafe extern "C" fn quaternion_from_axis_angle_vector( +pub unsafe extern "C" fn viam_quaternion_from_axis_angle_vector( theta: f64, axis_angle_vec_ptr: *const Vector3, ) -> *mut Quaternion { @@ -322,6 +448,15 @@ pub unsafe extern "C" fn quaternion_from_axis_angle_vector( to_raw_pointer(unit_quat.quaternion()) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_from_axis_angle_vector( + theta: f64, + axis_angle_vec_ptr: *const Vector3, +) -> *mut Quaternion { + viam_quaternion_from_axis_angle_vector(theta, axis_angle_vec_ptr) +} + /// Converts from a pointer to a Rotation3 to a quaternion /// /// # Safety @@ -330,7 +465,7 @@ pub unsafe extern "C" fn quaternion_from_axis_angle_vector( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_from_rotation_matrix( +pub unsafe extern "C" fn viam_quaternion_from_rotation_matrix( rot_ptr: *const Rotation3, ) -> *mut Quaternion { null_pointer_check!(rot_ptr); @@ -338,6 +473,14 @@ pub unsafe extern "C" fn quaternion_from_rotation_matrix( to_raw_pointer(unit_quat.quaternion()) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_from_rotation_matrix( + rot_ptr: *const Rotation3, +) -> *mut Quaternion { + viam_quaternion_from_rotation_matrix(rot_ptr) +} + /// Converts from a pointer to an OrientationVector to a quaternion /// /// # Safety @@ -346,13 +489,21 @@ pub unsafe extern "C" fn quaternion_from_rotation_matrix( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_from_orientation_vector( +pub unsafe extern "C" fn viam_quaternion_from_orientation_vector( o_vec_ptr: *const OrientationVector, ) -> *mut Quaternion { null_pointer_check!(o_vec_ptr); to_raw_pointer(&(*o_vec_ptr).to_quaternion()) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_from_orientation_vector( + o_vec_ptr: *const OrientationVector, +) -> *mut Quaternion { + viam_quaternion_from_orientation_vector(o_vec_ptr) +} + /// Scales an existing quaternion stored at the address of /// a pointer (quat_ptr) by a factor (float) /// @@ -362,11 +513,17 @@ pub unsafe extern "C" fn quaternion_from_orientation_vector( /// the caller must remember to free the quaternion memory using the /// free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn scale_quaternion(quat_ptr: *mut Quaternion, factor: f64) { +pub unsafe extern "C" fn viam_scale_quaternion(quat_ptr: *mut Quaternion, factor: f64) { null_pointer_check!(quat_ptr); (*quat_ptr).scale_mut(factor); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn scale_quaternion(quat_ptr: *mut Quaternion, factor: f64) { + viam_scale_quaternion(quat_ptr, factor) +} + /// Initializes a copy of the quaternion stored at the address of a pointer (quat_ptr) /// scaled by a factor (float) and returns a pointer to the memory of the result /// @@ -376,7 +533,7 @@ pub unsafe extern "C" fn scale_quaternion(quat_ptr: *mut Quaternion, factor /// *both* the input and output quaternions when finished with them /// using the free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_get_scaled( +pub unsafe extern "C" fn viam_quaternion_get_scaled( quat_ptr: *const Quaternion, factor: f64, ) -> *mut Quaternion { @@ -386,6 +543,15 @@ pub unsafe extern "C" fn quaternion_get_scaled( to_raw_pointer(©_quat) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_get_scaled( + quat_ptr: *const Quaternion, + factor: f64, +) -> *mut Quaternion { + viam_quaternion_get_scaled(quat_ptr, factor) +} + /// Initializes a quaternion that is the conjugate of one stored /// at the address of a pointer (quat_ptr)and returns a pointer /// to the memory of the result @@ -396,13 +562,21 @@ pub unsafe extern "C" fn quaternion_get_scaled( /// *both* the input and output quaternions when finished with them /// using the free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_get_conjugate( +pub unsafe extern "C" fn viam_quaternion_get_conjugate( quat_ptr: *const Quaternion, ) -> *mut Quaternion { null_pointer_check!(quat_ptr); to_raw_pointer(&(*quat_ptr).conjugate()) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_get_conjugate( + quat_ptr: *const Quaternion, +) -> *mut Quaternion { + viam_quaternion_get_conjugate(quat_ptr) +} + /// Adds two quaternions and returns a pointer to the /// memory of the result /// @@ -411,7 +585,7 @@ pub unsafe extern "C" fn quaternion_get_conjugate( /// The caller must remember to free the quaternion memory of *both* the input and /// output quaternions when finished with them using the free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_add( +pub unsafe extern "C" fn viam_quaternion_add( quat_ptr_1: *const Quaternion, quat_ptr_2: *const Quaternion, ) -> *mut Quaternion { @@ -420,6 +594,15 @@ pub unsafe extern "C" fn quaternion_add( to_raw_pointer(&((*quat_ptr_1) + (*quat_ptr_2))) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_add( + quat_ptr_1: *const Quaternion, + quat_ptr_2: *const Quaternion, +) -> *mut Quaternion { + viam_quaternion_add(quat_ptr_1, quat_ptr_2) +} + /// Subtracts two quaternions and returns a pointer to the /// memory of the result /// @@ -428,7 +611,7 @@ pub unsafe extern "C" fn quaternion_add( /// The caller must remember to free the quaternion memory of *both* the input and /// output quaternions when finished with them using the free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_subtract( +pub unsafe extern "C" fn viam_quaternion_subtract( quat_ptr_1: *const Quaternion, quat_ptr_2: *const Quaternion, ) -> *mut Quaternion { @@ -437,6 +620,15 @@ pub unsafe extern "C" fn quaternion_subtract( to_raw_pointer(&((*quat_ptr_1) - (*quat_ptr_2))) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_subtract( + quat_ptr_1: *const Quaternion, + quat_ptr_2: *const Quaternion, +) -> *mut Quaternion { + viam_quaternion_subtract(quat_ptr_1, quat_ptr_2) +} + /// Computes the Hamiltonian product of two quaternions and /// returns a pointer to the memory of the result /// @@ -445,7 +637,7 @@ pub unsafe extern "C" fn quaternion_subtract( /// The caller must remember to free the quaternion memory of *both* the input and /// output quaternions when finished with them using the free_quaternion_memory FFI function #[no_mangle] -pub unsafe extern "C" fn quaternion_hamiltonian_product( +pub unsafe extern "C" fn viam_quaternion_hamiltonian_product( quat_ptr_1: *const Quaternion, quat_ptr_2: *const Quaternion, ) -> *mut Quaternion { @@ -454,6 +646,15 @@ pub unsafe extern "C" fn quaternion_hamiltonian_product( to_raw_pointer(&((*quat_ptr_1) * (*quat_ptr_2))) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn quaternion_hamiltonian_product( + quat_ptr_1: *const Quaternion, + quat_ptr_2: *const Quaternion, +) -> *mut Quaternion { + viam_quaternion_hamiltonian_product(quat_ptr_1, quat_ptr_2) +} + /// Free memory of an array of quaternion components at the given address. /// /// # Safety @@ -461,10 +662,16 @@ pub unsafe extern "C" fn quaternion_hamiltonian_product( /// Outer processes that request the components of a quaternion should call this function /// to free the memory allocated to the array once finished #[no_mangle] -pub unsafe extern "C" fn free_quaternion_components(ptr: *mut c_double) { +pub unsafe extern "C" fn viam_free_quaternion_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_quaternion_components(ptr: *mut c_double) { + viam_free_quaternion_components(ptr) +} diff --git a/src/ffi/spatialmath/rotation_matrix.rs b/src/ffi/spatialmath/rotation_matrix.rs index aff41d2..3a035eb 100644 --- a/src/ffi/spatialmath/rotation_matrix.rs +++ b/src/ffi/spatialmath/rotation_matrix.rs @@ -17,13 +17,19 @@ fn to_raw_pointer(rot: &Rotation3) -> *mut Rotation3 { /// /// # Safety #[no_mangle] -pub unsafe extern "C" fn free_rotation_matrix_memory(ptr: *mut Rotation3) { +pub unsafe extern "C" fn viam_free_rotation_matrix_memory(ptr: *mut Rotation3) { 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) { + viam_free_rotation_matrix_memory(ptr) +} + /// Initialize a 3D rotation matrix from raw components and retrieve the C pointer /// to its address. This function DOES NOT check whether the matrix elements provided /// form a valid member of SO(3) @@ -34,13 +40,21 @@ pub unsafe extern "C" fn free_rotation_matrix_memory(ptr: *mut Rotation3) { /// the caller must remember to free the rotation matrix memory using the /// free_rotation_matrix_memory FFI function #[no_mangle] -pub unsafe extern "C" fn new_rotation_matrix(elements: *const [f64; 9]) -> *mut Rotation3 { +pub unsafe extern "C" fn viam_new_rotation_matrix( + elements: *const [f64; 9], +) -> *mut Rotation3 { 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 { + viam_new_rotation_matrix(elements) +} + /// Converts a quaternion into a 3D rotation matrix (a Rotation /// from the nalgebra crate) /// @@ -51,7 +65,7 @@ pub unsafe extern "C" fn new_rotation_matrix(elements: *const [f64; 9]) -> *mut /// free_quaternion_memory FFI function and the rotation matrix memory using /// the free_rotation_matrix_memory function #[no_mangle] -pub unsafe extern "C" fn rotation_matrix_from_quaternion( +pub unsafe extern "C" fn viam_rotation_matrix_from_quaternion( quat: *const Quaternion, ) -> *mut Rotation3 { null_pointer_check!(quat); @@ -59,3 +73,11 @@ pub unsafe extern "C" fn rotation_matrix_from_quaternion( 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, +) -> *mut Rotation3 { + viam_rotation_matrix_from_quaternion(quat) +} diff --git a/src/ffi/spatialmath/vector3.rs b/src/ffi/spatialmath/vector3.rs index 7e75fc8..943e834 100644 --- a/src/ffi/spatialmath/vector3.rs +++ b/src/ffi/spatialmath/vector3.rs @@ -22,24 +22,36 @@ pub(crate) fn to_raw_pointer(vec: Vector3) -> *mut Vector3 { /// the caller must remember to free the vector memory using the /// free_vector_memory FFI function #[no_mangle] -pub extern "C" fn new_vector3(x: f64, y: f64, z: f64) -> *mut Vector3 { +pub extern "C" fn viam_new_vector3(x: f64, y: f64, z: f64) -> *mut Vector3 { let new_vec = Vector3::new(x, y, z); to_raw_pointer(new_vec) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn new_vector3(x: f64, y: f64, z: f64) -> *mut Vector3 { + viam_new_vector3(x, y, z) +} + /// Free memory at the address of the vector pointer. /// /// # Safety /// Outer processes that work with Vectors via the FFI interface MUST remember /// to call this function when finished with a vector #[no_mangle] -pub unsafe extern "C" fn free_vector_memory(ptr: *mut Vector3) { +pub unsafe extern "C" fn viam_free_vector_memory(ptr: *mut Vector3) { if ptr.is_null() { return; } let _ = Box::from_raw(ptr); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn free_vector_memory(ptr: *mut Vector3) { + viam_free_vector_memory(ptr) +} + /// Get the components of a vector as a list of C doubles, the order of the /// components will be (x, y, z). /// @@ -48,12 +60,20 @@ pub unsafe extern "C" fn free_vector_memory(ptr: *mut Vector3) { /// When finished with the underlying vector, the caller must remember to /// free the vector memory using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_get_components(vec_ptr: *const Vector3) -> *const c_double { +pub unsafe extern "C" fn viam_vector_get_components( + vec_ptr: *const Vector3, +) -> *const c_double { null_pointer_check!(vec_ptr); let components: [c_double; 3] = [(&(*vec_ptr))[0], (&(*vec_ptr))[1], (&(*vec_ptr))[2]]; Box::into_raw(Box::new(components)) as *const _ } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_get_components(vec_ptr: *const Vector3) -> *const c_double { + viam_vector_get_components(vec_ptr) +} + /// Set the x component of an existing vector stored at the address /// of a pointer. /// @@ -62,11 +82,17 @@ pub unsafe extern "C" fn vector_get_components(vec_ptr: *const Vector3) -> /// When finished with the underlying vector, the caller must remember to /// free the vector memory using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_set_x(vec_ptr: *mut Vector3, x_val: f64) { +pub unsafe extern "C" fn viam_vector_set_x(vec_ptr: *mut Vector3, x_val: f64) { null_pointer_check!(vec_ptr); (&mut (*vec_ptr))[0] = x_val; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_set_x(vec_ptr: *mut Vector3, x_val: f64) { + viam_vector_set_x(vec_ptr, x_val) +} + /// Set the y component of an existing vector stored at the address /// of a pointer. /// @@ -75,11 +101,17 @@ pub unsafe extern "C" fn vector_set_x(vec_ptr: *mut Vector3, x_val: f64) { /// When finished with the underlying vector, the caller must remember to /// free the vector memory using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_set_y(vec_ptr: *mut Vector3, y_val: f64) { +pub unsafe extern "C" fn viam_vector_set_y(vec_ptr: *mut Vector3, y_val: f64) { null_pointer_check!(vec_ptr); (&mut (*vec_ptr))[1] = y_val; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_set_y(vec_ptr: *mut Vector3, y_val: f64) { + viam_vector_set_y(vec_ptr, y_val) +} + /// Set the z component of an existing vector stored at the address /// of a pointer. /// @@ -88,11 +120,17 @@ pub unsafe extern "C" fn vector_set_y(vec_ptr: *mut Vector3, y_val: f64) { /// When finished with the underlying vector, the caller must remember to /// free the vector memory using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_set_z(vec_ptr: *mut Vector3, z_val: f64) { +pub unsafe extern "C" fn viam_vector_set_z(vec_ptr: *mut Vector3, z_val: f64) { null_pointer_check!(vec_ptr); (&mut (*vec_ptr))[2] = z_val; } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_set_z(vec_ptr: *mut Vector3, z_val: f64) { + viam_vector_set_z(vec_ptr, z_val) +} + /// Normalizes an existing vector stored at the address of /// a pointer (vec_ptr) /// @@ -101,11 +139,17 @@ pub unsafe extern "C" fn vector_set_z(vec_ptr: *mut Vector3, z_val: f64) { /// When finished with the underlying vector, the caller must remember to /// free the vector memory using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn normalize_vector(vec_ptr: *mut Vector3) { +pub unsafe extern "C" fn viam_normalize_vector(vec_ptr: *mut Vector3) { null_pointer_check!(vec_ptr); (*vec_ptr).normalize_mut(); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn normalize_vector(vec_ptr: *mut Vector3) { + viam_normalize_vector(vec_ptr) +} + /// Initializes a normalized copy of a vector stored at the /// address of a pointer (vec_ptr) and returns a pointer to the /// memory of the result @@ -115,12 +159,20 @@ pub unsafe extern "C" fn normalize_vector(vec_ptr: *mut Vector3) { /// The caller must remember to free the vector memory of *both* the input and /// output vectors when finished with them using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_get_normalized(vec_ptr: *const Vector3) -> *mut Vector3 { +pub unsafe extern "C" fn viam_vector_get_normalized( + vec_ptr: *const Vector3, +) -> *mut Vector3 { null_pointer_check!(vec_ptr); let vec = (*vec_ptr).normalize(); to_raw_pointer(vec) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_get_normalized(vec_ptr: *const Vector3) -> *mut Vector3 { + viam_vector_get_normalized(vec_ptr) +} + /// Scales an existing vector stored at the address of /// a pointer (vec_ptr) by a float factor /// @@ -129,11 +181,17 @@ pub unsafe extern "C" fn vector_get_normalized(vec_ptr: *const Vector3) -> /// When finished with the underlying vector, the caller must remember to /// free the vector memory using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn scale_vector(vec_ptr: *mut Vector3, factor: f64) { +pub unsafe extern "C" fn viam_scale_vector(vec_ptr: *mut Vector3, factor: f64) { null_pointer_check!(vec_ptr); (*vec_ptr).scale_mut(factor); } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn scale_vector(vec_ptr: *mut Vector3, factor: f64) { + viam_scale_vector(vec_ptr, factor) +} + /// Initializes a scaled copy of a vector stored at the /// address of a pointer (vec_ptr) and returns a pointer to the /// memory of the result @@ -143,7 +201,7 @@ pub unsafe extern "C" fn scale_vector(vec_ptr: *mut Vector3, factor: f64) { /// The caller must remember to free the vector memory of *both* the input and /// output vectors when finished with them using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_get_scaled( +pub unsafe extern "C" fn viam_vector_get_scaled( vec_ptr: *const Vector3, factor: f64, ) -> *mut Vector3 { @@ -152,6 +210,15 @@ pub unsafe extern "C" fn vector_get_scaled( to_raw_pointer(vec) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_get_scaled( + vec_ptr: *const Vector3, + factor: f64, +) -> *mut Vector3 { + viam_vector_get_scaled(vec_ptr, factor) +} + /// Adds two vectors and returns a pointer to the /// memory of the result /// @@ -160,7 +227,7 @@ pub unsafe extern "C" fn vector_get_scaled( /// The caller must remember to free the vector memory of *both* the input and /// output vectors when finished with them using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_add( +pub unsafe extern "C" fn viam_vector_add( vec_ptr_1: *const Vector3, vec_ptr_2: *const Vector3, ) -> *mut Vector3 { @@ -169,6 +236,15 @@ pub unsafe extern "C" fn vector_add( to_raw_pointer((*vec_ptr_1) + (*vec_ptr_2)) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_add( + vec_ptr_1: *const Vector3, + vec_ptr_2: *const Vector3, +) -> *mut Vector3 { + viam_vector_add(vec_ptr_1, vec_ptr_2) +} + /// Subtracts two vectors and returns a pointer to the /// memory of the result /// @@ -177,7 +253,7 @@ pub unsafe extern "C" fn vector_add( /// The caller must remember to free the vector memory of *both* the input and /// output vectors when finished with them using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_subtract( +pub unsafe extern "C" fn viam_vector_subtract( vec_ptr_1: *const Vector3, vec_ptr_2: *const Vector3, ) -> *mut Vector3 { @@ -186,6 +262,15 @@ pub unsafe extern "C" fn vector_subtract( to_raw_pointer((*vec_ptr_1) - (*vec_ptr_2)) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_subtract( + vec_ptr_1: *const Vector3, + vec_ptr_2: *const Vector3, +) -> *mut Vector3 { + viam_vector_subtract(vec_ptr_1, vec_ptr_2) +} + /// Computes the dot product of two vectors /// /// # Safety @@ -193,7 +278,7 @@ pub unsafe extern "C" fn vector_subtract( /// The caller must remember to free the vector memory of the input vectors /// when finished with them using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_dot_product( +pub unsafe extern "C" fn viam_vector_dot_product( vec_ptr_1: *const Vector3, vec_ptr_2: *const Vector3, ) -> f64 { @@ -202,6 +287,15 @@ pub unsafe extern "C" fn vector_dot_product( (*vec_ptr_1).dot(&*vec_ptr_2) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_dot_product( + vec_ptr_1: *const Vector3, + vec_ptr_2: *const Vector3, +) -> f64 { + viam_vector_dot_product(vec_ptr_1, vec_ptr_2) +} + /// Computes the cross product of two vectors and returns /// a pointer to the memory of the result /// @@ -210,7 +304,7 @@ pub unsafe extern "C" fn vector_dot_product( /// The caller must remember to free the vector memory of *both* the input and /// output vectors when finished with them using the free_vector_memory FFI function #[no_mangle] -pub unsafe extern "C" fn vector_cross_product( +pub unsafe extern "C" fn viam_vector_cross_product( vec_ptr_1: *mut Vector3, vec_ptr_2: *mut Vector3, ) -> *mut Vector3 { @@ -220,6 +314,15 @@ pub unsafe extern "C" fn vector_cross_product( to_raw_pointer(vec) } +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn vector_cross_product( + vec_ptr_1: *mut Vector3, + vec_ptr_2: *mut Vector3, +) -> *mut Vector3 { + viam_vector_cross_product(vec_ptr_1, vec_ptr_2) +} + /// Free memory of an array of vector components at the given address. /// /// # Safety @@ -227,10 +330,16 @@ pub unsafe extern "C" fn vector_cross_product( /// Outer processes that request the components of a vector should call this function /// to free the memory allocated to the array once finished #[no_mangle] -pub unsafe extern "C" fn free_vector_components(ptr: *mut c_double) { +pub unsafe extern "C" fn viam_free_vector_components(ptr: *mut c_double) { if ptr.is_null() { return; } let ptr = ptr as *mut [c_double; 3]; let _: Box<[c_double; 3]> = Box::from_raw(ptr); } + +#[no_mangle] +#[deprecated] +pub unsafe extern "C" fn free_vector_components(ptr: *mut c_double) { + viam_free_vector_components(ptr) +}