maliput_sys/math/
mod.rs

1// BSD 3-Clause License
2//
3// Copyright (c) 2024, Woven by Toyota.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are met:
8//
9// * Redistributions of source code must retain the above copyright notice, this
10//   list of conditions and the following disclaimer.
11//
12// * Redistributions in binary form must reproduce the above copyright notice,
13//   this list of conditions and the following disclaimer in the documentation
14//   and/or other materials provided with the distribution.
15//
16// * Neither the name of the copyright holder nor the names of its
17//   contributors may be used to endorse or promote products derived from
18//   this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#[cxx::bridge(namespace = "maliput::math")]
32pub mod ffi {
33    unsafe extern "C++" {
34        include!("math/math.h");
35
36        #[namespace = "maliput::math"]
37        type Vector3;
38        fn Vector3_new(x: f64, y: f64, z: f64) -> UniquePtr<Vector3>;
39        fn x(self: &Vector3) -> f64;
40        fn y(self: &Vector3) -> f64;
41        fn z(self: &Vector3) -> f64;
42        fn norm(self: &Vector3) -> f64;
43        fn normalize(self: Pin<&mut Vector3>);
44        fn Vector3_dot(v: &Vector3, w: &Vector3) -> f64;
45        fn Vector3_cross(v: &Vector3, w: &Vector3) -> UniquePtr<Vector3>;
46        fn Vector3_equals(v: &Vector3, w: &Vector3) -> bool;
47        fn Vector3_to_str(v: &Vector3) -> String;
48
49        type Vector4;
50        fn Vector4_new(x: f64, y: f64, z: f64, w: f64) -> UniquePtr<Vector4>;
51        fn x(self: &Vector4) -> f64;
52        fn y(self: &Vector4) -> f64;
53        fn z(self: &Vector4) -> f64;
54        fn w(self: &Vector4) -> f64;
55        fn norm(self: &Vector4) -> f64;
56        fn normalize(self: Pin<&mut Vector4>);
57        fn Vector4_dot(v: &Vector4, w: &Vector4) -> f64;
58        fn Vector4_equals(v: &Vector4, w: &Vector4) -> bool;
59        fn Vector4_to_str(v: &Vector4) -> String;
60
61        type Matrix3;
62        #[allow(clippy::too_many_arguments)]
63        fn Matrix3_new(
64            m00: f64,
65            m01: f64,
66            m02: f64,
67            m10: f64,
68            m11: f64,
69            m12: f64,
70            m20: f64,
71            m21: f64,
72            m22: f64,
73        ) -> UniquePtr<Matrix3>;
74        fn cofactor(self: &Matrix3, row: u64, col: u64) -> f64;
75        fn determinant(self: &Matrix3) -> f64;
76        fn is_singular(self: &Matrix3) -> bool;
77        fn Matrix3_row(m: &Matrix3, index: u64) -> UniquePtr<Vector3>;
78        fn Matrix3_col(m: &Matrix3, index: u64) -> UniquePtr<Vector3>;
79        fn Matrix3_cofactor_matrix(m: &Matrix3) -> UniquePtr<Matrix3>;
80        fn Matrix3_transpose(m: &Matrix3) -> UniquePtr<Matrix3>;
81        fn Matrix3_equals(m: &Matrix3, other: &Matrix3) -> bool;
82        fn Matrix3_adjoint(m: &Matrix3) -> UniquePtr<Matrix3>;
83        fn Matrix3_operator_mul(m: &Matrix3, other: &Matrix3) -> UniquePtr<Matrix3>;
84        fn Matrix3_inverse(m: &Matrix3) -> UniquePtr<Matrix3>;
85        fn Matrix3_operator_sum(m: &Matrix3, other: &Matrix3) -> UniquePtr<Matrix3>;
86        fn Matrix3_operator_sub(m: &Matrix3, other: &Matrix3) -> UniquePtr<Matrix3>;
87        fn Matrix3_operator_divide_by_scalar(m: &Matrix3, scalar: f64) -> UniquePtr<Matrix3>;
88        fn Matrix3_to_str(m: &Matrix3) -> String;
89
90        type Quaternion;
91        fn Quaternion_new(w: f64, x: f64, y: f64, z: f64) -> UniquePtr<Quaternion>;
92        fn w(self: &Quaternion) -> f64;
93        fn x(self: &Quaternion) -> f64;
94        fn y(self: &Quaternion) -> f64;
95        fn z(self: &Quaternion) -> f64;
96        fn dot(self: &Quaternion, other: &Quaternion) -> f64;
97        fn AngularDistance(self: &Quaternion, other: &Quaternion) -> f64;
98        fn norm(self: &Quaternion) -> f64;
99        fn normalize(self: Pin<&mut Quaternion>);
100        fn squared_norm(self: &Quaternion) -> f64;
101        fn Quaternion_vec(q: &Quaternion) -> UniquePtr<Vector3>;
102        fn Quaternion_coeffs(q: &Quaternion) -> UniquePtr<Vector4>;
103        fn Quaternion_Inverse(q: &Quaternion) -> UniquePtr<Quaternion>;
104        fn Quaternion_conjugate(q: &Quaternion) -> UniquePtr<Quaternion>;
105        fn Quaternion_ToRotationMatrix(q: &Quaternion) -> UniquePtr<Matrix3>;
106        fn Quaternion_TransformVector(q: &Quaternion, v: &Vector3) -> UniquePtr<Vector3>;
107        fn Quaternion_IsApprox(q: &Quaternion, other: &Quaternion, precision: f64) -> bool;
108        fn Quaternion_equals(q: &Quaternion, other: &Quaternion) -> bool;
109        fn Quaternion_to_str(q: &Quaternion) -> String;
110
111        type RollPitchYaw;
112        fn RollPitchYaw_new(roll: f64, pitch: f64, yaw: f64) -> UniquePtr<RollPitchYaw>;
113        fn roll_angle(self: &RollPitchYaw) -> f64;
114        fn pitch_angle(self: &RollPitchYaw) -> f64;
115        fn yaw_angle(self: &RollPitchYaw) -> f64;
116        fn vector(self: &RollPitchYaw) -> &Vector3;
117        fn RollPitchYaw_set(rpy: Pin<&mut RollPitchYaw>, roll: f64, pitch: f64, yaw: f64);
118        fn RollPitchYaw_SetFromQuaternion(rpy: Pin<&mut RollPitchYaw>, q: &Quaternion);
119        fn RollPitchYaw_ToQuaternion(rpy: &RollPitchYaw) -> UniquePtr<Quaternion>;
120        fn RollPitchYaw_ToMatrix(rpy: &RollPitchYaw) -> UniquePtr<Matrix3>;
121        fn RollPitchYaw_CalcRotationMatrixDt(rpy: &RollPitchYaw, rpyDt: &Vector3) -> UniquePtr<Matrix3>;
122    }
123}