1#![deny(non_camel_case_types)]
65#![deny(unused_parens)]
66#![deny(non_upper_case_globals)]
67#![deny(unused_qualifications)]
68#![deny(missing_docs)] #![deny(unused_results)]
70#![deny(bare_trait_objects)]
71#![allow(type_alias_bounds)]
72#![warn(non_camel_case_types)]
73#![allow(missing_copy_implementations)]
74#![doc(html_root_url = "http://nphysics.org/rustdoc/")]
75
76#[macro_use]
77extern crate approx;
78#[macro_use]
79extern crate downcast_rs;
80#[macro_use]
81extern crate bitflags;
82
83extern crate nalgebra as na;
84#[cfg(feature = "dim2")]
85extern crate ncollide2d as ncollide;
86#[cfg(feature = "dim3")]
87extern crate ncollide3d as ncollide;
88extern crate num_traits as num;
89
90macro_rules! try_ret {
94 ($val: expr) => {
95 try_ret!($val, ())
96 };
97 ($val: expr, $ret: expr) => {
98 if let Some(val) = $val {
99 val
100 } else {
101 return $ret;
102 }
103 };
104}
105
106macro_rules! try_continue {
107 ($val: expr) => {
108 if let Some(val) = $val {
109 val
110 } else {
111 continue;
112 }
113 };
114}
115
116macro_rules! desc_setters(
117 ($($with_method: ident, $set_method: ident $(, $arg: ident: $t: ty)*)*) => {
118 $(
119 #[allow(missing_docs)]
120 #[inline]
121 pub fn $with_method(mut self $(, $arg: $t)*) -> Self {
122 $(
123 self.$arg = $arg;
124 )*
125 self
126 }
127
128 #[allow(missing_docs)]
129 #[inline]
130 pub fn $set_method(&mut self $(, $arg: $t)*) -> &mut Self {
131 $(
132 self.$arg = $arg;
133 )*
134 self
135 }
136 )*
137 }
138);
139
140macro_rules! desc_custom_setters(
141 ($($this: ident.$with_method: ident, $set_method: ident $(, $arg: ident: $t: ty)* | $imp: expr)*) => {
142 $(
143 #[allow(missing_docs)]
144 #[inline]
145 pub fn $with_method(mut $this $(, $arg: $t)*) -> Self {
146 $imp
147 $this
148 }
149
150 #[allow(missing_docs)]
151 #[inline]
152 pub fn $set_method(&mut $this $(, $arg: $t)*) -> &mut Self {
153 $imp
154 $this
155 }
156 )*
157 }
158);
159
160macro_rules! desc_custom_getters(
161 ($($this: ident.$get_method: ident: $t: ty | $imp: expr)*) => {
162 $(
163 #[allow(missing_docs)]
164 #[inline]
165 pub fn $get_method(&$this) -> $t {
166 $imp
167 }
168 )*
169 }
170);
171
172macro_rules! desc_getters(
173 ($([val] $name: ident -> $val: ident: $t: ty)* $([ref] $ref_name: ident -> $ref_val: ident: $ref_t: ty)*) => {
174 $(
175 #[allow(missing_docs)]
176 #[inline]
177 pub fn $name(&self) -> $t {
178 self.$val
179 }
180 )*
181 $(
182 #[allow(missing_docs)]
183 #[inline]
184 pub fn $ref_name(&self) -> &$ref_t {
185 &self.$ref_val
186 }
187 )*
188 }
189);
190
191macro_rules! user_data_accessors(
192 () => {
193 #[inline]
195 pub fn user_data(&self) -> Option<&(dyn Any + Send + Sync)> {
196 self.user_data.as_deref()
197 }
198
199 #[inline]
201 pub fn user_data_mut(&mut self) -> Option<&mut (dyn Any + Send + Sync)> {
202 self.user_data.as_deref_mut()
203 }
204
205 #[inline]
207 pub fn set_user_data(&mut self, data: Option<Box<dyn Any + Send + Sync>>) -> Option<Box<dyn Any + Send + Sync>> {
208 std::mem::replace(&mut self.user_data, data)
209 }
210
211 #[inline]
213 pub fn take_user_data(&mut self) -> Option<Box<dyn Any + Send + Sync>> {
214 self.user_data.take()
215 }
216 }
217);
218
219macro_rules! user_data_desc_accessors(
220 () => {
221 pub fn user_data(mut self, data: impl UserData) -> Self {
223 self.user_data = Some(UserDataBox(Box::new(data) as Box<dyn UserData>));
224 self
225 }
226
227 pub fn set_user_data(&mut self, data: Option<impl UserData>) -> &mut Self {
229 self.user_data = data.map(|data| UserDataBox(Box::new(data) as Box<dyn UserData>));
230 self
231 }
232
233 pub fn get_user_data(&self) -> Option<&(dyn Any + Send + Sync)> {
235 self.user_data.as_ref().map(|data| data.0.as_any())
236 }
237 }
238);
239
240const NOT_REGISTERED_ERROR: &'static str =
241 "This collider has not been registered into a world (proxy indexes are None).";
242
243pub mod algebra;
244pub mod counters;
245pub mod detection;
246pub mod force_generator;
247pub mod joint;
248pub mod material;
249pub mod object;
250pub mod solver;
251pub mod utils;
252pub mod volumetric;
253pub mod world;
254pub use nalgebra;
257#[cfg(feature = "dim2")]
258pub use ncollide2d;
259#[cfg(feature = "dim3")]
260pub use ncollide3d;
261pub use simba;
262
263#[cfg(feature = "dim3")]
265pub mod math {
266 use crate::algebra::{Force3, Inertia3, Velocity3};
267 use na::{
268 Dynamic, Isometry3, Matrix3, Matrix6, OMatrix, MatrixSlice6xX, MatrixSliceMut6xX, Point3,
269 Rotation3, Translation3, UnitQuaternion, Vector3, Vector6, U3, U6,
270 };
271
272 pub use crate::algebra::ForceType;
273
274 pub const SPATIAL_DIM: usize = 6;
276 pub const ANGULAR_DIM: usize = 3;
278 pub const DIM: usize = 3;
280
281 pub type Dim = U3;
283
284 pub type SpatialDim = U6;
286
287 pub type AngularDim = U3;
289
290 pub type Point<N> = Point3<N>;
292
293 pub type AngularVector<N> = Vector3<N>;
295
296 pub type Vector<N> = Vector3<N>;
298
299 pub type SpatialVector<N> = Vector6<N>;
301
302 pub type Orientation<N> = Vector3<N>;
304
305 pub type Isometry<N> = Isometry3<N>;
307
308 pub type Rotation<N> = UnitQuaternion<N>;
310
311 pub type RotationMatrix<N> = Rotation3<N>;
313
314 pub type Translation<N> = Translation3<N>;
316
317 pub type Velocity<N> = Velocity3<N>;
319
320 pub type Force<N> = Force3<N>;
322
323 pub type AngularInertia<N> = Matrix3<N>;
325
326 pub type Inertia<N> = Inertia3<N>;
328
329 pub type InertiaMatrix<N> = Matrix6<N>;
331
332 pub type Matrix<N> = Matrix3<N>;
334
335 pub type SpatialMatrix<N> = Matrix6<N>;
337
338 pub type Jacobian<N> = OMatrix<N, U6, Dynamic>;
340
341 pub type JacobianSlice<'a, N> = MatrixSlice6xX<'a, N>;
343
344 pub type JacobianSliceMut<'a, N> = MatrixSliceMut6xX<'a, N>;
346}
347
348#[cfg(feature = "dim2")]
350pub mod math {
351 use crate::algebra::{Force2, Inertia2, Velocity2};
352 use na::{
353 Dynamic, Isometry2, Matrix1, Matrix2, Matrix3, OMatrix, MatrixSlice3xX, MatrixSliceMut3xX,
354 Point2, Rotation2, Translation2, UnitComplex, Vector1, Vector2, Vector3, U1, U2, U3,
355 };
356
357 pub use crate::algebra::ForceType;
358
359 pub const SPATIAL_DIM: usize = 3;
361 pub const ANGULAR_DIM: usize = 1;
363 pub const DIM: usize = 2;
365
366 pub type Dim = U2;
368
369 pub type AngularDim = U1;
371
372 pub type SpatialDim = U3;
374
375 pub type Point<N> = Point2<N>;
377
378 pub type SpatialVector<N> = Vector3<N>;
380
381 pub type AngularVector<N> = Vector1<N>;
383
384 pub type Vector<N> = Vector2<N>;
386
387 pub type Orientation<N> = Vector1<N>;
389
390 pub type Isometry<N> = Isometry2<N>;
392
393 pub type Rotation<N> = UnitComplex<N>;
395
396 pub type RotationMatrix<N> = Rotation2<N>;
398
399 pub type Translation<N> = Translation2<N>;
401
402 pub type Velocity<N> = Velocity2<N>;
404
405 pub type Force<N> = Force2<N>;
407
408 pub type AngularInertia<N> = Matrix1<N>;
410
411 pub type Inertia<N> = Inertia2<N>;
413
414 pub type InertiaMatrix<N> = Matrix3<N>;
416
417 pub type Matrix<N> = Matrix2<N>;
419
420 pub type SpatialMatrix<N> = Matrix3<N>;
422
423 pub type Jacobian<N> = OMatrix<N, U3, Dynamic>;
425
426 pub type JacobianSlice<'a, N> = MatrixSlice3xX<'a, N>;
428
429 pub type JacobianSliceMut<'a, N> = MatrixSliceMut3xX<'a, N>;
431}