From 5328e2d26ccf82b0d7ec9fe9c1f03bf9afe761e7 Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Tue, 4 Nov 2025 11:09:51 -0500 Subject: [PATCH 01/10] autogen header file --- .github/workflows/release.yml | 3 + Cargo.lock | 108 ++- Cargo.toml | 1 + build.rs | 19 + viam_rust_utils.h | 1214 +++++++++++++++++++++++++++++++++ 5 files changed, 1333 insertions(+), 12 deletions(-) create mode 100644 build.rs create mode 100644 viam_rust_utils.h diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45420a1..79180b9 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.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.h - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -228,6 +230,7 @@ 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.h - name: Upload artifacts uses: actions/upload-artifact@v4 with: 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..57b3731 --- /dev/null +++ b/build.rs @@ -0,0 +1,19 @@ +extern crate cbindgen; + +use std::env; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_parse_include(&["nalgebra"]) + .with_parse_deps(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/viam_rust_utils.h b/viam_rust_utils.h new file mode 100644 index 0000000..9f70b47 --- /dev/null +++ b/viam_rust_utils.h @@ -0,0 +1,1214 @@ +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ + +#include +#include +#include +#include + +/** + * The DialFfi interface, returned as a pointer by init_rust_runtime. User should keep this pointer until freeing the runtime. + */ +typedef struct DialFfi DialFfi; + +/** + * A array-based statically sized matrix data storage. + */ +typedef double ArrayStorage_f64__3__1[1][3]; + +/** + * The most generic column-major matrix (and vector) type. + * + * # Methods summary + * Because `Matrix` is the most generic types used as a common representation of all matrices and + * vectors of **nalgebra** this documentation page contains every single matrix/vector-related + * method. In order to make browsing this page simpler, the next subsections contain direct links + * to groups of methods related to a specific topic. + * + * #### Vector and matrix construction + * - [Constructors of statically-sized vectors or statically-sized matrices](#constructors-of-statically-sized-vectors-or-statically-sized-matrices) + * (`Vector3`, `Matrix3x6`…) + * - [Constructors of fully dynamic matrices](#constructors-of-fully-dynamic-matrices) (`DMatrix`) + * - [Constructors of dynamic vectors and matrices with a dynamic number of rows](#constructors-of-dynamic-vectors-and-matrices-with-a-dynamic-number-of-rows) + * (`DVector`, `MatrixXx3`…) + * - [Constructors of matrices with a dynamic number of columns](#constructors-of-matrices-with-a-dynamic-number-of-columns) + * (`Matrix2xX`…) + * - [Generic constructors](#generic-constructors) + * (For code generic wrt. the vectors or matrices dimensions.) + * + * #### Computer graphics utilities for transformations + * - [2D transformations as a Matrix3 `new_rotation`…](#2d-transformations-as-a-matrix3) + * - [3D transformations as a Matrix4 `new_rotation`, `new_perspective`, `look_at_rh`…](#3d-transformations-as-a-matrix4) + * - [Translation and scaling in any dimension `new_scaling`, `new_translation`…](#translation-and-scaling-in-any-dimension) + * - [Append/prepend translation and scaling `append_scaling`, `prepend_translation_mut`…](#appendprepend-translation-and-scaling) + * - [Transformation of vectors and points `transform_vector`, `transform_point`…](#transformation-of-vectors-and-points) + * + * #### Common math operations + * - [Componentwise operations `component_mul`, `component_div`, `inf`…](#componentwise-operations) + * - [Special multiplications `tr_mul`, `ad_mul`, `kronecker`…](#special-multiplications) + * - [Dot/scalar product `dot`, `dotc`, `tr_dot`…](#dotscalar-product) + * - [Cross product `cross`, `perp`…](#cross-product) + * - [Magnitude and norms `norm`, `normalize`, `metric_distance`…](#magnitude-and-norms) + * - [In-place normalization `normalize_mut`, `try_normalize_mut`…](#in-place-normalization) + * - [Interpolation `lerp`, `slerp`…](#interpolation) + * - [BLAS functions `gemv`, `gemm`, `syger`…](#blas-functions) + * - [Swizzling `xx`, `yxz`…](#swizzling) + * - [Triangular matrix extraction `upper_triangle`, `lower_triangle`](#triangular-matrix-extraction) + * + * #### Statistics + * - [Common operations `row_sum`, `column_mean`, `variance`…](#common-statistics-operations) + * - [Find the min and max components `min`, `max`, `amin`, `amax`, `camin`, `cmax`…](#find-the-min-and-max-components) + * - [Find the min and max components (vector-specific methods) `argmin`, `argmax`, `icamin`, `icamax`…](#find-the-min-and-max-components-vector-specific-methods) + * + * #### Iteration, map, and fold + * - [Iteration on components, rows, and columns `iter`, `column_iter`…](#iteration-on-components-rows-and-columns) + * - [Elementwise mapping and folding `map`, `fold`, `zip_map`…](#elementwise-mapping-and-folding) + * - [Folding or columns and rows `compress_rows`, `compress_columns`…](#folding-on-columns-and-rows) + * + * #### Vector and matrix slicing + * - [Creating matrix slices from `&[T]` `from_slice`, `from_slice_with_strides`…](#creating-matrix-slices-from-t) + * - [Creating mutable matrix slices from `&mut [T]` `from_slice_mut`, `from_slice_with_strides_mut`…](#creating-mutable-matrix-slices-from-mut-t) + * - [Slicing based on index and length `row`, `columns`, `slice`…](#slicing-based-on-index-and-length) + * - [Mutable slicing based on index and length `row_mut`, `columns_mut`, `slice_mut`…](#mutable-slicing-based-on-index-and-length) + * - [Slicing based on ranges `rows_range`, `columns_range`…](#slicing-based-on-ranges) + * - [Mutable slicing based on ranges `rows_range_mut`, `columns_range_mut`…](#mutable-slicing-based-on-ranges) + * + * #### In-place modification of a single matrix or vector + * - [In-place filling `fill`, `fill_diagonal`, `fill_with_identity`…](#in-place-filling) + * - [In-place swapping `swap`, `swap_columns`…](#in-place-swapping) + * - [Set rows, columns, and diagonal `set_column`, `set_diagonal`…](#set-rows-columns-and-diagonal) + * + * #### Vector and matrix size modification + * - [Rows and columns insertion `insert_row`, `insert_column`…](#rows-and-columns-insertion) + * - [Rows and columns removal `remove_row`, `remove column`…](#rows-and-columns-removal) + * - [Rows and columns extraction `select_rows`, `select_columns`…](#rows-and-columns-extraction) + * - [Resizing and reshaping `resize`, `reshape_generic`…](#resizing-and-reshaping) + * - [In-place resizing `resize_mut`, `resize_vertically_mut`…](#in-place-resizing) + * + * #### Matrix decomposition + * - [Rectangular matrix decomposition `qr`, `lu`, `svd`…](#rectangular-matrix-decomposition) + * - [Square matrix decomposition `cholesky`, `symmetric_eigen`…](#square-matrix-decomposition) + * + * #### Vector basis computation + * - [Basis and orthogonalization `orthonormal_subspace_basis`, `orthonormalize`…](#basis-and-orthogonalization) + * + * # Type parameters + * The generic `Matrix` type has four type parameters: + * - `T`: for the matrix components scalar type. + * - `R`: for the matrix number of rows. + * - `C`: for the matrix number of columns. + * - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix + * components. + * + * The matrix dimensions parameters `R` and `C` can either be: + * - type-level unsigned integer constants (e.g. `U1`, `U124`) from the `nalgebra::` root module. + * All numbers from 0 to 127 are defined that way. + * - type-level unsigned integer constants (e.g. `U1024`, `U10000`) from the `typenum::` crate. + * Using those, you will not get error messages as nice as for numbers smaller than 128 defined on + * the `nalgebra::` module. + * - the special value `Dynamic` from the `nalgebra::` root module. This indicates that the + * specified dimension is not known at compile-time. Note that this will generally imply that the + * matrix data storage `S` performs a dynamic allocation and contains extra metadata for the + * matrix shape. + * + * Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a + * dynamically-sized column vector should be represented as a `Matrix` (given + * some concrete types for `T` and a compatible data storage type `S`). + */ +typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 { + /** + * The data storage that contains all the matrix components. Disappointed? + * + * Well, if you came here to see how you can access the matrix components, + * you may be in luck: you can access the individual components of all vectors with compile-time + * dimensions <= 6 using field notation like this: + * `vec.x`, `vec.y`, `vec.z`, `vec.w`, `vec.a`, `vec.b`. Reference and assignation work too: + * ``` + * # use nalgebra::Vector3; + * let mut vec = Vector3::new(1.0, 2.0, 3.0); + * vec.x = 10.0; + * vec.y += 30.0; + * assert_eq!(vec.x, 10.0); + * assert_eq!(vec.y + 100.0, 132.0); + * ``` + * Similarly, for matrices with compile-time dimensions <= 6, you can use field notation + * like this: `mat.m11`, `mat.m42`, etc. The first digit identifies the row to address + * and the second digit identifies the column to address. So `mat.m13` identifies the component + * at the first row and third column (note that the count of rows and columns start at 1 instead + * of 0 here. This is so we match the mathematical notation). + * + * For all matrices and vectors, independently from their size, individual components can + * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing + * starts at 0 as you would expect. + */ + ArrayStorage_f64__3__1 data; +} Matrix_f64__U3__U1__ArrayStorage_f64__3__1; + +/** + * A stack-allocated, 3-dimensional column vector. + */ +typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 Vector3_f64; + +typedef struct AxisAngle { + Vector3_f64 axis; + double theta; +} AxisAngle; + +/** + * A array-based statically sized matrix data storage. + */ +typedef double ArrayStorage_f64__4__1[1][4]; + +/** + * The most generic column-major matrix (and vector) type. + * + * # Methods summary + * Because `Matrix` is the most generic types used as a common representation of all matrices and + * vectors of **nalgebra** this documentation page contains every single matrix/vector-related + * method. In order to make browsing this page simpler, the next subsections contain direct links + * to groups of methods related to a specific topic. + * + * #### Vector and matrix construction + * - [Constructors of statically-sized vectors or statically-sized matrices](#constructors-of-statically-sized-vectors-or-statically-sized-matrices) + * (`Vector3`, `Matrix3x6`…) + * - [Constructors of fully dynamic matrices](#constructors-of-fully-dynamic-matrices) (`DMatrix`) + * - [Constructors of dynamic vectors and matrices with a dynamic number of rows](#constructors-of-dynamic-vectors-and-matrices-with-a-dynamic-number-of-rows) + * (`DVector`, `MatrixXx3`…) + * - [Constructors of matrices with a dynamic number of columns](#constructors-of-matrices-with-a-dynamic-number-of-columns) + * (`Matrix2xX`…) + * - [Generic constructors](#generic-constructors) + * (For code generic wrt. the vectors or matrices dimensions.) + * + * #### Computer graphics utilities for transformations + * - [2D transformations as a Matrix3 `new_rotation`…](#2d-transformations-as-a-matrix3) + * - [3D transformations as a Matrix4 `new_rotation`, `new_perspective`, `look_at_rh`…](#3d-transformations-as-a-matrix4) + * - [Translation and scaling in any dimension `new_scaling`, `new_translation`…](#translation-and-scaling-in-any-dimension) + * - [Append/prepend translation and scaling `append_scaling`, `prepend_translation_mut`…](#appendprepend-translation-and-scaling) + * - [Transformation of vectors and points `transform_vector`, `transform_point`…](#transformation-of-vectors-and-points) + * + * #### Common math operations + * - [Componentwise operations `component_mul`, `component_div`, `inf`…](#componentwise-operations) + * - [Special multiplications `tr_mul`, `ad_mul`, `kronecker`…](#special-multiplications) + * - [Dot/scalar product `dot`, `dotc`, `tr_dot`…](#dotscalar-product) + * - [Cross product `cross`, `perp`…](#cross-product) + * - [Magnitude and norms `norm`, `normalize`, `metric_distance`…](#magnitude-and-norms) + * - [In-place normalization `normalize_mut`, `try_normalize_mut`…](#in-place-normalization) + * - [Interpolation `lerp`, `slerp`…](#interpolation) + * - [BLAS functions `gemv`, `gemm`, `syger`…](#blas-functions) + * - [Swizzling `xx`, `yxz`…](#swizzling) + * - [Triangular matrix extraction `upper_triangle`, `lower_triangle`](#triangular-matrix-extraction) + * + * #### Statistics + * - [Common operations `row_sum`, `column_mean`, `variance`…](#common-statistics-operations) + * - [Find the min and max components `min`, `max`, `amin`, `amax`, `camin`, `cmax`…](#find-the-min-and-max-components) + * - [Find the min and max components (vector-specific methods) `argmin`, `argmax`, `icamin`, `icamax`…](#find-the-min-and-max-components-vector-specific-methods) + * + * #### Iteration, map, and fold + * - [Iteration on components, rows, and columns `iter`, `column_iter`…](#iteration-on-components-rows-and-columns) + * - [Elementwise mapping and folding `map`, `fold`, `zip_map`…](#elementwise-mapping-and-folding) + * - [Folding or columns and rows `compress_rows`, `compress_columns`…](#folding-on-columns-and-rows) + * + * #### Vector and matrix slicing + * - [Creating matrix slices from `&[T]` `from_slice`, `from_slice_with_strides`…](#creating-matrix-slices-from-t) + * - [Creating mutable matrix slices from `&mut [T]` `from_slice_mut`, `from_slice_with_strides_mut`…](#creating-mutable-matrix-slices-from-mut-t) + * - [Slicing based on index and length `row`, `columns`, `slice`…](#slicing-based-on-index-and-length) + * - [Mutable slicing based on index and length `row_mut`, `columns_mut`, `slice_mut`…](#mutable-slicing-based-on-index-and-length) + * - [Slicing based on ranges `rows_range`, `columns_range`…](#slicing-based-on-ranges) + * - [Mutable slicing based on ranges `rows_range_mut`, `columns_range_mut`…](#mutable-slicing-based-on-ranges) + * + * #### In-place modification of a single matrix or vector + * - [In-place filling `fill`, `fill_diagonal`, `fill_with_identity`…](#in-place-filling) + * - [In-place swapping `swap`, `swap_columns`…](#in-place-swapping) + * - [Set rows, columns, and diagonal `set_column`, `set_diagonal`…](#set-rows-columns-and-diagonal) + * + * #### Vector and matrix size modification + * - [Rows and columns insertion `insert_row`, `insert_column`…](#rows-and-columns-insertion) + * - [Rows and columns removal `remove_row`, `remove column`…](#rows-and-columns-removal) + * - [Rows and columns extraction `select_rows`, `select_columns`…](#rows-and-columns-extraction) + * - [Resizing and reshaping `resize`, `reshape_generic`…](#resizing-and-reshaping) + * - [In-place resizing `resize_mut`, `resize_vertically_mut`…](#in-place-resizing) + * + * #### Matrix decomposition + * - [Rectangular matrix decomposition `qr`, `lu`, `svd`…](#rectangular-matrix-decomposition) + * - [Square matrix decomposition `cholesky`, `symmetric_eigen`…](#square-matrix-decomposition) + * + * #### Vector basis computation + * - [Basis and orthogonalization `orthonormal_subspace_basis`, `orthonormalize`…](#basis-and-orthogonalization) + * + * # Type parameters + * The generic `Matrix` type has four type parameters: + * - `T`: for the matrix components scalar type. + * - `R`: for the matrix number of rows. + * - `C`: for the matrix number of columns. + * - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix + * components. + * + * The matrix dimensions parameters `R` and `C` can either be: + * - type-level unsigned integer constants (e.g. `U1`, `U124`) from the `nalgebra::` root module. + * All numbers from 0 to 127 are defined that way. + * - type-level unsigned integer constants (e.g. `U1024`, `U10000`) from the `typenum::` crate. + * Using those, you will not get error messages as nice as for numbers smaller than 128 defined on + * the `nalgebra::` module. + * - the special value `Dynamic` from the `nalgebra::` root module. This indicates that the + * specified dimension is not known at compile-time. Note that this will generally imply that the + * matrix data storage `S` performs a dynamic allocation and contains extra metadata for the + * matrix shape. + * + * Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a + * dynamically-sized column vector should be represented as a `Matrix` (given + * some concrete types for `T` and a compatible data storage type `S`). + */ +typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 { + /** + * The data storage that contains all the matrix components. Disappointed? + * + * Well, if you came here to see how you can access the matrix components, + * you may be in luck: you can access the individual components of all vectors with compile-time + * dimensions <= 6 using field notation like this: + * `vec.x`, `vec.y`, `vec.z`, `vec.w`, `vec.a`, `vec.b`. Reference and assignation work too: + * ``` + * # use nalgebra::Vector3; + * let mut vec = Vector3::new(1.0, 2.0, 3.0); + * vec.x = 10.0; + * vec.y += 30.0; + * assert_eq!(vec.x, 10.0); + * assert_eq!(vec.y + 100.0, 132.0); + * ``` + * Similarly, for matrices with compile-time dimensions <= 6, you can use field notation + * like this: `mat.m11`, `mat.m42`, etc. The first digit identifies the row to address + * and the second digit identifies the column to address. So `mat.m13` identifies the component + * at the first row and third column (note that the count of rows and columns start at 1 instead + * of 0 here. This is so we match the mathematical notation). + * + * For all matrices and vectors, independently from their size, individual components can + * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing + * starts at 0 as you would expect. + */ + ArrayStorage_f64__4__1 data; +} Matrix_f64__U4__U1__ArrayStorage_f64__4__1; + +/** + * A stack-allocated, 4-dimensional column vector. + */ +typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 Vector4_f64; + +/** + * A quaternion. See the type alias `UnitQuaternion = Unit` for a quaternion + * that may be used as a rotation. + */ +typedef struct Quaternion_f64 { + /** + * This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. + */ + Vector4_f64 coords; +} Quaternion_f64; + +typedef struct EulerAngles { + double roll; + double pitch; + double yaw; +} EulerAngles; + +/** + * A wrapper that ensures the underlying algebraic entity has a unit norm. + * + * **It is likely that the only piece of documentation that you need in this page are:** + * - **[The construction with normalization](#construction-with-normalization)** + * - **[Data extraction and construction without normalization](#data-extraction-and-construction-without-normalization)** + * - **[Interpolation between two unit vectors](#interpolation-between-two-unit-vectors)** + * + * All the other impl blocks you will see in this page are about [`UnitComplex`](crate::UnitComplex) + * and [`UnitQuaternion`](crate::UnitQuaternion); both built on top of `Unit`. If you are interested + * in their documentation, read their dedicated pages directly. + */ +typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1; + +/** + * A stack-allocated, 3-dimensional unit vector. + */ +typedef Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1 UnitVector3_f64; + +typedef struct OrientationVector { + UnitVector3_f64 o_vector; + double theta; +} OrientationVector; + +/** + * A array-based statically sized matrix data storage. + */ +typedef double ArrayStorage_f64__3__3[3][3]; + +/** + * The most generic column-major matrix (and vector) type. + * + * # Methods summary + * Because `Matrix` is the most generic types used as a common representation of all matrices and + * vectors of **nalgebra** this documentation page contains every single matrix/vector-related + * method. In order to make browsing this page simpler, the next subsections contain direct links + * to groups of methods related to a specific topic. + * + * #### Vector and matrix construction + * - [Constructors of statically-sized vectors or statically-sized matrices](#constructors-of-statically-sized-vectors-or-statically-sized-matrices) + * (`Vector3`, `Matrix3x6`…) + * - [Constructors of fully dynamic matrices](#constructors-of-fully-dynamic-matrices) (`DMatrix`) + * - [Constructors of dynamic vectors and matrices with a dynamic number of rows](#constructors-of-dynamic-vectors-and-matrices-with-a-dynamic-number-of-rows) + * (`DVector`, `MatrixXx3`…) + * - [Constructors of matrices with a dynamic number of columns](#constructors-of-matrices-with-a-dynamic-number-of-columns) + * (`Matrix2xX`…) + * - [Generic constructors](#generic-constructors) + * (For code generic wrt. the vectors or matrices dimensions.) + * + * #### Computer graphics utilities for transformations + * - [2D transformations as a Matrix3 `new_rotation`…](#2d-transformations-as-a-matrix3) + * - [3D transformations as a Matrix4 `new_rotation`, `new_perspective`, `look_at_rh`…](#3d-transformations-as-a-matrix4) + * - [Translation and scaling in any dimension `new_scaling`, `new_translation`…](#translation-and-scaling-in-any-dimension) + * - [Append/prepend translation and scaling `append_scaling`, `prepend_translation_mut`…](#appendprepend-translation-and-scaling) + * - [Transformation of vectors and points `transform_vector`, `transform_point`…](#transformation-of-vectors-and-points) + * + * #### Common math operations + * - [Componentwise operations `component_mul`, `component_div`, `inf`…](#componentwise-operations) + * - [Special multiplications `tr_mul`, `ad_mul`, `kronecker`…](#special-multiplications) + * - [Dot/scalar product `dot`, `dotc`, `tr_dot`…](#dotscalar-product) + * - [Cross product `cross`, `perp`…](#cross-product) + * - [Magnitude and norms `norm`, `normalize`, `metric_distance`…](#magnitude-and-norms) + * - [In-place normalization `normalize_mut`, `try_normalize_mut`…](#in-place-normalization) + * - [Interpolation `lerp`, `slerp`…](#interpolation) + * - [BLAS functions `gemv`, `gemm`, `syger`…](#blas-functions) + * - [Swizzling `xx`, `yxz`…](#swizzling) + * - [Triangular matrix extraction `upper_triangle`, `lower_triangle`](#triangular-matrix-extraction) + * + * #### Statistics + * - [Common operations `row_sum`, `column_mean`, `variance`…](#common-statistics-operations) + * - [Find the min and max components `min`, `max`, `amin`, `amax`, `camin`, `cmax`…](#find-the-min-and-max-components) + * - [Find the min and max components (vector-specific methods) `argmin`, `argmax`, `icamin`, `icamax`…](#find-the-min-and-max-components-vector-specific-methods) + * + * #### Iteration, map, and fold + * - [Iteration on components, rows, and columns `iter`, `column_iter`…](#iteration-on-components-rows-and-columns) + * - [Elementwise mapping and folding `map`, `fold`, `zip_map`…](#elementwise-mapping-and-folding) + * - [Folding or columns and rows `compress_rows`, `compress_columns`…](#folding-on-columns-and-rows) + * + * #### Vector and matrix slicing + * - [Creating matrix slices from `&[T]` `from_slice`, `from_slice_with_strides`…](#creating-matrix-slices-from-t) + * - [Creating mutable matrix slices from `&mut [T]` `from_slice_mut`, `from_slice_with_strides_mut`…](#creating-mutable-matrix-slices-from-mut-t) + * - [Slicing based on index and length `row`, `columns`, `slice`…](#slicing-based-on-index-and-length) + * - [Mutable slicing based on index and length `row_mut`, `columns_mut`, `slice_mut`…](#mutable-slicing-based-on-index-and-length) + * - [Slicing based on ranges `rows_range`, `columns_range`…](#slicing-based-on-ranges) + * - [Mutable slicing based on ranges `rows_range_mut`, `columns_range_mut`…](#mutable-slicing-based-on-ranges) + * + * #### In-place modification of a single matrix or vector + * - [In-place filling `fill`, `fill_diagonal`, `fill_with_identity`…](#in-place-filling) + * - [In-place swapping `swap`, `swap_columns`…](#in-place-swapping) + * - [Set rows, columns, and diagonal `set_column`, `set_diagonal`…](#set-rows-columns-and-diagonal) + * + * #### Vector and matrix size modification + * - [Rows and columns insertion `insert_row`, `insert_column`…](#rows-and-columns-insertion) + * - [Rows and columns removal `remove_row`, `remove column`…](#rows-and-columns-removal) + * - [Rows and columns extraction `select_rows`, `select_columns`…](#rows-and-columns-extraction) + * - [Resizing and reshaping `resize`, `reshape_generic`…](#resizing-and-reshaping) + * - [In-place resizing `resize_mut`, `resize_vertically_mut`…](#in-place-resizing) + * + * #### Matrix decomposition + * - [Rectangular matrix decomposition `qr`, `lu`, `svd`…](#rectangular-matrix-decomposition) + * - [Square matrix decomposition `cholesky`, `symmetric_eigen`…](#square-matrix-decomposition) + * + * #### Vector basis computation + * - [Basis and orthogonalization `orthonormal_subspace_basis`, `orthonormalize`…](#basis-and-orthogonalization) + * + * # Type parameters + * The generic `Matrix` type has four type parameters: + * - `T`: for the matrix components scalar type. + * - `R`: for the matrix number of rows. + * - `C`: for the matrix number of columns. + * - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix + * components. + * + * The matrix dimensions parameters `R` and `C` can either be: + * - type-level unsigned integer constants (e.g. `U1`, `U124`) from the `nalgebra::` root module. + * All numbers from 0 to 127 are defined that way. + * - type-level unsigned integer constants (e.g. `U1024`, `U10000`) from the `typenum::` crate. + * Using those, you will not get error messages as nice as for numbers smaller than 128 defined on + * the `nalgebra::` module. + * - the special value `Dynamic` from the `nalgebra::` root module. This indicates that the + * specified dimension is not known at compile-time. Note that this will generally imply that the + * matrix data storage `S` performs a dynamic allocation and contains extra metadata for the + * matrix shape. + * + * Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a + * dynamically-sized column vector should be represented as a `Matrix` (given + * some concrete types for `T` and a compatible data storage type `S`). + */ +typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 { + /** + * The data storage that contains all the matrix components. Disappointed? + * + * Well, if you came here to see how you can access the matrix components, + * you may be in luck: you can access the individual components of all vectors with compile-time + * dimensions <= 6 using field notation like this: + * `vec.x`, `vec.y`, `vec.z`, `vec.w`, `vec.a`, `vec.b`. Reference and assignation work too: + * ``` + * # use nalgebra::Vector3; + * let mut vec = Vector3::new(1.0, 2.0, 3.0); + * vec.x = 10.0; + * vec.y += 30.0; + * assert_eq!(vec.x, 10.0); + * assert_eq!(vec.y + 100.0, 132.0); + * ``` + * Similarly, for matrices with compile-time dimensions <= 6, you can use field notation + * like this: `mat.m11`, `mat.m42`, etc. The first digit identifies the row to address + * and the second digit identifies the column to address. So `mat.m13` identifies the component + * at the first row and third column (note that the count of rows and columns start at 1 instead + * of 0 here. This is so we match the mathematical notation). + * + * For all matrices and vectors, independently from their size, individual components can + * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing + * starts at 0 as you would expect. + */ + ArrayStorage_f64__3__3 data; +} Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3; + +/** + * A statically sized column-major matrix with `R` rows and `C` columns. + * + * **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** + */ +typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 SMatrix_f64__3__3; + +/** + * A rotation matrix. + * + * This is also known as an element of a Special Orthogonal (SO) group. + * The `Rotation` type can either represent a 2D or 3D rotation, represented as a matrix. + * For a rotation based on quaternions, see [`UnitQuaternion`](crate::UnitQuaternion) instead. + * + * Note that instead of using the [`Rotation`](crate::Rotation) type in your code directly, you should use one + * of its aliases: [`Rotation2`](crate::Rotation2), or [`Rotation3`](crate::Rotation3). Though + * keep in mind that all the documentation of all the methods of these aliases will also appears on + * this page. + * + * # Construction + * * [Identity `identity`](#identity) + * * [From a 2D rotation angle `new`…](#construction-from-a-2d-rotation-angle) + * * [From an existing 2D matrix or rotations `from_matrix`, `rotation_between`, `powf`…](#construction-from-an-existing-2d-matrix-or-rotations) + * * [From a 3D axis and/or angles `new`, `from_euler_angles`, `from_axis_angle`…](#construction-from-a-3d-axis-andor-angles) + * * [From a 3D eye position and target point `look_at`, `look_at_lh`, `rotation_between`…](#construction-from-a-3d-eye-position-and-target-point) + * * [From an existing 3D matrix or rotations `from_matrix`, `rotation_between`, `powf`…](#construction-from-an-existing-3d-matrix-or-rotations) + * + * # Transformation and composition + * Note that transforming vectors and points can be done by multiplication, e.g., `rotation * point`. + * Composing an rotation with another transformation can also be done by multiplication or division. + * * [3D axis and angle extraction `angle`, `euler_angles`, `scaled_axis`, `angle_to`…](#3d-axis-and-angle-extraction) + * * [2D angle extraction `angle`, `angle_to`…](#2d-angle-extraction) + * * [Transformation of a vector or a point `transform_vector`, `inverse_transform_point`…](#transformation-of-a-vector-or-a-point) + * * [Transposition and inversion `transpose`, `inverse`…](#transposition-and-inversion) + * * [Interpolation `slerp`…](#interpolation) + * + * # Conversion + * * [Conversion to a matrix `matrix`, `to_homogeneous`…](#conversion-to-a-matrix) + * + */ +typedef struct Rotation_f64__3 { + SMatrix_f64__3__3 matrix; +} Rotation_f64__3; + +/** + * A 3-dimensional rotation matrix. + * + * **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** + */ +typedef struct Rotation_f64__3 Rotation3_f64; + +/** + * 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`] + */ +struct DialFfi *init_rust_runtime(void); + +/** + * Returns a path to a proxy to a robot + * # Safety + * + * This function must be called from another language. See [`dial`](mod@crate::rpc::dial) for dial from rust + * The function returns a path to a proxy as a [`c_char`], the string should be freed with free_string when not needed anymore. + * When falling to dial it will return a NULL pointer + * # Arguments + * * `c_uri` a C-style string representing the address of robot you want to connect to + * * `c_type` a C-style string representing the type of robot's secret you want to use, set to NULL if you don't need authentication + * * `c_payload` a C-style string that is the robot's secret, set to NULL if you don't need authentication + * * `c_allow_insecure` a bool, set to true when allowing insecure connection to your robot + * * `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 + */ +char *dial(const char *c_uri, + const char *c_entity, + const char *c_type, + const char *c_payload, + bool c_allow_insec, + float c_timeout, + struct DialFfi *rt_ptr); + +/** + * This function must be used to free the path returned by the [`dial`] function + * # Safety + * + * The function must not be called more than once with the same pointer + * # Arguments + * * `c_char` a pointer to the string returned by [`dial`] + */ +void free_string(char *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 + * + * The function must not be called more than once with the same pointer + * # Arguments + * * `rt_prt` a pointer to the string returned by [`init_rust_runtime`] + */ +int32_t free_rust_runtime(struct DialFfi *rt_ptr); + +/** + * Free memory at the address of the axis angle pointer. + * + * # Safety + * + * Outer processes that work with axis angles via the FFI interface MUST remember + * to call this function when finished with an axis angle instance + */ +void free_axis_angles_memory(struct AxisAngle *ptr); + +/** + * Initialize axis angle from raw components and retrieve the C pointer + * to its address. + * + * # Safety + * + * When finished with the underlying axis angle initialized by this function + * the caller must remember to free the axis angle memory using the + * free_axis_angles_memory FFI function + */ +struct AxisAngle *new_axis_angle(double x, double y, double z, double 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 + * a zero axis angle. In the event of an error from the nalgebra crate, a zero + * axis angle is also returned. + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function and the axis angle memory using + * the free_array_memory function + */ +struct AxisAngle *axis_angle_from_quaternion(const struct Quaternion_f64 *quat); + +/** + * Free memory at the address of the euler angles pointer. + * + * # Safety + * + * Outer processes that work with EulerAngles via the FFI interface MUST remember + * to call this function when finished with a euler angles instance + */ +void free_euler_angles_memory(struct EulerAngles *ptr); + +/** + * Initialize euler angles from raw components and retrieve the C pointer + * to its address. + * + * # Safety + * + * When finished with the underlying euler angles initialized by this function + * the caller must remember to free the euler angles memory using the + * free_euler_angles_memory FFI function + */ +struct EulerAngles *new_euler_angles(double roll, double pitch, double 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). + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function and the euler angles memory using + * the free_euler_angles_memory function + */ +struct EulerAngles *euler_angles_from_quaternion(const struct Quaternion_f64 *quat_ptr); + +/** + * Free memory at the address of the orientation vector pointer. Outer processes + * that work with OrientationVectors via the FFI interface MUST remember + * to call this function when finished with a OrientationVector instance + * + * # Safety + */ +void free_orientation_vector_memory(struct OrientationVector *ptr); + +/** + * Initialize an orientation vector from raw components and retrieve the C pointer + * to its address. + * + * # Safety + * + * When finished with the underlying orientation vector initialized by this function + * the caller must remember to free the orientation vector memory using the + * free_orientation_vector_memory FFI function + */ +struct OrientationVector *new_orientation_vector(double o_x, double o_y, double o_z, double 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). + * + * # Safety + * + * When finished with the underlying orientation_vector passed to this function + * the caller must remember to free the orientation_vector memory using the + * free_orientation_vector_memory FFI function + */ +const double *orientation_vector_get_components(const struct OrientationVector *ov_ptr); + +/** + * Converts a quaternion into an orientation vector. + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function and the orientation-vector memory using + * the free_orientation_vector_memory function + */ +struct OrientationVector *orientation_vector_from_quaternion(const struct Quaternion_f64 *quat_ptr); + +/** + * Free memory of an array of orientation vector components at the given address. + * + * # Safety + * + * Outer processes that request the components of a orientation vector should call this function + * to free the memory allocated to the array once finished + */ +void free_orientation_vector_components(double *ptr); + +/** + * Initialize a quaternion from raw components and retrieve the C pointer + * to its address. + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +struct Quaternion_f64 *new_quaternion(double real, double i, double j, double k); + +/** + * Initialize a quaternion from a real part and a C pointer to a Vector3 + * and retrieve the C pointer to its address. + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +struct Quaternion_f64 *new_quaternion_from_vector(double real, const Vector3_f64 *imag_ptr); + +/** + * Free memory at the address of the quaternion pointer. + * + * # Safety + * + * Outer processes that work with Quaternions via the FFI interface MUST remember + * to call this function when finished with a quaternion + */ +void free_quaternion_memory(struct Quaternion_f64 *ptr); + +/** + * Get the components of a quaternion as a list of C doubles, the order of the + * components will be (real, i, j, k). + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +const double *quaternion_get_components(const struct Quaternion_f64 *quat_ptr); + +/** + * Set the real component of an existing quaternion stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void quaternion_set_real(struct Quaternion_f64 *quat_ptr, double real); + +/** + * Set the i component of an existing quaternion stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void quaternion_set_i(struct Quaternion_f64 *quat_ptr, double i); + +/** + * Set the j component of an existing quaternion stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void quaternion_set_j(struct Quaternion_f64 *quat_ptr, double j); + +/** + * Set the k component of an existing quaternion stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void quaternion_set_k(struct Quaternion_f64 *quat_ptr, double k); + +/** + * Set all of the components of an existing quaternion stored at the address + * of a pointer + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void quaternion_set_components(struct Quaternion_f64 *quat_ptr, + double real, + double i, + double j, + double 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 + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function (the same applies for the vector + * stored at vec_ptr) + */ +void quaternion_set_imag_from_vector(struct Quaternion_f64 *quat_ptr, const Vector3_f64 *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 + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +Vector3_f64 *quaternion_get_imaginary_vector(const struct Quaternion_f64 *quat_ptr); + +/** + * Normalizes an existing quaternion stored at the address of + * a pointer (quat_ptr) + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void normalize_quaternion(struct Quaternion_f64 *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 + * + * # Safety + * + * 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 + */ +struct Quaternion_f64 *quaternion_get_normalized(const struct Quaternion_f64 *quat_ptr); + +/** + * Returns the result of rotating a vector by a quaternion + * + * # Safety + * + * The caller must remember to free the quaternion memory and + * the memory of both vectors when finished with them using the + * free_quaternion_memory and free_vector_memory FFI functions + */ +Vector3_f64 *quaternion_rotate_vector(const struct Quaternion_f64 *quat_ptr, + const Vector3_f64 *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) + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +struct Quaternion_f64 *quaternion_from_euler_angles(double roll, double pitch, double 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 + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +struct Quaternion_f64 *quaternion_from_axis_angle(double x, double y, double z, double 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 + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function. Similarly the free_vector_memory should + * be called when finished with the axis angle vector + */ +struct Quaternion_f64 *quaternion_from_axis_angle_vector(double theta, + const Vector3_f64 *axis_angle_vec_ptr); + +/** + * Converts from a pointer to a Rotation3 to a quaternion + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +struct Quaternion_f64 *quaternion_from_rotation_matrix(const Rotation3_f64 *rot_ptr); + +/** + * Converts from a pointer to an OrientationVector to a quaternion + * + * # Safety + * + * When finished with the underlying quaternion initialized by this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +struct Quaternion_f64 *quaternion_from_orientation_vector(const struct OrientationVector *o_vec_ptr); + +/** + * Scales an existing quaternion stored at the address of + * a pointer (quat_ptr) by a factor (float) + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function + */ +void scale_quaternion(struct Quaternion_f64 *quat_ptr, double 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 + * + * # Safety + * + * 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 + */ +struct Quaternion_f64 *quaternion_get_scaled(const struct Quaternion_f64 *quat_ptr, double 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 + * + * # Safety + * + * 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 + */ +struct Quaternion_f64 *quaternion_get_conjugate(const struct Quaternion_f64 *quat_ptr); + +/** + * Adds two quaternions and returns a pointer to the + * memory of the result + * + * # Safety + * + * 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 + */ +struct Quaternion_f64 *quaternion_add(const struct Quaternion_f64 *quat_ptr_1, + const struct Quaternion_f64 *quat_ptr_2); + +/** + * Subtracts two quaternions and returns a pointer to the + * memory of the result + * + * # Safety + * + * 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 + */ +struct Quaternion_f64 *quaternion_subtract(const struct Quaternion_f64 *quat_ptr_1, + const struct Quaternion_f64 *quat_ptr_2); + +/** + * Computes the Hamiltonian product of two quaternions and + * returns a pointer to the memory of the result + * + * # Safety + * + * 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 + */ +struct Quaternion_f64 *quaternion_hamiltonian_product(const struct Quaternion_f64 *quat_ptr_1, + const struct Quaternion_f64 *quat_ptr_2); + +/** + * Free memory of an array of quaternion components at the given address. + * + * # Safety + * + * Outer processes that request the components of a quaternion should call this function + * to free the memory allocated to the array once finished + */ +void free_quaternion_components(double *ptr); + +/** + * Free memory at the address of the rotation matrix pointer. Outer processes + * that work with RotationMatrices via the FFI interface MUST remember + * to call this function when finished with a rotation matrix + * + * # Safety + */ +void free_rotation_matrix_memory(Rotation3_f64 *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) + * + * # Safety + * + * When finished with the underlying rotation matrix initialized by this function + * the caller must remember to free the rotation matrix memory using the + * free_rotation_matrix_memory FFI function + */ +Rotation3_f64 *new_rotation_matrix(const double (*elements)[9]); + +/** + * Converts a quaternion into a 3D rotation matrix (a Rotation + * from the nalgebra crate) + * + * # Safety + * + * When finished with the underlying quaternion passed to this function + * the caller must remember to free the quaternion memory using the + * free_quaternion_memory FFI function and the rotation matrix memory using + * the free_rotation_matrix_memory function + */ +Rotation3_f64 *rotation_matrix_from_quaternion(const struct Quaternion_f64 *quat); + +/** + * Initialize a 3-vector from raw components and retrieve the C pointer + * to its address. + * + * # Safety + * + * When finished with the underlying vector initialized by this function + * the caller must remember to free the vector memory using the + * free_vector_memory FFI function + */ +Vector3_f64 *new_vector3(double x, double y, double 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 + */ +void free_vector_memory(Vector3_f64 *ptr); + +/** + * Get the components of a vector as a list of C doubles, the order of the + * components will be (x, y, z). + * + * # Safety + * + * When finished with the underlying vector, the caller must remember to + * free the vector memory using the free_vector_memory FFI function + */ +const double *vector_get_components(const Vector3_f64 *vec_ptr); + +/** + * Set the x component of an existing vector stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying vector, the caller must remember to + * free the vector memory using the free_vector_memory FFI function + */ +void vector_set_x(Vector3_f64 *vec_ptr, double x_val); + +/** + * Set the y component of an existing vector stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying vector, the caller must remember to + * free the vector memory using the free_vector_memory FFI function + */ +void vector_set_y(Vector3_f64 *vec_ptr, double y_val); + +/** + * Set the z component of an existing vector stored at the address + * of a pointer. + * + * # Safety + * + * When finished with the underlying vector, the caller must remember to + * free the vector memory using the free_vector_memory FFI function + */ +void vector_set_z(Vector3_f64 *vec_ptr, double z_val); + +/** + * Normalizes an existing vector stored at the address of + * a pointer (vec_ptr) + * + * # Safety + * + * When finished with the underlying vector, the caller must remember to + * free the vector memory using the free_vector_memory FFI function + */ +void normalize_vector(Vector3_f64 *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 + * + * # Safety + * + * 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 + */ +Vector3_f64 *vector_get_normalized(const Vector3_f64 *vec_ptr); + +/** + * Scales an existing vector stored at the address of + * a pointer (vec_ptr) by a float factor + * + * # Safety + * + * When finished with the underlying vector, the caller must remember to + * free the vector memory using the free_vector_memory FFI function + */ +void scale_vector(Vector3_f64 *vec_ptr, double 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 + * + * # Safety + * + * 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 + */ +Vector3_f64 *vector_get_scaled(const Vector3_f64 *vec_ptr, double factor); + +/** + * Adds two vectors and returns a pointer to the + * memory of the result + * + * # Safety + * + * 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 + */ +Vector3_f64 *vector_add(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr_2); + +/** + * Subtracts two vectors and returns a pointer to the + * memory of the result + * + * # Safety + * + * 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 + */ +Vector3_f64 *vector_subtract(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr_2); + +/** + * Computes the dot product of two vectors + * + * # Safety + * + * The caller must remember to free the vector memory of the input vectors + * when finished with them using the free_vector_memory FFI function + */ +double vector_dot_product(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr_2); + +/** + * Computes the cross product of two vectors and returns + * a pointer to the memory of the result + * + * # Safety + * + * 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 + */ +Vector3_f64 *vector_cross_product(Vector3_f64 *vec_ptr_1, Vector3_f64 *vec_ptr_2); + +/** + * Free memory of an array of vector components at the given address. + * + * # Safety + * + * Outer processes that request the components of a vector should call this function + * to free the memory allocated to the array once finished + */ +void free_vector_components(double *ptr); From 2c19c294baabf90b903814a20b877a7e7f1edf5d Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Tue, 4 Nov 2025 11:20:40 -0500 Subject: [PATCH 02/10] add BSD-zero clause to license finder --- doc/dependency_decisions.yml | 6 ++++++ 1 file changed, 6 insertions(+) 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 From 2ca8592d22b8998577c529f5ae2c27aa69f3f44d Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Tue, 4 Nov 2025 11:54:49 -0500 Subject: [PATCH 03/10] add cpp compatibility --- build.rs | 1 + viam_rust_utils.h | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/build.rs b/build.rs index 57b3731..e2b1a3c 100644 --- a/build.rs +++ b/build.rs @@ -9,6 +9,7 @@ fn main() { .with_crate(crate_dir) .with_parse_include(&["nalgebra"]) .with_parse_deps(true) + .with_cpp_compat(true) .with_language(cbindgen::Language::C) .with_autogen_warning( "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */", diff --git a/viam_rust_utils.h b/viam_rust_utils.h index 9f70b47..6b2c5cf 100644 --- a/viam_rust_utils.h +++ b/viam_rust_utils.h @@ -516,6 +516,10 @@ typedef struct Rotation_f64__3 { */ typedef struct Rotation_f64__3 Rotation3_f64; +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** * 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`] @@ -1212,3 +1216,7 @@ Vector3_f64 *vector_cross_product(Vector3_f64 *vec_ptr_1, Vector3_f64 *vec_ptr_2 * to free the memory allocated to the array once finished */ void free_vector_components(double *ptr); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus From 4b0ed049bbf0c24f05b7363e9928b2d275f35f3e Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Tue, 4 Nov 2025 14:04:45 -0500 Subject: [PATCH 04/10] architecture-specific header file --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79180b9..a64a838 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -96,7 +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.h + 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 @@ -196,7 +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.h + cp viam_rust_utils.h builds/viam_rust_utils-${{ matrix.platform }}.h - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -230,7 +230,7 @@ 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.h + cp viam_rust_utils.h builds/viam_rust_utils-${{ matrix.platform }}.h - name: Upload artifacts uses: actions/upload-artifact@v4 with: From cc48a24c292cde7433891452a11b9f0c092623bc Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Wed, 12 Nov 2025 11:40:37 -0500 Subject: [PATCH 05/10] pr comments --- .github/workflows/release.yml | 31 +- build.rs | 74 +++- src/ffi/dial_ffi.rs | 8 +- src/ffi/spatialmath/axis_angle.rs | 25 +- src/ffi/spatialmath/euler_angles.rs | 26 +- src/ffi/spatialmath/orientation_vector.rs | 49 ++- src/ffi/spatialmath/quaternion.rs | 259 ++++++++++++-- src/ffi/spatialmath/rotation_matrix.rs | 28 +- src/ffi/spatialmath/vector3.rs | 139 +++++++- viam_rust_utils.h | 410 +++++++++++++++++----- 10 files changed, 893 insertions(+), 156 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a64a838..8581a1d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -237,8 +237,37 @@ jobs: name: builds-${{ matrix.platform }} path: builds/* + create_canonical_header: + needs: [builds_macos, build_linux, build_windows] + runs-on: ubuntu-latest + # pick one arbitrarily as the canonical header file + 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] + needs: [build_macos, build_linux, build_windows, compare_headers] runs-on: ubuntu-latest steps: - name: Merge artifacts diff --git a/build.rs b/build.rs index e2b1a3c..0fb91a1 100644 --- a/build.rs +++ b/build.rs @@ -1,14 +1,82 @@ extern crate cbindgen; -use std::env; +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__array_storage_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__array_storage_f64_4_1", + "nalgebra_matrix_f64_4_1", + ), + ("Vector4_f64", "nalgebra_vector4_f64"), + ("Quaternion_f64", "nalgebra_quaternion_f64"), + ( + "Unit_matrix_f64_u3_u1_array_storage_f64_3_1", + "nalgebra_unit_matrix_f64_3_1", + ), + ("UnitVector3_f64", "nalgebra_unit_vector3_f64"), + ("Rotation_f64__3", "nalgebra_rotation_f64_3"), + ]; + + // mangled viam type outputs, mapped to a prefixed snake case variant + let viam_types = vec![ + ( + "Matrix_f64__const_3__const_3__array_storage_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"), + ("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_parse_include(&["nalgebra"]) - .with_parse_deps(true) + .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( diff --git a/src/ffi/dial_ffi.rs b/src/ffi/dial_ffi.rs index 22dd1b2..7ce263e 100644 --- a/src/ffi/dial_ffi.rs +++ b/src/ffi/dial_ffi.rs @@ -65,7 +65,7 @@ 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] +#[export_name = "viam_init_rust_runtime"] pub extern "C" fn init_rust_runtime() -> Box { let _ = tracing_subscriber::fmt::try_init(); Box::new(DialFfi::new()) @@ -118,7 +118,7 @@ fn dial_with_cred( /// * `c_allow_insecure` a bool, set to true when allowing insecure connection to your robot /// * `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] +#[export_name = "viam_dial"] pub unsafe extern "C" fn dial( c_uri: *const c_char, c_entity: *const c_char, @@ -279,7 +279,7 @@ pub unsafe extern "C" fn dial( /// The function must not be called more than once with the same pointer /// # Arguments /// * `c_char` a pointer to the string returned by [`dial`] -#[no_mangle] +#[export_name = "viam_free_string"] pub unsafe extern "C" fn free_string(s: *mut c_char) { if s.is_null() { return; @@ -295,7 +295,7 @@ pub unsafe extern "C" fn free_string(s: *mut c_char) { /// The function must not be called more than once with the same pointer /// # Arguments /// * `rt_prt` a pointer to the string returned by [`init_rust_runtime`] -#[no_mangle] +#[export_name = "viam_free_rust_runtime"] pub extern "C" fn free_rust_runtime(rt_ptr: Option>) -> i32 { let mut ctx = match rt_ptr { Some(ctx) => ctx, 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) +} diff --git a/viam_rust_utils.h b/viam_rust_utils.h index 6b2c5cf..e4ed3c0 100644 --- a/viam_rust_utils.h +++ b/viam_rust_utils.h @@ -8,12 +8,12 @@ /** * The DialFfi interface, returned as a pointer by init_rust_runtime. User should keep this pointer until freeing the runtime. */ -typedef struct DialFfi DialFfi; +typedef struct viam_dial_ffi viam_dial_ffi; /** * A array-based statically sized matrix data storage. */ -typedef double ArrayStorage_f64__3__1[1][3]; +typedef double nalgebra_array_storage_f64__3__1[1][3]; /** * The most generic column-major matrix (and vector) type. @@ -140,23 +140,23 @@ typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 { * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing * starts at 0 as you would expect. */ - ArrayStorage_f64__3__1 data; + nalgebra_array_storage_f64__3__1 data; } Matrix_f64__U3__U1__ArrayStorage_f64__3__1; /** * A stack-allocated, 3-dimensional column vector. */ -typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 Vector3_f64; +typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 nalgebra_vector3_f64; -typedef struct AxisAngle { - Vector3_f64 axis; +typedef struct viam_axis_angle { + nalgebra_vector3_f64 axis; double theta; -} AxisAngle; +} viam_axis_angle; /** * A array-based statically sized matrix data storage. */ -typedef double ArrayStorage_f64__4__1[1][4]; +typedef double nalgebra_array_storage_f64__4__1[1][4]; /** * The most generic column-major matrix (and vector) type. @@ -283,30 +283,30 @@ typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 { * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing * starts at 0 as you would expect. */ - ArrayStorage_f64__4__1 data; + nalgebra_array_storage_f64__4__1 data; } Matrix_f64__U4__U1__ArrayStorage_f64__4__1; /** * A stack-allocated, 4-dimensional column vector. */ -typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 Vector4_f64; +typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 nalgebra_vector4_f64; /** * A quaternion. See the type alias `UnitQuaternion = Unit` for a quaternion * that may be used as a rotation. */ -typedef struct Quaternion_f64 { +typedef struct nalgebra_quaternion_f64 { /** * This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. */ - Vector4_f64 coords; -} Quaternion_f64; + nalgebra_vector4_f64 coords; +} nalgebra_quaternion_f64; -typedef struct EulerAngles { +typedef struct viam_euler_angles { double roll; double pitch; double yaw; -} EulerAngles; +} viam_euler_angles; /** * A wrapper that ensures the underlying algebraic entity has a unit norm. @@ -325,17 +325,17 @@ typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 Unit_Matrix_f64__U3__U /** * A stack-allocated, 3-dimensional unit vector. */ -typedef Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1 UnitVector3_f64; +typedef Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1 nalgebra_unit_vector3_f64; -typedef struct OrientationVector { - UnitVector3_f64 o_vector; +typedef struct viam_orientation_vector { + nalgebra_unit_vector3_f64 o_vector; double theta; -} OrientationVector; +} viam_orientation_vector; /** * A array-based statically sized matrix data storage. */ -typedef double ArrayStorage_f64__3__3[3][3]; +typedef double nalgebra_array_storage_f64__3__3[3][3]; /** * The most generic column-major matrix (and vector) type. @@ -462,7 +462,7 @@ typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 { * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing * starts at 0 as you would expect. */ - ArrayStorage_f64__3__3 data; + nalgebra_array_storage_f64__3__3 data; } Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3; /** @@ -470,7 +470,7 @@ typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 { * * **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** */ -typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 SMatrix_f64__3__3; +typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 nalgebra_smatrix_f64_3_3; /** * A rotation matrix. @@ -505,16 +505,16 @@ typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 SMatri * * [Conversion to a matrix `matrix`, `to_homogeneous`…](#conversion-to-a-matrix) * */ -typedef struct Rotation_f64__3 { - SMatrix_f64__3__3 matrix; -} Rotation_f64__3; +typedef struct nalgebra_rotation_f64_3 { + nalgebra_smatrix_f64_3_3 matrix; +} nalgebra_rotation_f64_3; /** * A 3-dimensional rotation matrix. * * **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** */ -typedef struct Rotation_f64__3 Rotation3_f64; +typedef struct nalgebra_rotation_f64_3 nalgebra_rotation3_f64; #ifdef __cplusplus extern "C" { @@ -524,7 +524,7 @@ extern "C" { * 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`] */ -struct DialFfi *init_rust_runtime(void); +struct viam_dial_ffi *viam_init_rust_runtime(void); /** * Returns a path to a proxy to a robot @@ -541,13 +541,13 @@ struct DialFfi *init_rust_runtime(void); * * `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 */ -char *dial(const char *c_uri, - const char *c_entity, - const char *c_type, - const char *c_payload, - bool c_allow_insec, - float c_timeout, - struct DialFfi *rt_ptr); +char *viam_dial(const char *c_uri, + const char *c_entity, + const char *c_type, + const char *c_payload, + bool c_allow_insec, + float c_timeout, + struct viam_dial_ffi *rt_ptr); /** * This function must be used to free the path returned by the [`dial`] function @@ -557,7 +557,7 @@ char *dial(const char *c_uri, * # Arguments * * `c_char` a pointer to the string returned by [`dial`] */ -void free_string(char *s); +void viam_free_string(char *s); /** * This function must be used the free a rust runtime returned by [`init_rust_runtime`] the function will signal any @@ -568,7 +568,7 @@ void free_string(char *s); * # Arguments * * `rt_prt` a pointer to the string returned by [`init_rust_runtime`] */ -int32_t free_rust_runtime(struct DialFfi *rt_ptr); +int32_t viam_free_rust_runtime(struct viam_dial_ffi *rt_ptr); /** * Free memory at the address of the axis angle pointer. @@ -578,7 +578,10 @@ int32_t free_rust_runtime(struct DialFfi *rt_ptr); * Outer processes that work with axis angles via the FFI interface MUST remember * to call this function when finished with an axis angle instance */ -void free_axis_angles_memory(struct AxisAngle *ptr); +void viam_free_axis_angles_memory(struct viam_axis_angle *ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void free_axis_angles_memory(struct viam_axis_angle *ptr); /** * Initialize axis angle from raw components and retrieve the C pointer @@ -590,7 +593,13 @@ void free_axis_angles_memory(struct AxisAngle *ptr); * the caller must remember to free the axis angle memory using the * free_axis_angles_memory FFI function */ -struct AxisAngle *new_axis_angle(double x, double y, double z, double theta); +struct viam_axis_angle *viam_new_axis_angle(double x, double y, double z, double theta); + +/// @deprecated please use `viam_`-prefixed function instead +struct viam_axis_angle *new_axis_angle(double x, + double y, + double z, + double theta); /** * Converts a quaternion into an R4 axis angle. The return value is a pointer @@ -606,7 +615,10 @@ struct AxisAngle *new_axis_angle(double x, double y, double z, double theta); * free_quaternion_memory FFI function and the axis angle memory using * the free_array_memory function */ -struct AxisAngle *axis_angle_from_quaternion(const struct Quaternion_f64 *quat); +struct viam_axis_angle *viam_axis_angle_from_quaternion(const struct nalgebra_quaternion_f64 *quat); + +/// @deprecated please use `viam_`-prefixed function instead +struct viam_axis_angle *axis_angle_from_quaternion(const struct nalgebra_quaternion_f64 *quat); /** * Free memory at the address of the euler angles pointer. @@ -616,7 +628,10 @@ struct AxisAngle *axis_angle_from_quaternion(const struct Quaternion_f64 *quat); * Outer processes that work with EulerAngles via the FFI interface MUST remember * to call this function when finished with a euler angles instance */ -void free_euler_angles_memory(struct EulerAngles *ptr); +void viam_free_euler_angles_memory(struct viam_euler_angles *ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void free_euler_angles_memory(struct viam_euler_angles *ptr); /** * Initialize euler angles from raw components and retrieve the C pointer @@ -628,7 +643,12 @@ void free_euler_angles_memory(struct EulerAngles *ptr); * the caller must remember to free the euler angles memory using the * free_euler_angles_memory FFI function */ -struct EulerAngles *new_euler_angles(double roll, double pitch, double yaw); +struct viam_euler_angles *viam_new_euler_angles(double roll, double pitch, double yaw); + +/// @deprecated please use `viam_`-prefixed function instead +struct viam_euler_angles *new_euler_angles(double roll, + double pitch, + double yaw); /** * Converts a quaternion into euler angles (in radians). The euler angles are @@ -642,7 +662,10 @@ struct EulerAngles *new_euler_angles(double roll, double pitch, double yaw); * free_quaternion_memory FFI function and the euler angles memory using * the free_euler_angles_memory function */ -struct EulerAngles *euler_angles_from_quaternion(const struct Quaternion_f64 *quat_ptr); +struct viam_euler_angles *viam_euler_angles_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct viam_euler_angles *euler_angles_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); /** * Free memory at the address of the orientation vector pointer. Outer processes @@ -651,7 +674,10 @@ struct EulerAngles *euler_angles_from_quaternion(const struct Quaternion_f64 *qu * * # Safety */ -void free_orientation_vector_memory(struct OrientationVector *ptr); +void viam_free_orientation_vector_memory(struct viam_orientation_vector *ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void free_orientation_vector_memory(struct viam_orientation_vector *ptr); /** * Initialize an orientation vector from raw components and retrieve the C pointer @@ -663,7 +689,16 @@ void free_orientation_vector_memory(struct OrientationVector *ptr); * the caller must remember to free the orientation vector memory using the * free_orientation_vector_memory FFI function */ -struct OrientationVector *new_orientation_vector(double o_x, double o_y, double o_z, double theta); +struct viam_orientation_vector *viam_new_orientation_vector(double o_x, + double o_y, + double o_z, + double theta); + +/// @deprecated please use `viam_`-prefixed function instead +struct viam_orientation_vector *new_orientation_vector(double o_x, + double o_y, + double o_z, + double theta); /** * Get the components of an orientation vector as a list of C doubles, the order of the @@ -675,7 +710,10 @@ struct OrientationVector *new_orientation_vector(double o_x, double o_y, double * the caller must remember to free the orientation_vector memory using the * free_orientation_vector_memory FFI function */ -const double *orientation_vector_get_components(const struct OrientationVector *ov_ptr); +const double *viam_orientation_vector_get_components(const struct viam_orientation_vector *ov_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +const double *orientation_vector_get_components(const struct viam_orientation_vector *ov_ptr); /** * Converts a quaternion into an orientation vector. @@ -687,7 +725,10 @@ const double *orientation_vector_get_components(const struct OrientationVector * * free_quaternion_memory FFI function and the orientation-vector memory using * the free_orientation_vector_memory function */ -struct OrientationVector *orientation_vector_from_quaternion(const struct Quaternion_f64 *quat_ptr); +struct viam_orientation_vector *viam_orientation_vector_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct viam_orientation_vector *orientation_vector_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); /** * Free memory of an array of orientation vector components at the given address. @@ -697,6 +738,9 @@ struct OrientationVector *orientation_vector_from_quaternion(const struct Quater * Outer processes that request the components of a orientation vector should call this function * to free the memory allocated to the array once finished */ +void viam_free_orientation_vector_components(double *ptr); + +/// @deprecated please use `viam_`-prefixed function instead void free_orientation_vector_components(double *ptr); /** @@ -709,7 +753,13 @@ void free_orientation_vector_components(double *ptr); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -struct Quaternion_f64 *new_quaternion(double real, double i, double j, double k); +struct nalgebra_quaternion_f64 *viam_new_quaternion(double real, double i, double j, double k); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *new_quaternion(double real, + double i, + double j, + double k); /** * Initialize a quaternion from a real part and a C pointer to a Vector3 @@ -721,7 +771,12 @@ struct Quaternion_f64 *new_quaternion(double real, double i, double j, double k) * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -struct Quaternion_f64 *new_quaternion_from_vector(double real, const Vector3_f64 *imag_ptr); +struct nalgebra_quaternion_f64 *viam_new_quaternion_from_vector(double real, + const nalgebra_vector3_f64 *imag_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *new_quaternion_from_vector(double real, + const nalgebra_vector3_f64 *imag_ptr); /** * Free memory at the address of the quaternion pointer. @@ -731,7 +786,10 @@ struct Quaternion_f64 *new_quaternion_from_vector(double real, const Vector3_f64 * Outer processes that work with Quaternions via the FFI interface MUST remember * to call this function when finished with a quaternion */ -void free_quaternion_memory(struct Quaternion_f64 *ptr); +void viam_free_quaternion_memory(struct nalgebra_quaternion_f64 *ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void free_quaternion_memory(struct nalgebra_quaternion_f64 *ptr); /** * Get the components of a quaternion as a list of C doubles, the order of the @@ -743,7 +801,10 @@ void free_quaternion_memory(struct Quaternion_f64 *ptr); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -const double *quaternion_get_components(const struct Quaternion_f64 *quat_ptr); +const double *viam_quaternion_get_components(const struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +const double *quaternion_get_components(const struct nalgebra_quaternion_f64 *quat_ptr); /** * Set the real component of an existing quaternion stored at the address @@ -755,7 +816,11 @@ const double *quaternion_get_components(const struct Quaternion_f64 *quat_ptr); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void quaternion_set_real(struct Quaternion_f64 *quat_ptr, double real); +void viam_quaternion_set_real(struct nalgebra_quaternion_f64 *quat_ptr, double real); + +/// @deprecated please use `viam_`-prefixed function instead +void quaternion_set_real(struct nalgebra_quaternion_f64 *quat_ptr, + double real); /** * Set the i component of an existing quaternion stored at the address @@ -767,7 +832,11 @@ void quaternion_set_real(struct Quaternion_f64 *quat_ptr, double real); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void quaternion_set_i(struct Quaternion_f64 *quat_ptr, double i); +void viam_quaternion_set_i(struct nalgebra_quaternion_f64 *quat_ptr, double i); + +/// @deprecated please use `viam_`-prefixed function instead +void quaternion_set_i(struct nalgebra_quaternion_f64 *quat_ptr, + double i); /** * Set the j component of an existing quaternion stored at the address @@ -779,7 +848,11 @@ void quaternion_set_i(struct Quaternion_f64 *quat_ptr, double i); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void quaternion_set_j(struct Quaternion_f64 *quat_ptr, double j); +void viam_quaternion_set_j(struct nalgebra_quaternion_f64 *quat_ptr, double j); + +/// @deprecated please use `viam_`-prefixed function instead +void quaternion_set_j(struct nalgebra_quaternion_f64 *quat_ptr, + double j); /** * Set the k component of an existing quaternion stored at the address @@ -791,7 +864,11 @@ void quaternion_set_j(struct Quaternion_f64 *quat_ptr, double j); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void quaternion_set_k(struct Quaternion_f64 *quat_ptr, double k); +void viam_quaternion_set_k(struct nalgebra_quaternion_f64 *quat_ptr, double k); + +/// @deprecated please use `viam_`-prefixed function instead +void quaternion_set_k(struct nalgebra_quaternion_f64 *quat_ptr, + double k); /** * Set all of the components of an existing quaternion stored at the address @@ -803,7 +880,14 @@ void quaternion_set_k(struct Quaternion_f64 *quat_ptr, double k); * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void quaternion_set_components(struct Quaternion_f64 *quat_ptr, +void viam_quaternion_set_components(struct nalgebra_quaternion_f64 *quat_ptr, + double real, + double i, + double j, + double k); + +/// @deprecated please use `viam_`-prefixed function instead +void quaternion_set_components(struct nalgebra_quaternion_f64 *quat_ptr, double real, double i, double j, @@ -821,7 +905,12 @@ void quaternion_set_components(struct Quaternion_f64 *quat_ptr, * free_quaternion_memory FFI function (the same applies for the vector * stored at vec_ptr) */ -void quaternion_set_imag_from_vector(struct Quaternion_f64 *quat_ptr, const Vector3_f64 *vec_ptr); +void viam_quaternion_set_imag_from_vector(struct nalgebra_quaternion_f64 *quat_ptr, + const nalgebra_vector3_f64 *vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void quaternion_set_imag_from_vector(struct nalgebra_quaternion_f64 *quat_ptr, + const nalgebra_vector3_f64 *vec_ptr); /** * Copies the imaginary components to a 3-vector (using x -> i, y -> j @@ -834,7 +923,10 @@ void quaternion_set_imag_from_vector(struct Quaternion_f64 *quat_ptr, const Vect * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -Vector3_f64 *quaternion_get_imaginary_vector(const struct Quaternion_f64 *quat_ptr); +nalgebra_vector3_f64 *viam_quaternion_get_imaginary_vector(const struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *quaternion_get_imaginary_vector(const struct nalgebra_quaternion_f64 *quat_ptr); /** * Normalizes an existing quaternion stored at the address of @@ -846,7 +938,10 @@ Vector3_f64 *quaternion_get_imaginary_vector(const struct Quaternion_f64 *quat_p * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void normalize_quaternion(struct Quaternion_f64 *quat_ptr); +void viam_normalize_quaternion(struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void normalize_quaternion(struct nalgebra_quaternion_f64 *quat_ptr); /** * Initializes a normalized copy of a quaternion stored at the @@ -859,7 +954,10 @@ void normalize_quaternion(struct Quaternion_f64 *quat_ptr); * *both* the input and output quaternions when finished with them * using the free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_get_normalized(const struct Quaternion_f64 *quat_ptr); +struct nalgebra_quaternion_f64 *viam_quaternion_get_normalized(const struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_get_normalized(const struct nalgebra_quaternion_f64 *quat_ptr); /** * Returns the result of rotating a vector by a quaternion @@ -870,8 +968,12 @@ struct Quaternion_f64 *quaternion_get_normalized(const struct Quaternion_f64 *qu * the memory of both vectors when finished with them using the * free_quaternion_memory and free_vector_memory FFI functions */ -Vector3_f64 *quaternion_rotate_vector(const struct Quaternion_f64 *quat_ptr, - const Vector3_f64 *vec_ptr); +nalgebra_vector3_f64 *viam_quaternion_rotate_vector(const struct nalgebra_quaternion_f64 *quat_ptr, + const nalgebra_vector3_f64 *vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *quaternion_rotate_vector(const struct nalgebra_quaternion_f64 *quat_ptr, + const nalgebra_vector3_f64 *vec_ptr); /** * Converts from euler angles (in radians) to a quaternion. The euler angles are expected to @@ -884,7 +986,14 @@ Vector3_f64 *quaternion_rotate_vector(const struct Quaternion_f64 *quat_ptr, * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_from_euler_angles(double roll, double pitch, double yaw); +struct nalgebra_quaternion_f64 *viam_quaternion_from_euler_angles(double roll, + double pitch, + double yaw); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_from_euler_angles(double roll, + double pitch, + double yaw); /** * Converts from an axis angle given by a vector's x, y, z components @@ -896,7 +1005,16 @@ struct Quaternion_f64 *quaternion_from_euler_angles(double roll, double pitch, d * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_from_axis_angle(double x, double y, double z, double theta); +struct nalgebra_quaternion_f64 *viam_quaternion_from_axis_angle(double x, + double y, + double z, + double theta); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_from_axis_angle(double x, + double y, + double z, + double theta); /** * Converts from an axis angle whose vector is given by a pointer @@ -910,8 +1028,12 @@ struct Quaternion_f64 *quaternion_from_axis_angle(double x, double y, double z, * free_quaternion_memory FFI function. Similarly the free_vector_memory should * be called when finished with the axis angle vector */ -struct Quaternion_f64 *quaternion_from_axis_angle_vector(double theta, - const Vector3_f64 *axis_angle_vec_ptr); +struct nalgebra_quaternion_f64 *viam_quaternion_from_axis_angle_vector(double theta, + const nalgebra_vector3_f64 *axis_angle_vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_from_axis_angle_vector(double theta, + const nalgebra_vector3_f64 *axis_angle_vec_ptr); /** * Converts from a pointer to a Rotation3 to a quaternion @@ -922,7 +1044,10 @@ struct Quaternion_f64 *quaternion_from_axis_angle_vector(double theta, * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_from_rotation_matrix(const Rotation3_f64 *rot_ptr); +struct nalgebra_quaternion_f64 *viam_quaternion_from_rotation_matrix(const nalgebra_rotation3_f64 *rot_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_from_rotation_matrix(const nalgebra_rotation3_f64 *rot_ptr); /** * Converts from a pointer to an OrientationVector to a quaternion @@ -933,7 +1058,10 @@ struct Quaternion_f64 *quaternion_from_rotation_matrix(const Rotation3_f64 *rot_ * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_from_orientation_vector(const struct OrientationVector *o_vec_ptr); +struct nalgebra_quaternion_f64 *viam_quaternion_from_orientation_vector(const struct viam_orientation_vector *o_vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_from_orientation_vector(const struct viam_orientation_vector *o_vec_ptr); /** * Scales an existing quaternion stored at the address of @@ -945,7 +1073,11 @@ struct Quaternion_f64 *quaternion_from_orientation_vector(const struct Orientati * the caller must remember to free the quaternion memory using the * free_quaternion_memory FFI function */ -void scale_quaternion(struct Quaternion_f64 *quat_ptr, double factor); +void viam_scale_quaternion(struct nalgebra_quaternion_f64 *quat_ptr, double factor); + +/// @deprecated please use `viam_`-prefixed function instead +void scale_quaternion(struct nalgebra_quaternion_f64 *quat_ptr, + double factor); /** * Initializes a copy of the quaternion stored at the address of a pointer (quat_ptr) @@ -957,7 +1089,12 @@ void scale_quaternion(struct Quaternion_f64 *quat_ptr, double factor); * *both* the input and output quaternions when finished with them * using the free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_get_scaled(const struct Quaternion_f64 *quat_ptr, double factor); +struct nalgebra_quaternion_f64 *viam_quaternion_get_scaled(const struct nalgebra_quaternion_f64 *quat_ptr, + double factor); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_get_scaled(const struct nalgebra_quaternion_f64 *quat_ptr, + double factor); /** * Initializes a quaternion that is the conjugate of one stored @@ -970,7 +1107,10 @@ struct Quaternion_f64 *quaternion_get_scaled(const struct Quaternion_f64 *quat_p * *both* the input and output quaternions when finished with them * using the free_quaternion_memory FFI function */ -struct Quaternion_f64 *quaternion_get_conjugate(const struct Quaternion_f64 *quat_ptr); +struct nalgebra_quaternion_f64 *viam_quaternion_get_conjugate(const struct nalgebra_quaternion_f64 *quat_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_get_conjugate(const struct nalgebra_quaternion_f64 *quat_ptr); /** * Adds two quaternions and returns a pointer to the @@ -981,8 +1121,12 @@ struct Quaternion_f64 *quaternion_get_conjugate(const struct Quaternion_f64 *qua * 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 */ -struct Quaternion_f64 *quaternion_add(const struct Quaternion_f64 *quat_ptr_1, - const struct Quaternion_f64 *quat_ptr_2); +struct nalgebra_quaternion_f64 *viam_quaternion_add(const struct nalgebra_quaternion_f64 *quat_ptr_1, + const struct nalgebra_quaternion_f64 *quat_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_add(const struct nalgebra_quaternion_f64 *quat_ptr_1, + const struct nalgebra_quaternion_f64 *quat_ptr_2); /** * Subtracts two quaternions and returns a pointer to the @@ -993,8 +1137,12 @@ struct Quaternion_f64 *quaternion_add(const struct Quaternion_f64 *quat_ptr_1, * 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 */ -struct Quaternion_f64 *quaternion_subtract(const struct Quaternion_f64 *quat_ptr_1, - const struct Quaternion_f64 *quat_ptr_2); +struct nalgebra_quaternion_f64 *viam_quaternion_subtract(const struct nalgebra_quaternion_f64 *quat_ptr_1, + const struct nalgebra_quaternion_f64 *quat_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_subtract(const struct nalgebra_quaternion_f64 *quat_ptr_1, + const struct nalgebra_quaternion_f64 *quat_ptr_2); /** * Computes the Hamiltonian product of two quaternions and @@ -1005,8 +1153,12 @@ struct Quaternion_f64 *quaternion_subtract(const struct Quaternion_f64 *quat_ptr * 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 */ -struct Quaternion_f64 *quaternion_hamiltonian_product(const struct Quaternion_f64 *quat_ptr_1, - const struct Quaternion_f64 *quat_ptr_2); +struct nalgebra_quaternion_f64 *viam_quaternion_hamiltonian_product(const struct nalgebra_quaternion_f64 *quat_ptr_1, + const struct nalgebra_quaternion_f64 *quat_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +struct nalgebra_quaternion_f64 *quaternion_hamiltonian_product(const struct nalgebra_quaternion_f64 *quat_ptr_1, + const struct nalgebra_quaternion_f64 *quat_ptr_2); /** * Free memory of an array of quaternion components at the given address. @@ -1016,6 +1168,9 @@ struct Quaternion_f64 *quaternion_hamiltonian_product(const struct Quaternion_f6 * Outer processes that request the components of a quaternion should call this function * to free the memory allocated to the array once finished */ +void viam_free_quaternion_components(double *ptr); + +/// @deprecated please use `viam_`-prefixed function instead void free_quaternion_components(double *ptr); /** @@ -1025,7 +1180,10 @@ void free_quaternion_components(double *ptr); * * # Safety */ -void free_rotation_matrix_memory(Rotation3_f64 *ptr); +void viam_free_rotation_matrix_memory(nalgebra_rotation3_f64 *ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void free_rotation_matrix_memory(nalgebra_rotation3_f64 *ptr); /** * Initialize a 3D rotation matrix from raw components and retrieve the C pointer @@ -1038,7 +1196,10 @@ void free_rotation_matrix_memory(Rotation3_f64 *ptr); * the caller must remember to free the rotation matrix memory using the * free_rotation_matrix_memory FFI function */ -Rotation3_f64 *new_rotation_matrix(const double (*elements)[9]); +nalgebra_rotation3_f64 *viam_new_rotation_matrix(const double (*elements)[9]); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_rotation3_f64 *new_rotation_matrix(const double (*elements)[9]); /** * Converts a quaternion into a 3D rotation matrix (a Rotation @@ -1051,7 +1212,10 @@ Rotation3_f64 *new_rotation_matrix(const double (*elements)[9]); * free_quaternion_memory FFI function and the rotation matrix memory using * the free_rotation_matrix_memory function */ -Rotation3_f64 *rotation_matrix_from_quaternion(const struct Quaternion_f64 *quat); +nalgebra_rotation3_f64 *viam_rotation_matrix_from_quaternion(const struct nalgebra_quaternion_f64 *quat); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_rotation3_f64 *rotation_matrix_from_quaternion(const struct nalgebra_quaternion_f64 *quat); /** * Initialize a 3-vector from raw components and retrieve the C pointer @@ -1063,7 +1227,12 @@ Rotation3_f64 *rotation_matrix_from_quaternion(const struct Quaternion_f64 *quat * the caller must remember to free the vector memory using the * free_vector_memory FFI function */ -Vector3_f64 *new_vector3(double x, double y, double z); +nalgebra_vector3_f64 *viam_new_vector3(double x, double y, double z); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *new_vector3(double x, + double y, + double z); /** * Free memory at the address of the vector pointer. @@ -1072,7 +1241,10 @@ Vector3_f64 *new_vector3(double x, double y, double z); * Outer processes that work with Vectors via the FFI interface MUST remember * to call this function when finished with a vector */ -void free_vector_memory(Vector3_f64 *ptr); +void viam_free_vector_memory(nalgebra_vector3_f64 *ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void free_vector_memory(nalgebra_vector3_f64 *ptr); /** * Get the components of a vector as a list of C doubles, the order of the @@ -1083,7 +1255,10 @@ void free_vector_memory(Vector3_f64 *ptr); * When finished with the underlying vector, the caller must remember to * free the vector memory using the free_vector_memory FFI function */ -const double *vector_get_components(const Vector3_f64 *vec_ptr); +const double *viam_vector_get_components(const nalgebra_vector3_f64 *vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +const double *vector_get_components(const nalgebra_vector3_f64 *vec_ptr); /** * Set the x component of an existing vector stored at the address @@ -1094,7 +1269,11 @@ const double *vector_get_components(const Vector3_f64 *vec_ptr); * When finished with the underlying vector, the caller must remember to * free the vector memory using the free_vector_memory FFI function */ -void vector_set_x(Vector3_f64 *vec_ptr, double x_val); +void viam_vector_set_x(nalgebra_vector3_f64 *vec_ptr, double x_val); + +/// @deprecated please use `viam_`-prefixed function instead +void vector_set_x(nalgebra_vector3_f64 *vec_ptr, + double x_val); /** * Set the y component of an existing vector stored at the address @@ -1105,7 +1284,11 @@ void vector_set_x(Vector3_f64 *vec_ptr, double x_val); * When finished with the underlying vector, the caller must remember to * free the vector memory using the free_vector_memory FFI function */ -void vector_set_y(Vector3_f64 *vec_ptr, double y_val); +void viam_vector_set_y(nalgebra_vector3_f64 *vec_ptr, double y_val); + +/// @deprecated please use `viam_`-prefixed function instead +void vector_set_y(nalgebra_vector3_f64 *vec_ptr, + double y_val); /** * Set the z component of an existing vector stored at the address @@ -1116,7 +1299,11 @@ void vector_set_y(Vector3_f64 *vec_ptr, double y_val); * When finished with the underlying vector, the caller must remember to * free the vector memory using the free_vector_memory FFI function */ -void vector_set_z(Vector3_f64 *vec_ptr, double z_val); +void viam_vector_set_z(nalgebra_vector3_f64 *vec_ptr, double z_val); + +/// @deprecated please use `viam_`-prefixed function instead +void vector_set_z(nalgebra_vector3_f64 *vec_ptr, + double z_val); /** * Normalizes an existing vector stored at the address of @@ -1127,7 +1314,10 @@ void vector_set_z(Vector3_f64 *vec_ptr, double z_val); * When finished with the underlying vector, the caller must remember to * free the vector memory using the free_vector_memory FFI function */ -void normalize_vector(Vector3_f64 *vec_ptr); +void viam_normalize_vector(nalgebra_vector3_f64 *vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +void normalize_vector(nalgebra_vector3_f64 *vec_ptr); /** * Initializes a normalized copy of a vector stored at the @@ -1139,7 +1329,10 @@ void normalize_vector(Vector3_f64 *vec_ptr); * 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 */ -Vector3_f64 *vector_get_normalized(const Vector3_f64 *vec_ptr); +nalgebra_vector3_f64 *viam_vector_get_normalized(const nalgebra_vector3_f64 *vec_ptr); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *vector_get_normalized(const nalgebra_vector3_f64 *vec_ptr); /** * Scales an existing vector stored at the address of @@ -1150,7 +1343,11 @@ Vector3_f64 *vector_get_normalized(const Vector3_f64 *vec_ptr); * When finished with the underlying vector, the caller must remember to * free the vector memory using the free_vector_memory FFI function */ -void scale_vector(Vector3_f64 *vec_ptr, double factor); +void viam_scale_vector(nalgebra_vector3_f64 *vec_ptr, double factor); + +/// @deprecated please use `viam_`-prefixed function instead +void scale_vector(nalgebra_vector3_f64 *vec_ptr, + double factor); /** * Initializes a scaled copy of a vector stored at the @@ -1162,7 +1359,11 @@ void scale_vector(Vector3_f64 *vec_ptr, double factor); * 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 */ -Vector3_f64 *vector_get_scaled(const Vector3_f64 *vec_ptr, double factor); +nalgebra_vector3_f64 *viam_vector_get_scaled(const nalgebra_vector3_f64 *vec_ptr, double factor); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *vector_get_scaled(const nalgebra_vector3_f64 *vec_ptr, + double factor); /** * Adds two vectors and returns a pointer to the @@ -1173,7 +1374,12 @@ Vector3_f64 *vector_get_scaled(const Vector3_f64 *vec_ptr, double factor); * 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 */ -Vector3_f64 *vector_add(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr_2); +nalgebra_vector3_f64 *viam_vector_add(const nalgebra_vector3_f64 *vec_ptr_1, + const nalgebra_vector3_f64 *vec_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *vector_add(const nalgebra_vector3_f64 *vec_ptr_1, + const nalgebra_vector3_f64 *vec_ptr_2); /** * Subtracts two vectors and returns a pointer to the @@ -1184,7 +1390,12 @@ Vector3_f64 *vector_add(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr * 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 */ -Vector3_f64 *vector_subtract(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr_2); +nalgebra_vector3_f64 *viam_vector_subtract(const nalgebra_vector3_f64 *vec_ptr_1, + const nalgebra_vector3_f64 *vec_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *vector_subtract(const nalgebra_vector3_f64 *vec_ptr_1, + const nalgebra_vector3_f64 *vec_ptr_2); /** * Computes the dot product of two vectors @@ -1194,7 +1405,12 @@ Vector3_f64 *vector_subtract(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *ve * The caller must remember to free the vector memory of the input vectors * when finished with them using the free_vector_memory FFI function */ -double vector_dot_product(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_ptr_2); +double viam_vector_dot_product(const nalgebra_vector3_f64 *vec_ptr_1, + const nalgebra_vector3_f64 *vec_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +double vector_dot_product(const nalgebra_vector3_f64 *vec_ptr_1, + const nalgebra_vector3_f64 *vec_ptr_2); /** * Computes the cross product of two vectors and returns @@ -1205,7 +1421,12 @@ double vector_dot_product(const Vector3_f64 *vec_ptr_1, const Vector3_f64 *vec_p * 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 */ -Vector3_f64 *vector_cross_product(Vector3_f64 *vec_ptr_1, Vector3_f64 *vec_ptr_2); +nalgebra_vector3_f64 *viam_vector_cross_product(nalgebra_vector3_f64 *vec_ptr_1, + nalgebra_vector3_f64 *vec_ptr_2); + +/// @deprecated please use `viam_`-prefixed function instead +nalgebra_vector3_f64 *vector_cross_product(nalgebra_vector3_f64 *vec_ptr_1, + nalgebra_vector3_f64 *vec_ptr_2); /** * Free memory of an array of vector components at the given address. @@ -1215,6 +1436,9 @@ Vector3_f64 *vector_cross_product(Vector3_f64 *vec_ptr_1, Vector3_f64 *vec_ptr_2 * Outer processes that request the components of a vector should call this function * to free the memory allocated to the array once finished */ +void viam_free_vector_components(double *ptr); + +/// @deprecated please use `viam_`-prefixed function instead void free_vector_components(double *ptr); #ifdef __cplusplus From 6a3835893d3ed23e344ed9d68c73c35e80fd3c07 Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Wed, 12 Nov 2025 11:53:34 -0500 Subject: [PATCH 06/10] fix yml syntax --- .github/workflows/release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8581a1d..4d3758f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -240,8 +240,10 @@ jobs: create_canonical_header: needs: [builds_macos, build_linux, build_windows] runs-on: ubuntu-latest - # pick one arbitrarily as the canonical header file - run: mv builds/viam_rust_utils-macosx_arm64.h builds/viam_rust_utils.h + 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] From 9672ff949ae46b08e6a2682d3c52b3b4c8f514eb Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Wed, 12 Nov 2025 11:56:40 -0500 Subject: [PATCH 07/10] fix yml syntax2 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d3758f..ba69324 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -238,7 +238,7 @@ jobs: path: builds/* create_canonical_header: - needs: [builds_macos, build_linux, build_windows] + needs: [build_macos, build_linux, build_windows] runs-on: ubuntu-latest steps: # pick one arbitrarily as the canonical header file From d9ff50947c395c102d48b698a0a1e30cd25a5838 Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Wed, 12 Nov 2025 13:10:54 -0500 Subject: [PATCH 08/10] fix lingering mangling issues --- build.rs | 16 ++++++++-------- viam_rust_utils.h | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index 0fb91a1..18dc193 100644 --- a/build.rs +++ b/build.rs @@ -11,35 +11,35 @@ fn main() { let nalgebra_types = vec![ ("ArrayStorage_f64__3__1", "nalgebra_array_storage_f64__3__1"), ( - "Matrix_f64__u3__u1__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__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_array_storage_f64_3_1", + "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"), - ]; - - // mangled viam type outputs, mapped to a prefixed snake case variant - let viam_types = vec![ ( - "Matrix_f64__const_3__const_3__array_storage_f64_3_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"), diff --git a/viam_rust_utils.h b/viam_rust_utils.h index e4ed3c0..bca4a1b 100644 --- a/viam_rust_utils.h +++ b/viam_rust_utils.h @@ -114,7 +114,7 @@ typedef double nalgebra_array_storage_f64__3__1[1][3]; * dynamically-sized column vector should be represented as a `Matrix` (given * some concrete types for `T` and a compatible data storage type `S`). */ -typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 { +typedef struct nalgebra_matrix_f64_3_1 { /** * The data storage that contains all the matrix components. Disappointed? * @@ -141,12 +141,12 @@ typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 { * starts at 0 as you would expect. */ nalgebra_array_storage_f64__3__1 data; -} Matrix_f64__U3__U1__ArrayStorage_f64__3__1; +} nalgebra_matrix_f64_3_1; /** * A stack-allocated, 3-dimensional column vector. */ -typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 nalgebra_vector3_f64; +typedef struct nalgebra_matrix_f64_3_1 nalgebra_vector3_f64; typedef struct viam_axis_angle { nalgebra_vector3_f64 axis; @@ -257,7 +257,7 @@ typedef double nalgebra_array_storage_f64__4__1[1][4]; * dynamically-sized column vector should be represented as a `Matrix` (given * some concrete types for `T` and a compatible data storage type `S`). */ -typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 { +typedef struct nalgebra_matrix_f64_4_1 { /** * The data storage that contains all the matrix components. Disappointed? * @@ -284,12 +284,12 @@ typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 { * starts at 0 as you would expect. */ nalgebra_array_storage_f64__4__1 data; -} Matrix_f64__U4__U1__ArrayStorage_f64__4__1; +} nalgebra_matrix_f64_4_1; /** * A stack-allocated, 4-dimensional column vector. */ -typedef struct Matrix_f64__U4__U1__ArrayStorage_f64__4__1 nalgebra_vector4_f64; +typedef struct nalgebra_matrix_f64_4_1 nalgebra_vector4_f64; /** * A quaternion. See the type alias `UnitQuaternion = Unit` for a quaternion @@ -320,12 +320,12 @@ typedef struct viam_euler_angles { * and [`UnitQuaternion`](crate::UnitQuaternion); both built on top of `Unit`. If you are interested * in their documentation, read their dedicated pages directly. */ -typedef struct Matrix_f64__U3__U1__ArrayStorage_f64__3__1 Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1; +typedef struct nalgebra_matrix_f64_3_1 nalgebra_unit_matrix_f64_3_1; /** * A stack-allocated, 3-dimensional unit vector. */ -typedef Unit_Matrix_f64__U3__U1__ArrayStorage_f64__3__1 nalgebra_unit_vector3_f64; +typedef nalgebra_unit_matrix_f64_3_1 nalgebra_unit_vector3_f64; typedef struct viam_orientation_vector { nalgebra_unit_vector3_f64 o_vector; @@ -436,7 +436,7 @@ typedef double nalgebra_array_storage_f64__3__3[3][3]; * dynamically-sized column vector should be represented as a `Matrix` (given * some concrete types for `T` and a compatible data storage type `S`). */ -typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 { +typedef struct nalgebra_matrix_f64_3_3 { /** * The data storage that contains all the matrix components. Disappointed? * @@ -463,14 +463,14 @@ typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 { * starts at 0 as you would expect. */ nalgebra_array_storage_f64__3__3 data; -} Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3; +} nalgebra_matrix_f64_3_3; /** * A statically sized column-major matrix with `R` rows and `C` columns. * * **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** */ -typedef struct Matrix_f64__Const_3_____Const_3_____ArrayStorage_f64__3__3 nalgebra_smatrix_f64_3_3; +typedef struct nalgebra_matrix_f64_3_3 nalgebra_smatrix_f64_3_3; /** * A rotation matrix. From a77fea2eea2cb8a48819dcf974ce368235a5fbe1 Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Thu, 13 Nov 2025 16:11:59 -0500 Subject: [PATCH 09/10] add missing deprecated methods --- src/ffi/dial_ffi.rs | 56 ++++++++++++++++++++++++++++++++++++++------- viam_rust_utils.h | 17 ++++++++++++++ 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/ffi/dial_ffi.rs b/src/ffi/dial_ffi.rs index 7ce263e..762b8e5 100644 --- a/src/ffi/dial_ffi.rs +++ b/src/ffi/dial_ffi.rs @@ -65,12 +65,18 @@ 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`] -#[export_name = "viam_init_rust_runtime"] -pub extern "C" fn init_rust_runtime() -> Box { +#[no_mangle] +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, @@ -118,8 +124,8 @@ fn dial_with_cred( /// * `c_allow_insecure` a bool, set to true when allowing insecure connection to your robot /// * `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 -#[export_name = "viam_dial"] -pub unsafe extern "C" fn dial( +#[no_mangle] +pub unsafe extern "C" fn viam_dial( c_uri: *const c_char, c_entity: *const c_char, c_type: *const c_char, @@ -273,14 +279,36 @@ 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 /// /// The function must not be called more than once with the same pointer /// # Arguments /// * `c_char` a pointer to the string returned by [`dial`] -#[export_name = "viam_free_string"] -pub unsafe extern "C" fn free_string(s: *mut c_char) { +#[no_mangle] +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 @@ -295,8 +329,8 @@ pub unsafe extern "C" fn free_string(s: *mut c_char) { /// The function must not be called more than once with the same pointer /// # Arguments /// * `rt_prt` a pointer to the string returned by [`init_rust_runtime`] -#[export_name = "viam_free_rust_runtime"] -pub extern "C" fn free_rust_runtime(rt_ptr: Option>) -> i32 { +#[no_mangle] +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/viam_rust_utils.h b/viam_rust_utils.h index bca4a1b..68a41b7 100644 --- a/viam_rust_utils.h +++ b/viam_rust_utils.h @@ -526,6 +526,9 @@ extern "C" { */ struct viam_dial_ffi *viam_init_rust_runtime(void); +/// @deprecated please use `viam_`-prefixed function instead +struct viam_dial_ffi *init_rust_runtime(void); + /** * Returns a path to a proxy to a robot * # Safety @@ -549,6 +552,15 @@ char *viam_dial(const char *c_uri, float c_timeout, struct viam_dial_ffi *rt_ptr); +/// @deprecated please use `viam_`-prefixed function instead +char *dial(const char *c_uri, + const char *c_entity, + const char *c_type, + const char *c_payload, + bool c_allow_insec, + float c_timeout, + struct viam_dial_ffi *rt_ptr); + /** * This function must be used to free the path returned by the [`dial`] function * # Safety @@ -559,6 +571,8 @@ char *viam_dial(const char *c_uri, */ void viam_free_string(char *s); +/// @deprecated please use `viam_`-prefixed function instead void free_string(char *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. @@ -570,6 +584,9 @@ void viam_free_string(char *s); */ int32_t viam_free_rust_runtime(struct viam_dial_ffi *rt_ptr); +/// @deprecated please use `viam_`-prefixed function instead +int32_t free_rust_runtime(struct viam_dial_ffi *rt_ptr); + /** * Free memory at the address of the axis angle pointer. * From 45399dfc8fed2a4274b861b20cf6414b4ae9446e Mon Sep 17 00:00:00 2001 From: Ethan Rodkin Date: Thu, 13 Nov 2025 16:13:22 -0500 Subject: [PATCH 10/10] remove and gitignore viam_rust_utils.h --- .gitignore | 2 + viam_rust_utils.h | 1463 --------------------------------------------- 2 files changed, 2 insertions(+), 1463 deletions(-) delete mode 100644 viam_rust_utils.h 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/viam_rust_utils.h b/viam_rust_utils.h deleted file mode 100644 index 68a41b7..0000000 --- a/viam_rust_utils.h +++ /dev/null @@ -1,1463 +0,0 @@ -/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ - -#include -#include -#include -#include - -/** - * The DialFfi interface, returned as a pointer by init_rust_runtime. User should keep this pointer until freeing the runtime. - */ -typedef struct viam_dial_ffi viam_dial_ffi; - -/** - * A array-based statically sized matrix data storage. - */ -typedef double nalgebra_array_storage_f64__3__1[1][3]; - -/** - * The most generic column-major matrix (and vector) type. - * - * # Methods summary - * Because `Matrix` is the most generic types used as a common representation of all matrices and - * vectors of **nalgebra** this documentation page contains every single matrix/vector-related - * method. In order to make browsing this page simpler, the next subsections contain direct links - * to groups of methods related to a specific topic. - * - * #### Vector and matrix construction - * - [Constructors of statically-sized vectors or statically-sized matrices](#constructors-of-statically-sized-vectors-or-statically-sized-matrices) - * (`Vector3`, `Matrix3x6`…) - * - [Constructors of fully dynamic matrices](#constructors-of-fully-dynamic-matrices) (`DMatrix`) - * - [Constructors of dynamic vectors and matrices with a dynamic number of rows](#constructors-of-dynamic-vectors-and-matrices-with-a-dynamic-number-of-rows) - * (`DVector`, `MatrixXx3`…) - * - [Constructors of matrices with a dynamic number of columns](#constructors-of-matrices-with-a-dynamic-number-of-columns) - * (`Matrix2xX`…) - * - [Generic constructors](#generic-constructors) - * (For code generic wrt. the vectors or matrices dimensions.) - * - * #### Computer graphics utilities for transformations - * - [2D transformations as a Matrix3 `new_rotation`…](#2d-transformations-as-a-matrix3) - * - [3D transformations as a Matrix4 `new_rotation`, `new_perspective`, `look_at_rh`…](#3d-transformations-as-a-matrix4) - * - [Translation and scaling in any dimension `new_scaling`, `new_translation`…](#translation-and-scaling-in-any-dimension) - * - [Append/prepend translation and scaling `append_scaling`, `prepend_translation_mut`…](#appendprepend-translation-and-scaling) - * - [Transformation of vectors and points `transform_vector`, `transform_point`…](#transformation-of-vectors-and-points) - * - * #### Common math operations - * - [Componentwise operations `component_mul`, `component_div`, `inf`…](#componentwise-operations) - * - [Special multiplications `tr_mul`, `ad_mul`, `kronecker`…](#special-multiplications) - * - [Dot/scalar product `dot`, `dotc`, `tr_dot`…](#dotscalar-product) - * - [Cross product `cross`, `perp`…](#cross-product) - * - [Magnitude and norms `norm`, `normalize`, `metric_distance`…](#magnitude-and-norms) - * - [In-place normalization `normalize_mut`, `try_normalize_mut`…](#in-place-normalization) - * - [Interpolation `lerp`, `slerp`…](#interpolation) - * - [BLAS functions `gemv`, `gemm`, `syger`…](#blas-functions) - * - [Swizzling `xx`, `yxz`…](#swizzling) - * - [Triangular matrix extraction `upper_triangle`, `lower_triangle`](#triangular-matrix-extraction) - * - * #### Statistics - * - [Common operations `row_sum`, `column_mean`, `variance`…](#common-statistics-operations) - * - [Find the min and max components `min`, `max`, `amin`, `amax`, `camin`, `cmax`…](#find-the-min-and-max-components) - * - [Find the min and max components (vector-specific methods) `argmin`, `argmax`, `icamin`, `icamax`…](#find-the-min-and-max-components-vector-specific-methods) - * - * #### Iteration, map, and fold - * - [Iteration on components, rows, and columns `iter`, `column_iter`…](#iteration-on-components-rows-and-columns) - * - [Elementwise mapping and folding `map`, `fold`, `zip_map`…](#elementwise-mapping-and-folding) - * - [Folding or columns and rows `compress_rows`, `compress_columns`…](#folding-on-columns-and-rows) - * - * #### Vector and matrix slicing - * - [Creating matrix slices from `&[T]` `from_slice`, `from_slice_with_strides`…](#creating-matrix-slices-from-t) - * - [Creating mutable matrix slices from `&mut [T]` `from_slice_mut`, `from_slice_with_strides_mut`…](#creating-mutable-matrix-slices-from-mut-t) - * - [Slicing based on index and length `row`, `columns`, `slice`…](#slicing-based-on-index-and-length) - * - [Mutable slicing based on index and length `row_mut`, `columns_mut`, `slice_mut`…](#mutable-slicing-based-on-index-and-length) - * - [Slicing based on ranges `rows_range`, `columns_range`…](#slicing-based-on-ranges) - * - [Mutable slicing based on ranges `rows_range_mut`, `columns_range_mut`…](#mutable-slicing-based-on-ranges) - * - * #### In-place modification of a single matrix or vector - * - [In-place filling `fill`, `fill_diagonal`, `fill_with_identity`…](#in-place-filling) - * - [In-place swapping `swap`, `swap_columns`…](#in-place-swapping) - * - [Set rows, columns, and diagonal `set_column`, `set_diagonal`…](#set-rows-columns-and-diagonal) - * - * #### Vector and matrix size modification - * - [Rows and columns insertion `insert_row`, `insert_column`…](#rows-and-columns-insertion) - * - [Rows and columns removal `remove_row`, `remove column`…](#rows-and-columns-removal) - * - [Rows and columns extraction `select_rows`, `select_columns`…](#rows-and-columns-extraction) - * - [Resizing and reshaping `resize`, `reshape_generic`…](#resizing-and-reshaping) - * - [In-place resizing `resize_mut`, `resize_vertically_mut`…](#in-place-resizing) - * - * #### Matrix decomposition - * - [Rectangular matrix decomposition `qr`, `lu`, `svd`…](#rectangular-matrix-decomposition) - * - [Square matrix decomposition `cholesky`, `symmetric_eigen`…](#square-matrix-decomposition) - * - * #### Vector basis computation - * - [Basis and orthogonalization `orthonormal_subspace_basis`, `orthonormalize`…](#basis-and-orthogonalization) - * - * # Type parameters - * The generic `Matrix` type has four type parameters: - * - `T`: for the matrix components scalar type. - * - `R`: for the matrix number of rows. - * - `C`: for the matrix number of columns. - * - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix - * components. - * - * The matrix dimensions parameters `R` and `C` can either be: - * - type-level unsigned integer constants (e.g. `U1`, `U124`) from the `nalgebra::` root module. - * All numbers from 0 to 127 are defined that way. - * - type-level unsigned integer constants (e.g. `U1024`, `U10000`) from the `typenum::` crate. - * Using those, you will not get error messages as nice as for numbers smaller than 128 defined on - * the `nalgebra::` module. - * - the special value `Dynamic` from the `nalgebra::` root module. This indicates that the - * specified dimension is not known at compile-time. Note that this will generally imply that the - * matrix data storage `S` performs a dynamic allocation and contains extra metadata for the - * matrix shape. - * - * Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a - * dynamically-sized column vector should be represented as a `Matrix` (given - * some concrete types for `T` and a compatible data storage type `S`). - */ -typedef struct nalgebra_matrix_f64_3_1 { - /** - * The data storage that contains all the matrix components. Disappointed? - * - * Well, if you came here to see how you can access the matrix components, - * you may be in luck: you can access the individual components of all vectors with compile-time - * dimensions <= 6 using field notation like this: - * `vec.x`, `vec.y`, `vec.z`, `vec.w`, `vec.a`, `vec.b`. Reference and assignation work too: - * ``` - * # use nalgebra::Vector3; - * let mut vec = Vector3::new(1.0, 2.0, 3.0); - * vec.x = 10.0; - * vec.y += 30.0; - * assert_eq!(vec.x, 10.0); - * assert_eq!(vec.y + 100.0, 132.0); - * ``` - * Similarly, for matrices with compile-time dimensions <= 6, you can use field notation - * like this: `mat.m11`, `mat.m42`, etc. The first digit identifies the row to address - * and the second digit identifies the column to address. So `mat.m13` identifies the component - * at the first row and third column (note that the count of rows and columns start at 1 instead - * of 0 here. This is so we match the mathematical notation). - * - * For all matrices and vectors, independently from their size, individual components can - * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing - * starts at 0 as you would expect. - */ - nalgebra_array_storage_f64__3__1 data; -} nalgebra_matrix_f64_3_1; - -/** - * A stack-allocated, 3-dimensional column vector. - */ -typedef struct nalgebra_matrix_f64_3_1 nalgebra_vector3_f64; - -typedef struct viam_axis_angle { - nalgebra_vector3_f64 axis; - double theta; -} viam_axis_angle; - -/** - * A array-based statically sized matrix data storage. - */ -typedef double nalgebra_array_storage_f64__4__1[1][4]; - -/** - * The most generic column-major matrix (and vector) type. - * - * # Methods summary - * Because `Matrix` is the most generic types used as a common representation of all matrices and - * vectors of **nalgebra** this documentation page contains every single matrix/vector-related - * method. In order to make browsing this page simpler, the next subsections contain direct links - * to groups of methods related to a specific topic. - * - * #### Vector and matrix construction - * - [Constructors of statically-sized vectors or statically-sized matrices](#constructors-of-statically-sized-vectors-or-statically-sized-matrices) - * (`Vector3`, `Matrix3x6`…) - * - [Constructors of fully dynamic matrices](#constructors-of-fully-dynamic-matrices) (`DMatrix`) - * - [Constructors of dynamic vectors and matrices with a dynamic number of rows](#constructors-of-dynamic-vectors-and-matrices-with-a-dynamic-number-of-rows) - * (`DVector`, `MatrixXx3`…) - * - [Constructors of matrices with a dynamic number of columns](#constructors-of-matrices-with-a-dynamic-number-of-columns) - * (`Matrix2xX`…) - * - [Generic constructors](#generic-constructors) - * (For code generic wrt. the vectors or matrices dimensions.) - * - * #### Computer graphics utilities for transformations - * - [2D transformations as a Matrix3 `new_rotation`…](#2d-transformations-as-a-matrix3) - * - [3D transformations as a Matrix4 `new_rotation`, `new_perspective`, `look_at_rh`…](#3d-transformations-as-a-matrix4) - * - [Translation and scaling in any dimension `new_scaling`, `new_translation`…](#translation-and-scaling-in-any-dimension) - * - [Append/prepend translation and scaling `append_scaling`, `prepend_translation_mut`…](#appendprepend-translation-and-scaling) - * - [Transformation of vectors and points `transform_vector`, `transform_point`…](#transformation-of-vectors-and-points) - * - * #### Common math operations - * - [Componentwise operations `component_mul`, `component_div`, `inf`…](#componentwise-operations) - * - [Special multiplications `tr_mul`, `ad_mul`, `kronecker`…](#special-multiplications) - * - [Dot/scalar product `dot`, `dotc`, `tr_dot`…](#dotscalar-product) - * - [Cross product `cross`, `perp`…](#cross-product) - * - [Magnitude and norms `norm`, `normalize`, `metric_distance`…](#magnitude-and-norms) - * - [In-place normalization `normalize_mut`, `try_normalize_mut`…](#in-place-normalization) - * - [Interpolation `lerp`, `slerp`…](#interpolation) - * - [BLAS functions `gemv`, `gemm`, `syger`…](#blas-functions) - * - [Swizzling `xx`, `yxz`…](#swizzling) - * - [Triangular matrix extraction `upper_triangle`, `lower_triangle`](#triangular-matrix-extraction) - * - * #### Statistics - * - [Common operations `row_sum`, `column_mean`, `variance`…](#common-statistics-operations) - * - [Find the min and max components `min`, `max`, `amin`, `amax`, `camin`, `cmax`…](#find-the-min-and-max-components) - * - [Find the min and max components (vector-specific methods) `argmin`, `argmax`, `icamin`, `icamax`…](#find-the-min-and-max-components-vector-specific-methods) - * - * #### Iteration, map, and fold - * - [Iteration on components, rows, and columns `iter`, `column_iter`…](#iteration-on-components-rows-and-columns) - * - [Elementwise mapping and folding `map`, `fold`, `zip_map`…](#elementwise-mapping-and-folding) - * - [Folding or columns and rows `compress_rows`, `compress_columns`…](#folding-on-columns-and-rows) - * - * #### Vector and matrix slicing - * - [Creating matrix slices from `&[T]` `from_slice`, `from_slice_with_strides`…](#creating-matrix-slices-from-t) - * - [Creating mutable matrix slices from `&mut [T]` `from_slice_mut`, `from_slice_with_strides_mut`…](#creating-mutable-matrix-slices-from-mut-t) - * - [Slicing based on index and length `row`, `columns`, `slice`…](#slicing-based-on-index-and-length) - * - [Mutable slicing based on index and length `row_mut`, `columns_mut`, `slice_mut`…](#mutable-slicing-based-on-index-and-length) - * - [Slicing based on ranges `rows_range`, `columns_range`…](#slicing-based-on-ranges) - * - [Mutable slicing based on ranges `rows_range_mut`, `columns_range_mut`…](#mutable-slicing-based-on-ranges) - * - * #### In-place modification of a single matrix or vector - * - [In-place filling `fill`, `fill_diagonal`, `fill_with_identity`…](#in-place-filling) - * - [In-place swapping `swap`, `swap_columns`…](#in-place-swapping) - * - [Set rows, columns, and diagonal `set_column`, `set_diagonal`…](#set-rows-columns-and-diagonal) - * - * #### Vector and matrix size modification - * - [Rows and columns insertion `insert_row`, `insert_column`…](#rows-and-columns-insertion) - * - [Rows and columns removal `remove_row`, `remove column`…](#rows-and-columns-removal) - * - [Rows and columns extraction `select_rows`, `select_columns`…](#rows-and-columns-extraction) - * - [Resizing and reshaping `resize`, `reshape_generic`…](#resizing-and-reshaping) - * - [In-place resizing `resize_mut`, `resize_vertically_mut`…](#in-place-resizing) - * - * #### Matrix decomposition - * - [Rectangular matrix decomposition `qr`, `lu`, `svd`…](#rectangular-matrix-decomposition) - * - [Square matrix decomposition `cholesky`, `symmetric_eigen`…](#square-matrix-decomposition) - * - * #### Vector basis computation - * - [Basis and orthogonalization `orthonormal_subspace_basis`, `orthonormalize`…](#basis-and-orthogonalization) - * - * # Type parameters - * The generic `Matrix` type has four type parameters: - * - `T`: for the matrix components scalar type. - * - `R`: for the matrix number of rows. - * - `C`: for the matrix number of columns. - * - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix - * components. - * - * The matrix dimensions parameters `R` and `C` can either be: - * - type-level unsigned integer constants (e.g. `U1`, `U124`) from the `nalgebra::` root module. - * All numbers from 0 to 127 are defined that way. - * - type-level unsigned integer constants (e.g. `U1024`, `U10000`) from the `typenum::` crate. - * Using those, you will not get error messages as nice as for numbers smaller than 128 defined on - * the `nalgebra::` module. - * - the special value `Dynamic` from the `nalgebra::` root module. This indicates that the - * specified dimension is not known at compile-time. Note that this will generally imply that the - * matrix data storage `S` performs a dynamic allocation and contains extra metadata for the - * matrix shape. - * - * Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a - * dynamically-sized column vector should be represented as a `Matrix` (given - * some concrete types for `T` and a compatible data storage type `S`). - */ -typedef struct nalgebra_matrix_f64_4_1 { - /** - * The data storage that contains all the matrix components. Disappointed? - * - * Well, if you came here to see how you can access the matrix components, - * you may be in luck: you can access the individual components of all vectors with compile-time - * dimensions <= 6 using field notation like this: - * `vec.x`, `vec.y`, `vec.z`, `vec.w`, `vec.a`, `vec.b`. Reference and assignation work too: - * ``` - * # use nalgebra::Vector3; - * let mut vec = Vector3::new(1.0, 2.0, 3.0); - * vec.x = 10.0; - * vec.y += 30.0; - * assert_eq!(vec.x, 10.0); - * assert_eq!(vec.y + 100.0, 132.0); - * ``` - * Similarly, for matrices with compile-time dimensions <= 6, you can use field notation - * like this: `mat.m11`, `mat.m42`, etc. The first digit identifies the row to address - * and the second digit identifies the column to address. So `mat.m13` identifies the component - * at the first row and third column (note that the count of rows and columns start at 1 instead - * of 0 here. This is so we match the mathematical notation). - * - * For all matrices and vectors, independently from their size, individual components can - * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing - * starts at 0 as you would expect. - */ - nalgebra_array_storage_f64__4__1 data; -} nalgebra_matrix_f64_4_1; - -/** - * A stack-allocated, 4-dimensional column vector. - */ -typedef struct nalgebra_matrix_f64_4_1 nalgebra_vector4_f64; - -/** - * A quaternion. See the type alias `UnitQuaternion = Unit` for a quaternion - * that may be used as a rotation. - */ -typedef struct nalgebra_quaternion_f64 { - /** - * This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. - */ - nalgebra_vector4_f64 coords; -} nalgebra_quaternion_f64; - -typedef struct viam_euler_angles { - double roll; - double pitch; - double yaw; -} viam_euler_angles; - -/** - * A wrapper that ensures the underlying algebraic entity has a unit norm. - * - * **It is likely that the only piece of documentation that you need in this page are:** - * - **[The construction with normalization](#construction-with-normalization)** - * - **[Data extraction and construction without normalization](#data-extraction-and-construction-without-normalization)** - * - **[Interpolation between two unit vectors](#interpolation-between-two-unit-vectors)** - * - * All the other impl blocks you will see in this page are about [`UnitComplex`](crate::UnitComplex) - * and [`UnitQuaternion`](crate::UnitQuaternion); both built on top of `Unit`. If you are interested - * in their documentation, read their dedicated pages directly. - */ -typedef struct nalgebra_matrix_f64_3_1 nalgebra_unit_matrix_f64_3_1; - -/** - * A stack-allocated, 3-dimensional unit vector. - */ -typedef nalgebra_unit_matrix_f64_3_1 nalgebra_unit_vector3_f64; - -typedef struct viam_orientation_vector { - nalgebra_unit_vector3_f64 o_vector; - double theta; -} viam_orientation_vector; - -/** - * A array-based statically sized matrix data storage. - */ -typedef double nalgebra_array_storage_f64__3__3[3][3]; - -/** - * The most generic column-major matrix (and vector) type. - * - * # Methods summary - * Because `Matrix` is the most generic types used as a common representation of all matrices and - * vectors of **nalgebra** this documentation page contains every single matrix/vector-related - * method. In order to make browsing this page simpler, the next subsections contain direct links - * to groups of methods related to a specific topic. - * - * #### Vector and matrix construction - * - [Constructors of statically-sized vectors or statically-sized matrices](#constructors-of-statically-sized-vectors-or-statically-sized-matrices) - * (`Vector3`, `Matrix3x6`…) - * - [Constructors of fully dynamic matrices](#constructors-of-fully-dynamic-matrices) (`DMatrix`) - * - [Constructors of dynamic vectors and matrices with a dynamic number of rows](#constructors-of-dynamic-vectors-and-matrices-with-a-dynamic-number-of-rows) - * (`DVector`, `MatrixXx3`…) - * - [Constructors of matrices with a dynamic number of columns](#constructors-of-matrices-with-a-dynamic-number-of-columns) - * (`Matrix2xX`…) - * - [Generic constructors](#generic-constructors) - * (For code generic wrt. the vectors or matrices dimensions.) - * - * #### Computer graphics utilities for transformations - * - [2D transformations as a Matrix3 `new_rotation`…](#2d-transformations-as-a-matrix3) - * - [3D transformations as a Matrix4 `new_rotation`, `new_perspective`, `look_at_rh`…](#3d-transformations-as-a-matrix4) - * - [Translation and scaling in any dimension `new_scaling`, `new_translation`…](#translation-and-scaling-in-any-dimension) - * - [Append/prepend translation and scaling `append_scaling`, `prepend_translation_mut`…](#appendprepend-translation-and-scaling) - * - [Transformation of vectors and points `transform_vector`, `transform_point`…](#transformation-of-vectors-and-points) - * - * #### Common math operations - * - [Componentwise operations `component_mul`, `component_div`, `inf`…](#componentwise-operations) - * - [Special multiplications `tr_mul`, `ad_mul`, `kronecker`…](#special-multiplications) - * - [Dot/scalar product `dot`, `dotc`, `tr_dot`…](#dotscalar-product) - * - [Cross product `cross`, `perp`…](#cross-product) - * - [Magnitude and norms `norm`, `normalize`, `metric_distance`…](#magnitude-and-norms) - * - [In-place normalization `normalize_mut`, `try_normalize_mut`…](#in-place-normalization) - * - [Interpolation `lerp`, `slerp`…](#interpolation) - * - [BLAS functions `gemv`, `gemm`, `syger`…](#blas-functions) - * - [Swizzling `xx`, `yxz`…](#swizzling) - * - [Triangular matrix extraction `upper_triangle`, `lower_triangle`](#triangular-matrix-extraction) - * - * #### Statistics - * - [Common operations `row_sum`, `column_mean`, `variance`…](#common-statistics-operations) - * - [Find the min and max components `min`, `max`, `amin`, `amax`, `camin`, `cmax`…](#find-the-min-and-max-components) - * - [Find the min and max components (vector-specific methods) `argmin`, `argmax`, `icamin`, `icamax`…](#find-the-min-and-max-components-vector-specific-methods) - * - * #### Iteration, map, and fold - * - [Iteration on components, rows, and columns `iter`, `column_iter`…](#iteration-on-components-rows-and-columns) - * - [Elementwise mapping and folding `map`, `fold`, `zip_map`…](#elementwise-mapping-and-folding) - * - [Folding or columns and rows `compress_rows`, `compress_columns`…](#folding-on-columns-and-rows) - * - * #### Vector and matrix slicing - * - [Creating matrix slices from `&[T]` `from_slice`, `from_slice_with_strides`…](#creating-matrix-slices-from-t) - * - [Creating mutable matrix slices from `&mut [T]` `from_slice_mut`, `from_slice_with_strides_mut`…](#creating-mutable-matrix-slices-from-mut-t) - * - [Slicing based on index and length `row`, `columns`, `slice`…](#slicing-based-on-index-and-length) - * - [Mutable slicing based on index and length `row_mut`, `columns_mut`, `slice_mut`…](#mutable-slicing-based-on-index-and-length) - * - [Slicing based on ranges `rows_range`, `columns_range`…](#slicing-based-on-ranges) - * - [Mutable slicing based on ranges `rows_range_mut`, `columns_range_mut`…](#mutable-slicing-based-on-ranges) - * - * #### In-place modification of a single matrix or vector - * - [In-place filling `fill`, `fill_diagonal`, `fill_with_identity`…](#in-place-filling) - * - [In-place swapping `swap`, `swap_columns`…](#in-place-swapping) - * - [Set rows, columns, and diagonal `set_column`, `set_diagonal`…](#set-rows-columns-and-diagonal) - * - * #### Vector and matrix size modification - * - [Rows and columns insertion `insert_row`, `insert_column`…](#rows-and-columns-insertion) - * - [Rows and columns removal `remove_row`, `remove column`…](#rows-and-columns-removal) - * - [Rows and columns extraction `select_rows`, `select_columns`…](#rows-and-columns-extraction) - * - [Resizing and reshaping `resize`, `reshape_generic`…](#resizing-and-reshaping) - * - [In-place resizing `resize_mut`, `resize_vertically_mut`…](#in-place-resizing) - * - * #### Matrix decomposition - * - [Rectangular matrix decomposition `qr`, `lu`, `svd`…](#rectangular-matrix-decomposition) - * - [Square matrix decomposition `cholesky`, `symmetric_eigen`…](#square-matrix-decomposition) - * - * #### Vector basis computation - * - [Basis and orthogonalization `orthonormal_subspace_basis`, `orthonormalize`…](#basis-and-orthogonalization) - * - * # Type parameters - * The generic `Matrix` type has four type parameters: - * - `T`: for the matrix components scalar type. - * - `R`: for the matrix number of rows. - * - `C`: for the matrix number of columns. - * - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix - * components. - * - * The matrix dimensions parameters `R` and `C` can either be: - * - type-level unsigned integer constants (e.g. `U1`, `U124`) from the `nalgebra::` root module. - * All numbers from 0 to 127 are defined that way. - * - type-level unsigned integer constants (e.g. `U1024`, `U10000`) from the `typenum::` crate. - * Using those, you will not get error messages as nice as for numbers smaller than 128 defined on - * the `nalgebra::` module. - * - the special value `Dynamic` from the `nalgebra::` root module. This indicates that the - * specified dimension is not known at compile-time. Note that this will generally imply that the - * matrix data storage `S` performs a dynamic allocation and contains extra metadata for the - * matrix shape. - * - * Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a - * dynamically-sized column vector should be represented as a `Matrix` (given - * some concrete types for `T` and a compatible data storage type `S`). - */ -typedef struct nalgebra_matrix_f64_3_3 { - /** - * The data storage that contains all the matrix components. Disappointed? - * - * Well, if you came here to see how you can access the matrix components, - * you may be in luck: you can access the individual components of all vectors with compile-time - * dimensions <= 6 using field notation like this: - * `vec.x`, `vec.y`, `vec.z`, `vec.w`, `vec.a`, `vec.b`. Reference and assignation work too: - * ``` - * # use nalgebra::Vector3; - * let mut vec = Vector3::new(1.0, 2.0, 3.0); - * vec.x = 10.0; - * vec.y += 30.0; - * assert_eq!(vec.x, 10.0); - * assert_eq!(vec.y + 100.0, 132.0); - * ``` - * Similarly, for matrices with compile-time dimensions <= 6, you can use field notation - * like this: `mat.m11`, `mat.m42`, etc. The first digit identifies the row to address - * and the second digit identifies the column to address. So `mat.m13` identifies the component - * at the first row and third column (note that the count of rows and columns start at 1 instead - * of 0 here. This is so we match the mathematical notation). - * - * For all matrices and vectors, independently from their size, individual components can - * be accessed and modified using indexing: `vec[20]`, `mat[(20, 19)]`. Here the indexing - * starts at 0 as you would expect. - */ - nalgebra_array_storage_f64__3__3 data; -} nalgebra_matrix_f64_3_3; - -/** - * A statically sized column-major matrix with `R` rows and `C` columns. - * - * **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** - */ -typedef struct nalgebra_matrix_f64_3_3 nalgebra_smatrix_f64_3_3; - -/** - * A rotation matrix. - * - * This is also known as an element of a Special Orthogonal (SO) group. - * The `Rotation` type can either represent a 2D or 3D rotation, represented as a matrix. - * For a rotation based on quaternions, see [`UnitQuaternion`](crate::UnitQuaternion) instead. - * - * Note that instead of using the [`Rotation`](crate::Rotation) type in your code directly, you should use one - * of its aliases: [`Rotation2`](crate::Rotation2), or [`Rotation3`](crate::Rotation3). Though - * keep in mind that all the documentation of all the methods of these aliases will also appears on - * this page. - * - * # Construction - * * [Identity `identity`](#identity) - * * [From a 2D rotation angle `new`…](#construction-from-a-2d-rotation-angle) - * * [From an existing 2D matrix or rotations `from_matrix`, `rotation_between`, `powf`…](#construction-from-an-existing-2d-matrix-or-rotations) - * * [From a 3D axis and/or angles `new`, `from_euler_angles`, `from_axis_angle`…](#construction-from-a-3d-axis-andor-angles) - * * [From a 3D eye position and target point `look_at`, `look_at_lh`, `rotation_between`…](#construction-from-a-3d-eye-position-and-target-point) - * * [From an existing 3D matrix or rotations `from_matrix`, `rotation_between`, `powf`…](#construction-from-an-existing-3d-matrix-or-rotations) - * - * # Transformation and composition - * Note that transforming vectors and points can be done by multiplication, e.g., `rotation * point`. - * Composing an rotation with another transformation can also be done by multiplication or division. - * * [3D axis and angle extraction `angle`, `euler_angles`, `scaled_axis`, `angle_to`…](#3d-axis-and-angle-extraction) - * * [2D angle extraction `angle`, `angle_to`…](#2d-angle-extraction) - * * [Transformation of a vector or a point `transform_vector`, `inverse_transform_point`…](#transformation-of-a-vector-or-a-point) - * * [Transposition and inversion `transpose`, `inverse`…](#transposition-and-inversion) - * * [Interpolation `slerp`…](#interpolation) - * - * # Conversion - * * [Conversion to a matrix `matrix`, `to_homogeneous`…](#conversion-to-a-matrix) - * - */ -typedef struct nalgebra_rotation_f64_3 { - nalgebra_smatrix_f64_3_3 matrix; -} nalgebra_rotation_f64_3; - -/** - * A 3-dimensional rotation matrix. - * - * **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** - */ -typedef struct nalgebra_rotation_f64_3 nalgebra_rotation3_f64; - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * 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`] - */ -struct viam_dial_ffi *viam_init_rust_runtime(void); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_dial_ffi *init_rust_runtime(void); - -/** - * Returns a path to a proxy to a robot - * # Safety - * - * This function must be called from another language. See [`dial`](mod@crate::rpc::dial) for dial from rust - * The function returns a path to a proxy as a [`c_char`], the string should be freed with free_string when not needed anymore. - * When falling to dial it will return a NULL pointer - * # Arguments - * * `c_uri` a C-style string representing the address of robot you want to connect to - * * `c_type` a C-style string representing the type of robot's secret you want to use, set to NULL if you don't need authentication - * * `c_payload` a C-style string that is the robot's secret, set to NULL if you don't need authentication - * * `c_allow_insecure` a bool, set to true when allowing insecure connection to your robot - * * `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 - */ -char *viam_dial(const char *c_uri, - const char *c_entity, - const char *c_type, - const char *c_payload, - bool c_allow_insec, - float c_timeout, - struct viam_dial_ffi *rt_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -char *dial(const char *c_uri, - const char *c_entity, - const char *c_type, - const char *c_payload, - bool c_allow_insec, - float c_timeout, - struct viam_dial_ffi *rt_ptr); - -/** - * This function must be used to free the path returned by the [`dial`] function - * # Safety - * - * The function must not be called more than once with the same pointer - * # Arguments - * * `c_char` a pointer to the string returned by [`dial`] - */ -void viam_free_string(char *s); - -/// @deprecated please use `viam_`-prefixed function instead void free_string(char *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 - * - * The function must not be called more than once with the same pointer - * # Arguments - * * `rt_prt` a pointer to the string returned by [`init_rust_runtime`] - */ -int32_t viam_free_rust_runtime(struct viam_dial_ffi *rt_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -int32_t free_rust_runtime(struct viam_dial_ffi *rt_ptr); - -/** - * Free memory at the address of the axis angle pointer. - * - * # Safety - * - * Outer processes that work with axis angles via the FFI interface MUST remember - * to call this function when finished with an axis angle instance - */ -void viam_free_axis_angles_memory(struct viam_axis_angle *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_axis_angles_memory(struct viam_axis_angle *ptr); - -/** - * Initialize axis angle from raw components and retrieve the C pointer - * to its address. - * - * # Safety - * - * When finished with the underlying axis angle initialized by this function - * the caller must remember to free the axis angle memory using the - * free_axis_angles_memory FFI function - */ -struct viam_axis_angle *viam_new_axis_angle(double x, double y, double z, double theta); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_axis_angle *new_axis_angle(double x, - double y, - double z, - double 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 - * a zero axis angle. In the event of an error from the nalgebra crate, a zero - * axis angle is also returned. - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function and the axis angle memory using - * the free_array_memory function - */ -struct viam_axis_angle *viam_axis_angle_from_quaternion(const struct nalgebra_quaternion_f64 *quat); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_axis_angle *axis_angle_from_quaternion(const struct nalgebra_quaternion_f64 *quat); - -/** - * Free memory at the address of the euler angles pointer. - * - * # Safety - * - * Outer processes that work with EulerAngles via the FFI interface MUST remember - * to call this function when finished with a euler angles instance - */ -void viam_free_euler_angles_memory(struct viam_euler_angles *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_euler_angles_memory(struct viam_euler_angles *ptr); - -/** - * Initialize euler angles from raw components and retrieve the C pointer - * to its address. - * - * # Safety - * - * When finished with the underlying euler angles initialized by this function - * the caller must remember to free the euler angles memory using the - * free_euler_angles_memory FFI function - */ -struct viam_euler_angles *viam_new_euler_angles(double roll, double pitch, double yaw); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_euler_angles *new_euler_angles(double roll, - double pitch, - double 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). - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function and the euler angles memory using - * the free_euler_angles_memory function - */ -struct viam_euler_angles *viam_euler_angles_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_euler_angles *euler_angles_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); - -/** - * Free memory at the address of the orientation vector pointer. Outer processes - * that work with OrientationVectors via the FFI interface MUST remember - * to call this function when finished with a OrientationVector instance - * - * # Safety - */ -void viam_free_orientation_vector_memory(struct viam_orientation_vector *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_orientation_vector_memory(struct viam_orientation_vector *ptr); - -/** - * Initialize an orientation vector from raw components and retrieve the C pointer - * to its address. - * - * # Safety - * - * When finished with the underlying orientation vector initialized by this function - * the caller must remember to free the orientation vector memory using the - * free_orientation_vector_memory FFI function - */ -struct viam_orientation_vector *viam_new_orientation_vector(double o_x, - double o_y, - double o_z, - double theta); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_orientation_vector *new_orientation_vector(double o_x, - double o_y, - double o_z, - double 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). - * - * # Safety - * - * When finished with the underlying orientation_vector passed to this function - * the caller must remember to free the orientation_vector memory using the - * free_orientation_vector_memory FFI function - */ -const double *viam_orientation_vector_get_components(const struct viam_orientation_vector *ov_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -const double *orientation_vector_get_components(const struct viam_orientation_vector *ov_ptr); - -/** - * Converts a quaternion into an orientation vector. - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function and the orientation-vector memory using - * the free_orientation_vector_memory function - */ -struct viam_orientation_vector *viam_orientation_vector_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct viam_orientation_vector *orientation_vector_from_quaternion(const struct nalgebra_quaternion_f64 *quat_ptr); - -/** - * Free memory of an array of orientation vector components at the given address. - * - * # Safety - * - * Outer processes that request the components of a orientation vector should call this function - * to free the memory allocated to the array once finished - */ -void viam_free_orientation_vector_components(double *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_orientation_vector_components(double *ptr); - -/** - * Initialize a quaternion from raw components and retrieve the C pointer - * to its address. - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -struct nalgebra_quaternion_f64 *viam_new_quaternion(double real, double i, double j, double k); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *new_quaternion(double real, - double i, - double j, - double k); - -/** - * Initialize a quaternion from a real part and a C pointer to a Vector3 - * and retrieve the C pointer to its address. - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -struct nalgebra_quaternion_f64 *viam_new_quaternion_from_vector(double real, - const nalgebra_vector3_f64 *imag_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *new_quaternion_from_vector(double real, - const nalgebra_vector3_f64 *imag_ptr); - -/** - * Free memory at the address of the quaternion pointer. - * - * # Safety - * - * Outer processes that work with Quaternions via the FFI interface MUST remember - * to call this function when finished with a quaternion - */ -void viam_free_quaternion_memory(struct nalgebra_quaternion_f64 *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_quaternion_memory(struct nalgebra_quaternion_f64 *ptr); - -/** - * Get the components of a quaternion as a list of C doubles, the order of the - * components will be (real, i, j, k). - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -const double *viam_quaternion_get_components(const struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -const double *quaternion_get_components(const struct nalgebra_quaternion_f64 *quat_ptr); - -/** - * Set the real component of an existing quaternion stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_quaternion_set_real(struct nalgebra_quaternion_f64 *quat_ptr, double real); - -/// @deprecated please use `viam_`-prefixed function instead -void quaternion_set_real(struct nalgebra_quaternion_f64 *quat_ptr, - double real); - -/** - * Set the i component of an existing quaternion stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_quaternion_set_i(struct nalgebra_quaternion_f64 *quat_ptr, double i); - -/// @deprecated please use `viam_`-prefixed function instead -void quaternion_set_i(struct nalgebra_quaternion_f64 *quat_ptr, - double i); - -/** - * Set the j component of an existing quaternion stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_quaternion_set_j(struct nalgebra_quaternion_f64 *quat_ptr, double j); - -/// @deprecated please use `viam_`-prefixed function instead -void quaternion_set_j(struct nalgebra_quaternion_f64 *quat_ptr, - double j); - -/** - * Set the k component of an existing quaternion stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_quaternion_set_k(struct nalgebra_quaternion_f64 *quat_ptr, double k); - -/// @deprecated please use `viam_`-prefixed function instead -void quaternion_set_k(struct nalgebra_quaternion_f64 *quat_ptr, - double k); - -/** - * Set all of the components of an existing quaternion stored at the address - * of a pointer - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_quaternion_set_components(struct nalgebra_quaternion_f64 *quat_ptr, - double real, - double i, - double j, - double k); - -/// @deprecated please use `viam_`-prefixed function instead -void quaternion_set_components(struct nalgebra_quaternion_f64 *quat_ptr, - double real, - double i, - double j, - double 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 - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function (the same applies for the vector - * stored at vec_ptr) - */ -void viam_quaternion_set_imag_from_vector(struct nalgebra_quaternion_f64 *quat_ptr, - const nalgebra_vector3_f64 *vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void quaternion_set_imag_from_vector(struct nalgebra_quaternion_f64 *quat_ptr, - const nalgebra_vector3_f64 *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 - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -nalgebra_vector3_f64 *viam_quaternion_get_imaginary_vector(const struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *quaternion_get_imaginary_vector(const struct nalgebra_quaternion_f64 *quat_ptr); - -/** - * Normalizes an existing quaternion stored at the address of - * a pointer (quat_ptr) - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_normalize_quaternion(struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void normalize_quaternion(struct nalgebra_quaternion_f64 *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 - * - * # Safety - * - * 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 - */ -struct nalgebra_quaternion_f64 *viam_quaternion_get_normalized(const struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_get_normalized(const struct nalgebra_quaternion_f64 *quat_ptr); - -/** - * Returns the result of rotating a vector by a quaternion - * - * # Safety - * - * The caller must remember to free the quaternion memory and - * the memory of both vectors when finished with them using the - * free_quaternion_memory and free_vector_memory FFI functions - */ -nalgebra_vector3_f64 *viam_quaternion_rotate_vector(const struct nalgebra_quaternion_f64 *quat_ptr, - const nalgebra_vector3_f64 *vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *quaternion_rotate_vector(const struct nalgebra_quaternion_f64 *quat_ptr, - const nalgebra_vector3_f64 *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) - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -struct nalgebra_quaternion_f64 *viam_quaternion_from_euler_angles(double roll, - double pitch, - double yaw); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_from_euler_angles(double roll, - double pitch, - double 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 - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -struct nalgebra_quaternion_f64 *viam_quaternion_from_axis_angle(double x, - double y, - double z, - double theta); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_from_axis_angle(double x, - double y, - double z, - double 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 - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function. Similarly the free_vector_memory should - * be called when finished with the axis angle vector - */ -struct nalgebra_quaternion_f64 *viam_quaternion_from_axis_angle_vector(double theta, - const nalgebra_vector3_f64 *axis_angle_vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_from_axis_angle_vector(double theta, - const nalgebra_vector3_f64 *axis_angle_vec_ptr); - -/** - * Converts from a pointer to a Rotation3 to a quaternion - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -struct nalgebra_quaternion_f64 *viam_quaternion_from_rotation_matrix(const nalgebra_rotation3_f64 *rot_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_from_rotation_matrix(const nalgebra_rotation3_f64 *rot_ptr); - -/** - * Converts from a pointer to an OrientationVector to a quaternion - * - * # Safety - * - * When finished with the underlying quaternion initialized by this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -struct nalgebra_quaternion_f64 *viam_quaternion_from_orientation_vector(const struct viam_orientation_vector *o_vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_from_orientation_vector(const struct viam_orientation_vector *o_vec_ptr); - -/** - * Scales an existing quaternion stored at the address of - * a pointer (quat_ptr) by a factor (float) - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function - */ -void viam_scale_quaternion(struct nalgebra_quaternion_f64 *quat_ptr, double factor); - -/// @deprecated please use `viam_`-prefixed function instead -void scale_quaternion(struct nalgebra_quaternion_f64 *quat_ptr, - double 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 - * - * # Safety - * - * 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 - */ -struct nalgebra_quaternion_f64 *viam_quaternion_get_scaled(const struct nalgebra_quaternion_f64 *quat_ptr, - double factor); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_get_scaled(const struct nalgebra_quaternion_f64 *quat_ptr, - double 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 - * - * # Safety - * - * 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 - */ -struct nalgebra_quaternion_f64 *viam_quaternion_get_conjugate(const struct nalgebra_quaternion_f64 *quat_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_get_conjugate(const struct nalgebra_quaternion_f64 *quat_ptr); - -/** - * Adds two quaternions and returns a pointer to the - * memory of the result - * - * # Safety - * - * 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 - */ -struct nalgebra_quaternion_f64 *viam_quaternion_add(const struct nalgebra_quaternion_f64 *quat_ptr_1, - const struct nalgebra_quaternion_f64 *quat_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_add(const struct nalgebra_quaternion_f64 *quat_ptr_1, - const struct nalgebra_quaternion_f64 *quat_ptr_2); - -/** - * Subtracts two quaternions and returns a pointer to the - * memory of the result - * - * # Safety - * - * 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 - */ -struct nalgebra_quaternion_f64 *viam_quaternion_subtract(const struct nalgebra_quaternion_f64 *quat_ptr_1, - const struct nalgebra_quaternion_f64 *quat_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_subtract(const struct nalgebra_quaternion_f64 *quat_ptr_1, - const struct nalgebra_quaternion_f64 *quat_ptr_2); - -/** - * Computes the Hamiltonian product of two quaternions and - * returns a pointer to the memory of the result - * - * # Safety - * - * 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 - */ -struct nalgebra_quaternion_f64 *viam_quaternion_hamiltonian_product(const struct nalgebra_quaternion_f64 *quat_ptr_1, - const struct nalgebra_quaternion_f64 *quat_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -struct nalgebra_quaternion_f64 *quaternion_hamiltonian_product(const struct nalgebra_quaternion_f64 *quat_ptr_1, - const struct nalgebra_quaternion_f64 *quat_ptr_2); - -/** - * Free memory of an array of quaternion components at the given address. - * - * # Safety - * - * Outer processes that request the components of a quaternion should call this function - * to free the memory allocated to the array once finished - */ -void viam_free_quaternion_components(double *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_quaternion_components(double *ptr); - -/** - * Free memory at the address of the rotation matrix pointer. Outer processes - * that work with RotationMatrices via the FFI interface MUST remember - * to call this function when finished with a rotation matrix - * - * # Safety - */ -void viam_free_rotation_matrix_memory(nalgebra_rotation3_f64 *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_rotation_matrix_memory(nalgebra_rotation3_f64 *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) - * - * # Safety - * - * When finished with the underlying rotation matrix initialized by this function - * the caller must remember to free the rotation matrix memory using the - * free_rotation_matrix_memory FFI function - */ -nalgebra_rotation3_f64 *viam_new_rotation_matrix(const double (*elements)[9]); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_rotation3_f64 *new_rotation_matrix(const double (*elements)[9]); - -/** - * Converts a quaternion into a 3D rotation matrix (a Rotation - * from the nalgebra crate) - * - * # Safety - * - * When finished with the underlying quaternion passed to this function - * the caller must remember to free the quaternion memory using the - * free_quaternion_memory FFI function and the rotation matrix memory using - * the free_rotation_matrix_memory function - */ -nalgebra_rotation3_f64 *viam_rotation_matrix_from_quaternion(const struct nalgebra_quaternion_f64 *quat); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_rotation3_f64 *rotation_matrix_from_quaternion(const struct nalgebra_quaternion_f64 *quat); - -/** - * Initialize a 3-vector from raw components and retrieve the C pointer - * to its address. - * - * # Safety - * - * When finished with the underlying vector initialized by this function - * the caller must remember to free the vector memory using the - * free_vector_memory FFI function - */ -nalgebra_vector3_f64 *viam_new_vector3(double x, double y, double z); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *new_vector3(double x, - double y, - double 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 - */ -void viam_free_vector_memory(nalgebra_vector3_f64 *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_vector_memory(nalgebra_vector3_f64 *ptr); - -/** - * Get the components of a vector as a list of C doubles, the order of the - * components will be (x, y, z). - * - * # Safety - * - * When finished with the underlying vector, the caller must remember to - * free the vector memory using the free_vector_memory FFI function - */ -const double *viam_vector_get_components(const nalgebra_vector3_f64 *vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -const double *vector_get_components(const nalgebra_vector3_f64 *vec_ptr); - -/** - * Set the x component of an existing vector stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying vector, the caller must remember to - * free the vector memory using the free_vector_memory FFI function - */ -void viam_vector_set_x(nalgebra_vector3_f64 *vec_ptr, double x_val); - -/// @deprecated please use `viam_`-prefixed function instead -void vector_set_x(nalgebra_vector3_f64 *vec_ptr, - double x_val); - -/** - * Set the y component of an existing vector stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying vector, the caller must remember to - * free the vector memory using the free_vector_memory FFI function - */ -void viam_vector_set_y(nalgebra_vector3_f64 *vec_ptr, double y_val); - -/// @deprecated please use `viam_`-prefixed function instead -void vector_set_y(nalgebra_vector3_f64 *vec_ptr, - double y_val); - -/** - * Set the z component of an existing vector stored at the address - * of a pointer. - * - * # Safety - * - * When finished with the underlying vector, the caller must remember to - * free the vector memory using the free_vector_memory FFI function - */ -void viam_vector_set_z(nalgebra_vector3_f64 *vec_ptr, double z_val); - -/// @deprecated please use `viam_`-prefixed function instead -void vector_set_z(nalgebra_vector3_f64 *vec_ptr, - double z_val); - -/** - * Normalizes an existing vector stored at the address of - * a pointer (vec_ptr) - * - * # Safety - * - * When finished with the underlying vector, the caller must remember to - * free the vector memory using the free_vector_memory FFI function - */ -void viam_normalize_vector(nalgebra_vector3_f64 *vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void normalize_vector(nalgebra_vector3_f64 *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 - * - * # Safety - * - * 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 - */ -nalgebra_vector3_f64 *viam_vector_get_normalized(const nalgebra_vector3_f64 *vec_ptr); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *vector_get_normalized(const nalgebra_vector3_f64 *vec_ptr); - -/** - * Scales an existing vector stored at the address of - * a pointer (vec_ptr) by a float factor - * - * # Safety - * - * When finished with the underlying vector, the caller must remember to - * free the vector memory using the free_vector_memory FFI function - */ -void viam_scale_vector(nalgebra_vector3_f64 *vec_ptr, double factor); - -/// @deprecated please use `viam_`-prefixed function instead -void scale_vector(nalgebra_vector3_f64 *vec_ptr, - double 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 - * - * # Safety - * - * 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 - */ -nalgebra_vector3_f64 *viam_vector_get_scaled(const nalgebra_vector3_f64 *vec_ptr, double factor); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *vector_get_scaled(const nalgebra_vector3_f64 *vec_ptr, - double factor); - -/** - * Adds two vectors and returns a pointer to the - * memory of the result - * - * # Safety - * - * 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 - */ -nalgebra_vector3_f64 *viam_vector_add(const nalgebra_vector3_f64 *vec_ptr_1, - const nalgebra_vector3_f64 *vec_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *vector_add(const nalgebra_vector3_f64 *vec_ptr_1, - const nalgebra_vector3_f64 *vec_ptr_2); - -/** - * Subtracts two vectors and returns a pointer to the - * memory of the result - * - * # Safety - * - * 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 - */ -nalgebra_vector3_f64 *viam_vector_subtract(const nalgebra_vector3_f64 *vec_ptr_1, - const nalgebra_vector3_f64 *vec_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *vector_subtract(const nalgebra_vector3_f64 *vec_ptr_1, - const nalgebra_vector3_f64 *vec_ptr_2); - -/** - * Computes the dot product of two vectors - * - * # Safety - * - * The caller must remember to free the vector memory of the input vectors - * when finished with them using the free_vector_memory FFI function - */ -double viam_vector_dot_product(const nalgebra_vector3_f64 *vec_ptr_1, - const nalgebra_vector3_f64 *vec_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -double vector_dot_product(const nalgebra_vector3_f64 *vec_ptr_1, - const nalgebra_vector3_f64 *vec_ptr_2); - -/** - * Computes the cross product of two vectors and returns - * a pointer to the memory of the result - * - * # Safety - * - * 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 - */ -nalgebra_vector3_f64 *viam_vector_cross_product(nalgebra_vector3_f64 *vec_ptr_1, - nalgebra_vector3_f64 *vec_ptr_2); - -/// @deprecated please use `viam_`-prefixed function instead -nalgebra_vector3_f64 *vector_cross_product(nalgebra_vector3_f64 *vec_ptr_1, - nalgebra_vector3_f64 *vec_ptr_2); - -/** - * Free memory of an array of vector components at the given address. - * - * # Safety - * - * Outer processes that request the components of a vector should call this function - * to free the memory allocated to the array once finished - */ -void viam_free_vector_components(double *ptr); - -/// @deprecated please use `viam_`-prefixed function instead -void free_vector_components(double *ptr); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus