1#![no_std]
2
3pub extern crate nalgebra as na;
4
5#[cfg(feature = "serde")]
6#[macro_use]
7extern crate serde;
8
9pub mod prelude {
10 pub use crate::dynamics::models::*;
11 pub use crate::dynamics::solver::*;
12 pub use crate::dynamics::*;
13 pub use crate::math::*;
14}
15
16pub mod math {
17 pub use super::parry_math::math::*;
19 pub type Kernel = crate::dynamics::solver::QuadraticKernel;
20
21 #[derive(Copy, Clone, Debug, PartialEq)]
22 pub struct DecomposedTensor {
23 pub deviatoric_part: Matrix<Real>,
24 pub spherical_part: Real,
25 }
26
27 impl DecomposedTensor {
28 pub fn decompose(tensor: &Matrix<Real>) -> Self {
29 let spherical_part = tensor.trace() / (DIM as Real);
30 let mut deviatoric_part = *tensor;
31
32 for i in 0..DIM {
33 deviatoric_part[(i, i)] -= spherical_part;
34 }
35
36 Self {
37 deviatoric_part,
38 spherical_part,
39 }
40 }
41
42 pub fn zero() -> Self {
43 Self {
44 deviatoric_part: Matrix::zeros(),
45 spherical_part: 0.0,
46 }
47 }
48
49 pub fn recompose(&self) -> Matrix<Real> {
50 self.deviatoric_part + Matrix::identity() * self.spherical_part
51 }
52 }
53
54 impl core::ops::Add<DecomposedTensor> for DecomposedTensor {
55 type Output = DecomposedTensor;
56
57 #[inline]
58 fn add(self, rhs: DecomposedTensor) -> DecomposedTensor {
59 DecomposedTensor {
60 deviatoric_part: self.deviatoric_part + rhs.deviatoric_part,
61 spherical_part: self.spherical_part + rhs.spherical_part,
62 }
63 }
64 }
65
66 impl core::ops::AddAssign<DecomposedTensor> for DecomposedTensor {
67 #[inline]
68 fn add_assign(&mut self, rhs: DecomposedTensor) {
69 self.deviatoric_part += rhs.deviatoric_part;
70 self.spherical_part += rhs.spherical_part;
71 }
72 }
73
74 impl core::ops::Mul<Vector<Real>> for DecomposedTensor {
75 type Output = Vector<Real>;
76
77 #[inline]
78 fn mul(self, rhs: Vector<Real>) -> Self::Output {
79 self.deviatoric_part * rhs + self.spherical_part * rhs
80 }
81 }
82}
83
84mod parry_math {
85
86 mod real {
87 #[cfg(feature = "f64")]
89 pub type Real = f64;
90
91 #[cfg(feature = "f32")]
93 pub type Real = f32;
94 }
95
96 #[cfg(feature = "dim3")]
98 pub mod math {
99 pub use super::real::*;
100 use na::{
101 Isometry3, Matrix3, Point3, Translation3, UnitQuaternion, UnitVector3, Vector3,
102 Vector6, U3, U6,
103 };
104
105 pub const DEFAULT_EPSILON: Real = Real::EPSILON;
107
108 pub const DIM: usize = 3;
110
111 pub type Dim = U3;
113
114 pub type SpatialDim = U6;
116
117 pub type AngDim = U3;
119
120 pub type Point<N> = Point3<N>;
122
123 pub type AngVector<N> = Vector3<N>;
125
126 pub type Vector<N> = Vector3<N>;
128
129 pub type UnitVector<N> = UnitVector3<N>;
131
132 pub type Matrix<N> = Matrix3<N>;
134
135 pub type SpatialVector<N> = Vector6<N>;
137
138 pub type Orientation<N> = Vector3<N>;
140
141 pub type Isometry<N> = Isometry3<N>;
143
144 pub type Rotation<N> = UnitQuaternion<N>;
146
147 pub type Translation<N> = Translation3<N>;
149
150 pub type PrincipalAngularInertia<N> = Vector3<N>;
152
153 pub type CrossMatrix<N> = Matrix3<N>;
155
156 pub type SpacialVector<N> = Vector6<N>;
158 }
159
160 #[cfg(feature = "dim2")]
162 pub mod math {
163 pub use super::real::*;
164 use na::{
165 Isometry2, Matrix2, Point2, Translation2, UnitComplex, UnitVector2, Vector1, Vector2,
166 Vector3, U2,
167 };
168
169 pub const DEFAULT_EPSILON: Real = Real::EPSILON;
171
172 pub const DIM: usize = 2;
174
175 pub type Dim = U2;
177
178 pub type Point<N> = Point2<N>;
180
181 pub type AngVector<N> = N;
183
184 pub type Vector<N> = Vector2<N>;
186
187 pub type UnitVector<N> = UnitVector2<N>;
189
190 pub type Matrix<N> = Matrix2<N>;
192
193 pub type Orientation<N> = Vector1<N>;
195
196 pub type Isometry<N> = Isometry2<N>;
198
199 pub type Rotation<N> = UnitComplex<N>;
201
202 pub type Translation<N> = Translation2<N>;
204
205 pub type AngularInertia<N> = N;
207
208 pub type PrincipalAngularInertia<N> = N;
210
211 pub type CrossMatrix<N> = Vector2<N>;
213
214 pub type SpacialVector<N> = Vector3<N>;
216 }
217}
218
219pub mod dynamics;
220pub mod utils;