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(
27    feature = "simd-is-enabled",
28    not(feature = "simd-stable"),
29    not(feature = "simd-nightly")
30))]
31std::compile_error!("The `simd-is-enabled` feature should not be enabled explicitly. Please enable the `simd-stable` or the `simd-nightly` feature instead.");
32#[cfg(all(feature = "simd-is-enabled", feature = "enhanced-determinism"))]
33std::compile_error!(
34    "SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled."
35);
36
37#[cfg(feature = "simd-is-enabled")]
38#[allow(unused_macros)]
39macro_rules! array(
40    ($callback: expr; SIMD_WIDTH) => {
41        {
42            #[inline(always)]
43            #[allow(dead_code)]
44            fn create_arr<T>(mut callback: impl FnMut(usize) -> T) -> [T; SIMD_WIDTH] {
45                #[cfg(not(feature = "simd-is-enabled"))]
46                return [callback(0usize)];
47                #[cfg(feature = "simd-is-enabled")]
48                return [callback(0usize), callback(1usize), callback(2usize), callback(3usize)];
49            }
50
51            create_arr($callback)
52        }
53    }
54);
55
56#[cfg(feature = "std")]
57extern crate std;
58
59#[cfg(feature = "alloc")]
60#[cfg_attr(test, macro_use)]
61extern crate alloc;
62
63#[cfg(feature = "serde")]
64#[macro_use]
65extern crate serde;
66#[macro_use]
67extern crate approx;
68extern crate num_traits as num;
69
70pub extern crate either;
71pub extern crate glamx;
72pub extern crate simba;
73
74pub mod bounding_volume;
75pub mod mass_properties;
76pub mod math;
77pub mod partitioning;
78pub mod query;
79pub mod shape;
80#[cfg(feature = "alloc")]
81pub mod transformation;
82pub mod utils;
83
84#[cfg(not(feature = "simd-is-enabled"))]
85mod simd {
86    /// The number of lanes of a SIMD number.
87    pub const SIMD_WIDTH: usize = 1;
88    /// SIMD_WIDTH - 1
89    pub const SIMD_LAST_INDEX: usize = 0;
90
91    /// A SIMD float with SIMD_WIDTH lanes.
92    #[cfg(feature = "f32")]
93    pub type SimdReal = f32;
94
95    /// A SIMD float with SIMD_WIDTH lanes.
96    #[cfg(feature = "f64")]
97    pub type SimdReal = f64;
98
99    /// A SIMD bool with SIMD_WIDTH lanes.
100    pub type SimdBool = bool;
101}
102
103#[cfg(feature = "simd-is-enabled")]
104mod simd {
105    #[cfg(all(feature = "simd-nightly", feature = "f32"))]
106    pub use simba::simd::{f32x4 as SimdReal, mask32x4 as SimdBool};
107    #[cfg(all(feature = "simd-stable", feature = "f32"))]
108    pub use simba::simd::{WideBoolF32x4 as SimdBool, WideF32x4 as SimdReal};
109
110    #[cfg(all(feature = "simd-nightly", feature = "f64"))]
111    pub use simba::simd::{f64x4 as SimdReal, mask64x4 as SimdBool};
112    #[cfg(all(feature = "simd-stable", feature = "f64"))]
113    pub use simba::simd::{WideBoolF64x4 as SimdBool, WideF64x4 as SimdReal};
114
115    /// The number of lanes of a SIMD number.
116    pub const SIMD_WIDTH: usize = 4;
117    /// SIMD_WIDTH - 1
118    pub const SIMD_LAST_INDEX: usize = 3;
119}