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