Skip to main content

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#![cfg_attr(feature = "dim2", doc(html_root_url = "https://docs.rs/parry2d"))]
23#![cfg_attr(feature = "dim3", doc(html_root_url = "https://docs.rs/parry3d"))]
24#![no_std]
25
26#[cfg(all(feature = "simd8", feature = "enhanced-determinism"))]
27core::compile_error!(
28    "8-lanes SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled because it breaks cross-platform determinism."
29);
30
31#[allow(unused_macros)]
32macro_rules! array(
33    ($callback: expr; SIMD_WIDTH) => {
34        {
35            #[inline(always)]
36            #[allow(dead_code)]
37            fn create_arr<T>(callback: impl FnMut(usize) -> T) -> [T; SIMD_WIDTH] {
38                // Width-agnostic: `N` is inferred from the `[T; SIMD_WIDTH]` return type,
39                // so this covers the 1-, 4-, and 8-lane builds alike.
40                core::array::from_fn(callback)
41            }
42
43            create_arr($callback)
44        }
45    }
46);
47
48#[cfg(feature = "std")]
49extern crate std;
50
51#[cfg(feature = "alloc")]
52#[cfg_attr(test, macro_use)]
53extern crate alloc;
54
55#[cfg(feature = "serde")]
56#[macro_use]
57extern crate serde;
58#[macro_use]
59extern crate approx;
60extern crate num_traits as num;
61
62pub extern crate either;
63pub extern crate glamx;
64pub extern crate simba;
65
66#[macro_use]
67mod macros;
68
69pub mod bounding_volume;
70pub mod mass_properties;
71pub mod math;
72pub mod partitioning;
73pub mod query;
74pub mod shape;
75#[cfg(feature = "alloc")]
76pub mod transformation;
77pub mod utils;
78
79mod simd {
80    // The `wide` types fall back to scalar code on targets without SIMD, so
81    // they are always used, whatever the platform.
82
83    // 8-lane SIMD (f32 only; simba has no `WideF64x8`). Opt-in via `simd8`.
84    // Requires an AVX-enabled target (`RUSTFLAGS="-C target-feature=+avx2,+fma"`
85    // or `-C target-cpu=native`) for the compiler to actually emit 256-bit
86    // instructions; otherwise it runs (correctly) as two 128-bit halves.
87    #[cfg(all(feature = "simd8", feature = "f32"))]
88    pub use simba::simd::{WideBoolF32x8 as SimdBool, WideF32x8 as SimdReal};
89
90    // 4-lane SIMD (default width).
91    #[cfg(all(not(feature = "simd8"), feature = "f32"))]
92    pub use simba::simd::{WideBoolF32x4 as SimdBool, WideF32x4 as SimdReal};
93
94    // f64 stays 4-lane regardless of `simd8` (no 8-lane f64 type in simba).
95    #[cfg(feature = "f64")]
96    pub use simba::simd::{WideBoolF64x4 as SimdBool, WideF64x4 as SimdReal};
97
98    /// The number of lanes of a SIMD number.
99    #[cfg(all(feature = "simd8", feature = "f32"))]
100    pub const SIMD_WIDTH: usize = 8;
101    /// SIMD_WIDTH - 1
102    #[cfg(all(feature = "simd8", feature = "f32"))]
103    pub const SIMD_LAST_INDEX: usize = 7;
104
105    /// The number of lanes of a SIMD number.
106    #[cfg(not(all(feature = "simd8", feature = "f32")))]
107    pub const SIMD_WIDTH: usize = 4;
108    /// SIMD_WIDTH - 1
109    #[cfg(not(all(feature = "simd8", feature = "f32")))]
110    pub const SIMD_LAST_INDEX: usize = 3;
111}