1mod vector_ext;
4
5#[cfg(feature = "f64")]
7pub use f64 as Real;
8#[cfg(feature = "f64")]
9pub use i64 as Int;
10
11#[cfg(feature = "f32")]
13pub use f32 as Real;
14#[cfg(feature = "f32")]
15pub use i32 as Int;
16
17pub use simba::scalar::{ComplexField, RealField};
19
20pub use vector_ext::*;
21
22pub use crate::simd::*;
24
25#[cfg(feature = "f64")]
27pub use glamx::{
28 DPose2 as Pose2, DPose3 as Pose3, DRot2 as Rot2, DRot3 as Rot3,
29 DSymmetricEigen2 as SymmetricEigen2, DSymmetricEigen3 as SymmetricEigen3, MatExt,
30};
31#[cfg(feature = "f32")]
32pub use glamx::{MatExt, Pose2, Pose3, Rot2, Rot3, SymmetricEigen2, SymmetricEigen3};
33
34#[cfg(feature = "f64")]
36pub use glamx::{
37 DMat2 as Mat2, DMat3 as Mat3, DVec2 as Vec2, DVec3 as Vec3, DVec3 as Vec3A, DVec4 as Vec4,
38};
39#[cfg(feature = "f32")]
40pub use glamx::{Mat2, Mat3, Vec2, Vec3, Vec3A, Vec4};
41
42pub const DEFAULT_EPSILON: Real = Real::EPSILON;
44
45#[cfg(feature = "dim2")]
47pub const DIM: usize = 2;
48#[cfg(feature = "dim3")]
50pub const DIM: usize = 3;
51
52pub const TWO_DIM: usize = DIM * 2;
54
55#[cfg(feature = "dim3")]
60mod dim3_types {
61 use super::*;
62 #[cfg(feature = "f64")]
63 use glamx::{DMat3, DVec3};
64
65 #[cfg(feature = "f32")]
67 pub type Vector = Vec3;
68 #[cfg(feature = "f64")]
70 pub type Vector = DVec3;
71
72 #[cfg(feature = "f32")]
74 pub type IVector = glamx::IVec3;
75 #[cfg(feature = "f64")]
77 pub type IVector = glamx::I64Vec3;
78
79 #[cfg(feature = "f32")]
81 pub type AngVector = Vec3;
82 #[cfg(feature = "f64")]
84 pub type AngVector = DVec3;
85
86 #[cfg(feature = "f32")]
88 pub type Matrix = Mat3;
89 #[cfg(feature = "f64")]
91 pub type Matrix = DMat3;
92
93 pub type Pose = Pose3;
95
96 pub type Rotation = Rot3;
98
99 #[cfg(feature = "f32")]
101 pub type Orientation = Vec3;
102 #[cfg(feature = "f64")]
104 pub type Orientation = DVec3;
105
106 #[cfg(feature = "f32")]
108 pub type SpatialVector = [f32; 6];
109 #[cfg(feature = "f64")]
111 pub type SpatialVector = [f64; 6];
112
113 pub type AngularInertia = crate::utils::SdpMatrix3<Real>;
115
116 #[cfg(feature = "f32")]
118 pub type PrincipalAngularInertia = Vec3;
119 #[cfg(feature = "f64")]
121 pub type PrincipalAngularInertia = DVec3;
122
123 #[cfg(feature = "f32")]
125 pub type CrossMatrix = Mat3;
126 #[cfg(feature = "f64")]
128 pub type CrossMatrix = DMat3;
129
130 pub type SdpMatrix = crate::utils::SdpMatrix3<Real>;
132
133 #[cfg(feature = "f32")]
135 pub type SymmetricEigen = SymmetricEigen3;
136 #[cfg(feature = "f64")]
138 pub type SymmetricEigen = glamx::DSymmetricEigen3;
139}
140
141#[cfg(feature = "dim3")]
142pub use dim3_types::*;
143
144#[cfg(feature = "dim2")]
147mod dim2_types {
148 use super::*;
149 #[cfg(feature = "f64")]
150 use glamx::{DMat2, DVec2, DVec3};
151
152 #[cfg(feature = "f32")]
154 pub type Vector = Vec2;
155 #[cfg(feature = "f64")]
157 pub type Vector = DVec2;
158
159 #[cfg(feature = "f32")]
161 pub type IVector = glamx::IVec2;
162 #[cfg(feature = "f64")]
164 pub type IVector = glamx::I64Vec2;
165
166 pub type AngVector = Real;
168
169 #[cfg(feature = "f32")]
171 pub type Matrix = Mat2;
172 #[cfg(feature = "f64")]
174 pub type Matrix = DMat2;
175
176 pub type Pose = Pose2;
178
179 pub type Rotation = Rot2;
181
182 pub type Orientation = Real;
184
185 #[cfg(feature = "f32")]
187 pub type SpatialVector = Vec3;
188 #[cfg(feature = "f64")]
190 pub type SpatialVector = DVec3;
191
192 pub type AngularInertia = Real;
194
195 pub type PrincipalAngularInertia = Real;
197
198 #[cfg(feature = "f32")]
200 pub type CrossMatrix = Vec2;
201 #[cfg(feature = "f64")]
203 pub type CrossMatrix = DVec2;
204
205 pub type SdpMatrix = crate::utils::SdpMatrix2<Real>;
207
208 #[cfg(feature = "f32")]
210 pub type SymmetricEigen = SymmetricEigen2;
211 #[cfg(feature = "f64")]
213 pub type SymmetricEigen = glamx::DSymmetricEigen2;
214}
215
216#[cfg(feature = "dim2")]
217pub use dim2_types::*;
218
219#[cfg(feature = "dim3")]
226pub fn orthonormal_subspace_basis<F>(vs: &[Vector], mut f: F)
227where
228 F: FnMut(Vector) -> bool,
229{
230 if vs.is_empty() {
231 return;
232 }
233
234 let v = vs[0].normalize_or_zero();
236
237 if v == Vector::ZERO {
238 return;
239 }
240
241 let orth = if v.x.abs() > v.z.abs() {
243 Vector::new(-v.y, v.x, 0.0)
244 } else {
245 Vector::new(0.0, -v.z, v.y)
246 };
247
248 let orth1 = orth.normalize();
250 if !f(orth1) {
251 return;
252 }
253
254 let orth2 = v.cross(orth1);
256 let _ = f(orth2);
257}
258
259pub type Vector2 = Vec2;
264
265pub type Matrix2 = Mat2;
267
268pub type Vector3 = Vec3;
270
271pub type Matrix3 = Mat3;
273
274#[cfg(all(feature = "dim2", feature = "f32"))]
276pub fn ivect_to_vect(p: IVector) -> Vector {
277 p.as_vec2()
278}
279#[cfg(all(feature = "dim2", feature = "f64"))]
281pub fn ivect_to_vect(p: IVector) -> Vector {
282 p.as_dvec2()
283}
284#[cfg(all(feature = "dim3", feature = "f32"))]
286pub fn ivect_to_vect(p: IVector) -> Vector {
287 p.as_vec3()
288}
289#[cfg(all(feature = "dim3", feature = "f64"))]
291pub fn ivect_to_vect(p: IVector) -> Vector {
292 p.as_dvec3()
293}
294
295#[cfg(all(feature = "dim2", feature = "f32"))]
297pub fn vect_to_ivect(p: Vector) -> IVector {
298 p.as_ivec2()
299}
300#[cfg(all(feature = "dim2", feature = "f64"))]
302pub fn vect_to_ivect(p: Vector) -> IVector {
303 p.as_i64vec2()
304}
305#[cfg(all(feature = "dim3", feature = "f32"))]
307pub fn vect_to_ivect(p: Vector) -> IVector {
308 p.as_ivec3()
309}
310#[cfg(all(feature = "dim3", feature = "f64"))]
312pub fn vect_to_ivect(p: Vector) -> IVector {
313 p.as_i64vec3()
314}