parry3d/
lib.rs

1/*!
2parry
3========
4
5**parry** is a 2 and 3-dimensional geometric library written with
6the rust programming language.
7
8*/
9
10#![deny(non_camel_case_types)]
11#![deny(unused_parens)]
12#![deny(non_upper_case_globals)]
13#![deny(unused_results)]
14#![deny(unused_qualifications)]
15#![warn(missing_docs)]
16#![warn(unused_imports)]
17#![allow(missing_copy_implementations)]
18#![allow(clippy::too_many_arguments)] // Maybe revisit this one later.
19#![allow(clippy::module_inception)]
20#![allow(clippy::manual_range_contains)] // This usually makes it way more verbose that it could be.
21#![allow(clippy::type_complexity)] // Complains about closures that are fairly simple.
22#![doc(html_root_url = "http://docs.rs/parry/0.1.1")]
23#![no_std]
24
25#[cfg(all(
26    feature = "simd-is-enabled",
27    not(feature = "simd-stable"),
28    not(feature = "simd-nightly")
29))]
30std::compile_error!("The `simd-is-enabled` feature should not be enabled explicitly. Please enable the `simd-stable` or the `simd-nightly` feature instead.");
31#[cfg(all(feature = "simd-is-enabled", feature = "enhanced-determinism"))]
32std::compile_error!(
33    "SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled."
34);
35
36macro_rules! array(
37    ($callback: expr; SIMD_WIDTH) => {
38        {
39            #[inline(always)]
40            #[allow(dead_code)]
41            fn create_arr<T>(mut callback: impl FnMut(usize) -> T) -> [T; SIMD_WIDTH] {
42                [callback(0usize), callback(1usize), callback(2usize), callback(3usize)]
43            }
44
45            create_arr($callback)
46        }
47    }
48);
49
50#[cfg(feature = "std")]
51extern crate std;
52
53#[cfg(feature = "alloc")]
54#[cfg_attr(test, macro_use)]
55extern crate alloc;
56
57#[cfg(feature = "serde")]
58#[macro_use]
59extern crate serde;
60#[macro_use]
61extern crate approx;
62extern crate num_traits as num;
63
64pub extern crate either;
65pub extern crate nalgebra as na;
66pub extern crate simba;
67
68pub mod bounding_volume;
69pub mod mass_properties;
70pub mod partitioning;
71pub mod query;
72pub mod shape;
73#[cfg(feature = "alloc")]
74pub mod transformation;
75pub mod utils;
76
77mod real {
78    /// The scalar type used throughout this crate.
79    #[cfg(feature = "f64")]
80    pub use f64 as Real;
81
82    /// The scalar type used throughout this crate.
83    #[cfg(feature = "f32")]
84    pub use f32 as Real;
85}
86
87/// Compilation flags dependent aliases for mathematical types.
88#[cfg(feature = "dim3")]
89pub mod math {
90    pub use super::real::*;
91    pub use super::simd::*;
92    use na::{
93        Isometry3, Matrix3, Point3, Translation3, UnitQuaternion, UnitVector3, Vector3, Vector6,
94        U3, U6,
95    };
96
97    /// The default tolerance used for geometric operations.
98    pub const DEFAULT_EPSILON: Real = Real::EPSILON;
99
100    /// The dimension of the space.
101    pub const DIM: usize = 3;
102
103    /// The dimension of the space multiplied by two.
104    pub const TWO_DIM: usize = DIM * 2;
105
106    /// The dimension of the ambient space.
107    pub type Dim = U3;
108
109    /// The dimension of a spatial vector.
110    pub type SpatialDim = U6;
111
112    /// The dimension of the rotations.
113    pub type AngDim = U3;
114
115    /// The point type.
116    pub type Point<N> = Point3<N>;
117
118    /// The angular vector type.
119    pub type AngVector<N> = Vector3<N>;
120
121    /// The vector type.
122    pub type Vector<N> = Vector3<N>;
123
124    /// The unit vector type.
125    pub type UnitVector<N> = UnitVector3<N>;
126
127    /// The matrix type.
128    pub type Matrix<N> = Matrix3<N>;
129
130    /// The vector type with dimension `SpatialDim × 1`.
131    pub type SpatialVector<N> = Vector6<N>;
132
133    /// The orientation type.
134    pub type Orientation<N> = Vector3<N>;
135
136    /// The transformation matrix type.
137    pub type Isometry<N> = Isometry3<N>;
138
139    /// The rotation matrix type.
140    pub type Rotation<N> = UnitQuaternion<N>;
141
142    /// The translation type.
143    pub type Translation<N> = Translation3<N>;
144
145    /// The angular inertia of a rigid body.
146    pub type AngularInertia<N> = crate::utils::SdpMatrix3<N>;
147
148    /// The principal angular inertia of a rigid body.
149    pub type PrincipalAngularInertia<N> = Vector3<N>;
150
151    /// A matrix that represent the cross product with a given vector.
152    pub type CrossMatrix<N> = Matrix3<N>;
153
154    /// A vector with a dimension equal to the maximum number of degrees of freedom of a rigid body.
155    pub type SpacialVector<N> = Vector6<N>;
156
157    /// A 3D symmetric-definite-positive matrix.
158    pub type SdpMatrix<N> = crate::utils::SdpMatrix3<N>;
159}
160
161/// Compilation flags dependent aliases for mathematical types.
162#[cfg(feature = "dim2")]
163pub mod math {
164    pub use super::real::*;
165    pub use super::simd::*;
166    use na::{
167        Isometry2, Matrix2, Point2, Translation2, UnitComplex, UnitVector2, Vector1, Vector2,
168        Vector3, U1, U2,
169    };
170
171    /// The default tolerance used for geometric operations.
172    pub const DEFAULT_EPSILON: Real = Real::EPSILON;
173
174    /// The dimension of the space.
175    pub const DIM: usize = 2;
176
177    /// The dimension of the space multiplied by two.
178    pub const TWO_DIM: usize = DIM * 2;
179
180    /// The dimension of the ambient space.
181    pub type Dim = U2;
182
183    /// The dimension of the rotations.
184    pub type AngDim = U1;
185
186    /// The point type.
187    pub type Point<N> = Point2<N>;
188
189    /// The angular vector type.
190    pub type AngVector<N> = N;
191
192    /// The vector type.
193    pub type Vector<N> = Vector2<N>;
194
195    /// The unit vector type.
196    pub type UnitVector<N> = UnitVector2<N>;
197
198    /// The matrix type.
199    pub type Matrix<N> = Matrix2<N>;
200
201    /// The orientation type.
202    pub type Orientation<N> = Vector1<N>;
203
204    /// The transformation matrix type.
205    pub type Isometry<N> = Isometry2<N>;
206
207    /// The rotation matrix type.
208    pub type Rotation<N> = UnitComplex<N>;
209
210    /// The translation type.
211    pub type Translation<N> = Translation2<N>;
212
213    /// The angular inertia of a rigid body.
214    pub type AngularInertia<N> = N;
215
216    /// The principal angular inertia of a rigid body.
217    pub type PrincipalAngularInertia<N> = N;
218
219    /// A matrix that represent the cross product with a given vector.
220    pub type CrossMatrix<N> = Vector2<N>;
221
222    /// A vector with a dimension equal to the maximum number of degrees of freedom of a rigid body.
223    pub type SpacialVector<N> = Vector3<N>;
224
225    /// A 2D symmetric-definite-positive matrix.
226    pub type SdpMatrix<N> = crate::utils::SdpMatrix2<N>;
227}
228
229#[cfg(not(feature = "simd-is-enabled"))]
230mod simd {
231    use simba::simd::AutoBoolx4;
232    /// The number of lanes of a SIMD number.
233    pub const SIMD_WIDTH: usize = 4;
234    /// SIMD_WIDTH - 1
235    pub const SIMD_LAST_INDEX: usize = 3;
236
237    /// A SIMD float with SIMD_WIDTH lanes.
238    #[cfg(feature = "f32")]
239    pub type SimdReal = simba::simd::AutoF32x4;
240
241    /// A SIMD float with SIMD_WIDTH lanes.
242    #[cfg(feature = "f64")]
243    pub type SimdReal = simba::simd::AutoF64x4;
244
245    /// A SIMD bool with SIMD_WIDTH lanes.
246    pub type SimdBool = AutoBoolx4;
247}
248
249#[cfg(feature = "simd-is-enabled")]
250mod simd {
251    #[cfg(all(feature = "simd-nightly", feature = "f32"))]
252    pub use simba::simd::{f32x4 as SimdReal, mask32x4 as SimdBool};
253    #[cfg(all(feature = "simd-stable", feature = "f32"))]
254    pub use simba::simd::{WideBoolF32x4 as SimdBool, WideF32x4 as SimdReal};
255
256    #[cfg(all(feature = "simd-nightly", feature = "f64"))]
257    pub use simba::simd::{f64x4 as SimdReal, mask64x4 as SimdBool};
258    #[cfg(all(feature = "simd-stable", feature = "f64"))]
259    pub use simba::simd::{WideBoolF64x4 as SimdBool, WideF64x4 as SimdReal};
260
261    /// The number of lanes of a SIMD number.
262    pub const SIMD_WIDTH: usize = 4;
263    /// SIMD_WIDTH - 1
264    pub const SIMD_LAST_INDEX: usize = 3;
265}