diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index 119ef4d5..35c94acc 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -19,7 +19,8 @@ maintenance = { status = "actively-developed" } [features] default = [ "required-features", "std" ] required-features = [ "dim2", "f32" ] -std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade" ] +alloc = [ "hashbrown", "num-traits/libm", "nalgebra/alloc", "spade/alloc" ] +std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade/std" ] dim2 = [ ] f32 = [ ] serde-serialize = [ "serde", "nalgebra/serde-serialize", "arrayvec/serde" ] @@ -57,9 +58,10 @@ num-derive = "0.4" indexmap = { version = "1", features = [ "serde-1" ], optional = true } rustc-hash = { version = "1", optional = true } cust_core = { version = "0.1", optional = true } -spade = { version = "2", optional = true } +spade = { git = "https://github.com/hatmajster/spade.git", branch = "no_std", default-features = false, optional = true } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = [ "derive" ], optional = true } +hashbrown = { version = "0.14.2", optional = true } [target.'cfg(not(target_os = "cuda"))'.dependencies] cust = { version = "0.3", optional = true } diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index b074ebb8..de88f8a4 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -19,7 +19,8 @@ maintenance = { status = "actively-developed" } [features] default = [ "required-features", "std" ] required-features = [ "dim3", "f32" ] -std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade" ] +alloc = [ "hashbrown", "num-traits/libm", "nalgebra/alloc", "spade/alloc"] +std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade/std" ] dim3 = [ ] f32 = [ ] serde-serialize = [ "serde", "nalgebra/serde-serialize" ] @@ -58,9 +59,10 @@ num-derive = "0.4" indexmap = { version = "1", features = [ "serde-1" ], optional = true } rustc-hash = { version = "1", optional = true } cust_core = { version = "0.1", optional = true } -spade = { version = "2", optional = true } # Make this optional? +spade = { git = "https://github.com/hatmajster/spade.git", branch = "no_std", default-features = false, optional = true } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = [ "derive" ], optional = true } +hashbrown = { version = "0.14.2", optional = true } [target.'cfg(not(target_os = "cuda"))'.dependencies] cust = { version = "0.3", optional = true } diff --git a/src/bounding_volume/mod.rs b/src/bounding_volume/mod.rs index 4587f99f..c1fbab69 100644 --- a/src/bounding_volume/mod.rs +++ b/src/bounding_volume/mod.rs @@ -16,10 +16,10 @@ pub mod bounding_volume; pub mod aabb; mod aabb_ball; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod aabb_convex_polygon; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod aabb_convex_polyhedron; mod aabb_cuboid; mod aabb_halfspace; @@ -36,21 +36,21 @@ mod bounding_sphere_capsule; #[cfg(feature = "dim3")] mod bounding_sphere_cone; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod bounding_sphere_convex; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod bounding_sphere_convex_polygon; mod bounding_sphere_cuboid; #[cfg(feature = "dim3")] mod bounding_sphere_cylinder; mod bounding_sphere_halfspace; mod bounding_sphere_heightfield; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod bounding_sphere_polyline; mod bounding_sphere_segment; mod bounding_sphere_triangle; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod bounding_sphere_trimesh; mod bounding_sphere_utils; mod simd_aabb; diff --git a/src/lib.rs b/src/lib.rs index 6889900b..6b6a43fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ pub mod mass_properties; pub mod partitioning; pub mod query; pub mod shape; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub mod transformation; pub mod utils; diff --git a/src/mass_properties/mass_properties.rs b/src/mass_properties/mass_properties.rs index 1fd833d0..140535c3 100644 --- a/src/mass_properties/mass_properties.rs +++ b/src/mass_properties/mass_properties.rs @@ -9,6 +9,9 @@ use {na::Matrix3, std::ops::MulAssign}; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + const EPSILON: Real = f32::EPSILON as Real; #[derive(Copy, Clone, Debug, Default, PartialEq)] @@ -378,8 +381,8 @@ impl AddAssign for MassProperties { } } -#[cfg(feature = "std")] -impl std::iter::Sum for MassProperties { +#[cfg(any(feature = "std", feature = "alloc"))] +impl core::iter::Sum for MassProperties { #[cfg(feature = "dim2")] fn sum(iter: I) -> Self where diff --git a/src/mass_properties/mass_properties_trimesh3d.rs b/src/mass_properties/mass_properties_trimesh3d.rs index 502fbc9e..b150cda7 100644 --- a/src/mass_properties/mass_properties_trimesh3d.rs +++ b/src/mass_properties/mass_properties_trimesh3d.rs @@ -29,7 +29,10 @@ impl MassProperties { itot += ipart * vol; } + #[cfg(feature = "std")] let sign = volume.signum(); + #[cfg(not(feature = "std"))] + let sign = if volume >= 0.0f32 { 1.0f32 } else { -1.0f32 }; Self::with_inertia_matrix(com, volume * density * sign, itot * density * sign) } } @@ -208,6 +211,7 @@ mod test { use crate::shape::Shape; let orig_mprops = cuboid.mass_properties(1.0); + #[cfg(feature = "std")] dbg!(orig_mprops.principal_inertia()); let mut trimesh = cuboid.to_trimesh(); diff --git a/src/mass_properties/mod.rs b/src/mass_properties/mod.rs index bebb8618..e631eee7 100644 --- a/src/mass_properties/mod.rs +++ b/src/mass_properties/mod.rs @@ -5,37 +5,37 @@ pub use self::mass_properties::MassProperties; mod mass_properties; mod mass_properties_ball; mod mass_properties_capsule; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod mass_properties_compound; #[cfg(feature = "dim3")] mod mass_properties_cone; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod mass_properties_convex_polygon; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod mass_properties_convex_polyhedron; mod mass_properties_cuboid; mod mass_properties_cylinder; #[cfg(feature = "dim2")] mod mass_properties_triangle; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod mass_properties_trimesh2d; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod mass_properties_trimesh3d; /// Free functions for some special-cases of mass-properties computation. pub mod details { #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub use super::mass_properties_convex_polygon::convex_polygon_area_and_center_of_mass; #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub use super::mass_properties_trimesh2d::trimesh_area_and_center_of_mass; #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub use super::mass_properties_trimesh3d::{ tetrahedron_unit_inertia_tensor_wrt_point, trimesh_signed_volume_and_center_of_mass, }; diff --git a/src/partitioning/qbvh/build.rs b/src/partitioning/qbvh/build.rs index 58c98783..5a49ebd0 100644 --- a/src/partitioning/qbvh/build.rs +++ b/src/partitioning/qbvh/build.rs @@ -5,6 +5,12 @@ use crate::query::SplitResult; use crate::simd::SimdReal; use simba::simd::SimdValue; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec}; + +#[cfg(not(feature = "std"))] +use na::ComplexField; // for .abs() + use super::utils::split_indices_wrt_dim; use super::{IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhNodeFlags, QbvhProxy}; diff --git a/src/partitioning/qbvh/mod.rs b/src/partitioning/qbvh/mod.rs index 87ca330a..314fa201 100644 --- a/src/partitioning/qbvh/mod.rs +++ b/src/partitioning/qbvh/mod.rs @@ -15,11 +15,11 @@ mod qbvh; mod storage; pub(self) mod utils; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod build; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod traversal; -#[cfg(not(feature = "std"))] +#[cfg(not(any(feature = "std", feature = "alloc")))] mod traversal_no_std; #[cfg(feature = "std")] mod update; diff --git a/src/partitioning/qbvh/qbvh.rs b/src/partitioning/qbvh/qbvh.rs index 1095ea86..68d21d42 100644 --- a/src/partitioning/qbvh/qbvh.rs +++ b/src/partitioning/qbvh/qbvh.rs @@ -6,6 +6,10 @@ use bitflags::bitflags; use na::SimdValue; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + + #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; #[cfg(all(feature = "std", feature = "cuda"))] @@ -307,7 +311,7 @@ impl CudaQbvh { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Qbvh { /// Initialize an empty Qbvh. pub fn new() -> Self { diff --git a/src/partitioning/qbvh/storage.rs b/src/partitioning/qbvh/storage.rs index d54176c0..a287d719 100644 --- a/src/partitioning/qbvh/storage.rs +++ b/src/partitioning/qbvh/storage.rs @@ -5,6 +5,8 @@ use crate::utils::{Array1, DefaultStorage}; use crate::utils::CudaArray1; #[cfg(feature = "cuda")] use crate::utils::{CudaArrayPointer1, CudaStorage, CudaStoragePtr}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; /// Trait describing all the types needed for storing a Qbvh’s data. pub trait QbvhStorage { @@ -16,7 +18,7 @@ pub trait QbvhStorage { type ArrayProxies: Array1>; } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl QbvhStorage for DefaultStorage { type Nodes = Vec; type ArrayU32 = Vec; diff --git a/src/partitioning/qbvh/traversal.rs b/src/partitioning/qbvh/traversal.rs index 62f86a4e..b8ce7c79 100644 --- a/src/partitioning/qbvh/traversal.rs +++ b/src/partitioning/qbvh/traversal.rs @@ -10,7 +10,6 @@ use crate::utils::Array1; use crate::utils::WeightedValue; use num::Bounded; use simba::simd::SimdBool; -use std::collections::BinaryHeap; #[cfg(feature = "parallel")] use { crate::partitioning::{ParallelSimdSimultaneousVisitor, ParallelSimdVisitor}, @@ -19,6 +18,12 @@ use { std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}, }; +#[cfg(feature = "std")] +use std::collections::BinaryHeap; + +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec, collections::BinaryHeap}; + use super::{IndexedData, NodeIndex, Qbvh}; impl> GenericQbvh { diff --git a/src/query/clip/clip_aabb_polygon.rs b/src/query/clip/clip_aabb_polygon.rs index 92984512..ab65b2ca 100644 --- a/src/query/clip/clip_aabb_polygon.rs +++ b/src/query/clip/clip_aabb_polygon.rs @@ -1,6 +1,9 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real, Vector}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl Aabb { /// Computes the intersections between this Aabb and the given polygon. /// diff --git a/src/query/clip/clip_halfspace_polygon.rs b/src/query/clip/clip_halfspace_polygon.rs index d651ba97..b53c8892 100644 --- a/src/query/clip/clip_halfspace_polygon.rs +++ b/src/query/clip/clip_halfspace_polygon.rs @@ -1,6 +1,9 @@ use crate::math::{Point, Real, Vector}; use crate::query::{self, Ray}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + /// Cuts a polygon with the given half-space. /// /// Given the half-space `center` and outward `normal`, diff --git a/src/query/clip/mod.rs b/src/query/clip/mod.rs index 3a17f804..c1bd0113 100644 --- a/src/query/clip/mod.rs +++ b/src/query/clip/mod.rs @@ -1,13 +1,13 @@ pub use self::clip_aabb_line::clip_aabb_line; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::clip_halfspace_polygon::clip_halfspace_polygon; pub use self::clip_segment_segment::clip_segment_segment; #[cfg(feature = "dim2")] pub use self::clip_segment_segment::clip_segment_segment_with_normal; mod clip_aabb_line; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod clip_aabb_polygon; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod clip_halfspace_polygon; mod clip_segment_segment; diff --git a/src/query/contact/mod.rs b/src/query/contact/mod.rs index 6a6dcd9c..2b0659d8 100644 --- a/src/query/contact/mod.rs +++ b/src/query/contact/mod.rs @@ -14,7 +14,7 @@ pub use self::contact_halfspace_support_map::{ contact_halfspace_support_map, contact_support_map_halfspace, }; pub use self::contact_shape_shape::contact; -#[cfg(feature = "std")] // TODO: doesn’t work without std because of EPA +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::contact_support_map_support_map::{ contact_support_map_support_map, contact_support_map_support_map_with_params, }; @@ -27,5 +27,5 @@ mod contact_composite_shape_shape; mod contact_cuboid_cuboid; mod contact_halfspace_support_map; mod contact_shape_shape; -#[cfg(feature = "std")] // TODO: doesn’t work without std because of EPA +#[cfg(any(feature = "std", feature = "alloc"))] mod contact_support_map_support_map; diff --git a/src/query/contact_manifolds/contact_manifold.rs b/src/query/contact_manifolds/contact_manifold.rs index e1560fce..6776d86e 100644 --- a/src/query/contact_manifolds/contact_manifold.rs +++ b/src/query/contact_manifolds/contact_manifold.rs @@ -1,6 +1,9 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::PackedFeatureId; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( diff --git a/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs b/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs index 52641aa3..448a38da 100644 --- a/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_composite_shape_composite_shape.rs @@ -11,6 +11,9 @@ use crate::shape::SimdCompositeShape; use crate::utils::hashmap::{Entry, HashMap}; use crate::utils::IsometryOpt; +#[cfg(feature = "alloc")] +use alloc::{boxed::Box, vec::Vec}; + #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", @@ -128,7 +131,7 @@ pub fn contact_manifolds_composite_shape_composite_shape<'a, ManifoldData, Conta timestamp: new_timestamp, }; - let mut manifold = ContactManifold::new(); + let mut manifold: ContactManifold = ContactManifold::::new(); if flipped { manifold.subshape1 = *leaf2; diff --git a/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs b/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs index 31037e93..d6e53437 100644 --- a/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_composite_shape_shape.rs @@ -11,6 +11,9 @@ use crate::shape::{Shape, SimdCompositeShape}; use crate::utils::hashmap::{Entry, HashMap}; use crate::utils::IsometryOpt; +#[cfg(feature = "alloc")] +use alloc::{boxed::Box, vec::Vec}; + #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", @@ -103,7 +106,7 @@ pub fn contact_manifolds_composite_shape_shape( timestamp: new_timestamp, }; - let mut manifold = ContactManifold::new(); + let mut manifold: ContactManifold = ContactManifold::new(); if flipped { manifold.subshape1 = 0; diff --git a/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs b/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs index 5c31e91c..4af596d3 100644 --- a/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs +++ b/src/query/contact_manifolds/contact_manifolds_cuboid_cuboid.rs @@ -89,7 +89,7 @@ pub fn contact_manifold_cuboid_cuboid<'a, ManifoldData, ContactData: Default + C let feature1 = cuboid1.support_feature(best_sep.1); let feature2 = cuboid2.support_feature(local_n2); - PolygonalFeature::contacts( + PolygonalFeature::contacts::( pos12, pos21, &best_sep.1, diff --git a/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs b/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs index 25576328..8a328c7f 100644 --- a/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs +++ b/src/query/contact_manifolds/contact_manifolds_cuboid_triangle.rs @@ -122,7 +122,7 @@ pub fn contact_manifold_cuboid_triangle<'a, ManifoldData, ContactData>( let old_manifold_points = manifold.points.clone(); manifold.clear(); - PolygonalFeature::contacts( + PolygonalFeature::contacts::( pos12, pos21, &best_sep.1, diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs index e1c6afaa..1ae268dc 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs @@ -13,6 +13,9 @@ use crate::shape::{HeightField, Shape, SimdCompositeShape}; use crate::utils::hashmap::{Entry, HashMap}; use crate::utils::IsometryOpt; +#[cfg(feature = "alloc")] +use alloc::{boxed::Box, vec::Vec}; + #[cfg(feature = "dim3")] use crate::query::contact_manifolds::InternalEdgesFixer; @@ -117,7 +120,7 @@ pub fn contact_manifolds_heightfield_composite_shape( timestamp: new_timestamp, }; - let mut manifold = ContactManifold::new(); + let mut manifold: ContactManifold = ContactManifold::new(); if flipped { manifold.subshape1 = *leaf2; diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs index 1ea8a641..0c291859 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs @@ -14,6 +14,9 @@ use crate::utils::hashmap::{Entry, HashMap}; #[cfg(feature = "dim3")] use crate::query::contact_manifolds::InternalEdgesFixer; +#[cfg(feature = "alloc")] +use alloc::{boxed::Box, vec::Vec}; + #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", @@ -149,7 +152,7 @@ pub fn contact_manifolds_heightfield_shape( }; let (id1, id2) = if flipped { (0, i) } else { (i, 0) }; - manifolds.push(ContactManifold::with_data( + manifolds.push(ContactManifold::::with_data( id1, id2, ManifoldData::default(), diff --git a/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs b/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs index 11b5653e..a2b4021e 100644 --- a/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs +++ b/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs @@ -80,7 +80,7 @@ pub fn contact_manifold_pfm_pfm<'a, ManifoldData, ContactData, S1, S2>( pfm1.local_support_feature(&local_n1, &mut feature1); pfm2.local_support_feature(&local_n2, &mut feature2); - PolygonalFeature::contacts( + PolygonalFeature::contacts::( pos12, &pos12.inverse(), &local_n1, diff --git a/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs b/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs index 0d7e2ac2..7d4e2dc9 100644 --- a/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs @@ -8,6 +8,9 @@ use crate::query::query_dispatcher::PersistentQueryDispatcher; use crate::query::ContactManifold; use crate::shape::{Shape, TriMesh}; +#[cfg(feature = "alloc")] +use alloc::{boxed::Box, vec::Vec}; + #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", @@ -163,7 +166,7 @@ pub fn contact_manifolds_trimesh_shape( } } - let manifold = if old_inter_it.peek() != Some(triangle_id) { + let manifold: ContactManifold = if old_inter_it.peek() != Some(triangle_id) { let (id1, id2) = if flipped { (0, *triangle_id) } else { diff --git a/src/query/contact_manifolds/contact_manifolds_workspace.rs b/src/query/contact_manifolds/contact_manifolds_workspace.rs index f808a0dd..3e9f33ab 100644 --- a/src/query/contact_manifolds/contact_manifolds_workspace.rs +++ b/src/query/contact_manifolds/contact_manifolds_workspace.rs @@ -1,5 +1,8 @@ use downcast_rs::{impl_downcast, DowncastSync}; +#[cfg(feature = "alloc")] +use alloc::boxed::Box; + use crate::query::contact_manifolds::{ CompositeShapeCompositeShapeContactManifoldsWorkspace, CompositeShapeShapeContactManifoldsWorkspace, diff --git a/src/query/contact_manifolds/internal_edges_fixer.rs b/src/query/contact_manifolds/internal_edges_fixer.rs index a950922c..e8d7200f 100644 --- a/src/query/contact_manifolds/internal_edges_fixer.rs +++ b/src/query/contact_manifolds/internal_edges_fixer.rs @@ -2,9 +2,15 @@ use crate::query::ContactManifold; use crate::shape::Triangle; use crate::utils::hashmap::HashMap; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + #[cfg(feature = "dim3")] use crate::math::Real; +#[cfg(not(feature = "std"))] +use crate::na::ComplexField; + #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", diff --git a/src/query/default_query_dispatcher.rs b/src/query/default_query_dispatcher.rs index 121a34e6..df1eeb0e 100644 --- a/src/query/default_query_dispatcher.rs +++ b/src/query/default_query_dispatcher.rs @@ -3,13 +3,16 @@ use crate::query::{ self, details::NonlinearTOIMode, ClosestPoints, Contact, NonlinearRigidMotion, QueryDispatcher, Unsupported, TOI, }; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::query::{ contact_manifolds::ContactManifoldsWorkspace, query_dispatcher::PersistentQueryDispatcher, ContactManifold, }; use crate::shape::{HalfSpace, Segment, Shape, ShapeType}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + /// A dispatcher that exposes built-in queries #[derive(Debug, Clone)] pub struct DefaultQueryDispatcher; @@ -61,7 +64,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { pos12, s1, s2, )) } else { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] if let Some(c1) = shape1.as_composite_shape() { return Ok(query::details::intersection_test_composite_shape_shape( self, pos12, c1, shape2, @@ -307,7 +310,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { stop_at_penetration, )) } else { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] if let Some(heightfield1) = shape1.as_heightfield() { return query::details::time_of_impact_heightfield_shape( self, @@ -427,7 +430,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl PersistentQueryDispatcher for DefaultQueryDispatcher where @@ -518,7 +521,7 @@ where ); } else { if manifolds.is_empty() { - manifolds.push(ContactManifold::new()); + manifolds.push(ContactManifold::::new()); } return self.contact_manifold_convex_convex( diff --git a/src/query/epa/epa2.rs b/src/query/epa/epa2.rs index dac3476a..283b5179 100644 --- a/src/query/epa/epa2.rs +++ b/src/query/epa/epa2.rs @@ -1,6 +1,7 @@ //! Two-dimensional penetration depth queries using the Expanding Polytope Algorithm. -use std::cmp::Ordering; +use core::cmp::Ordering; +#[cfg(feature = "std")] use std::collections::BinaryHeap; use na::{self, Unit}; @@ -11,6 +12,9 @@ use crate::query::gjk::{self, CSOPoint, ConstantOrigin, VoronoiSimplex}; use crate::shape::SupportMap; use crate::utils; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, collections::BinaryHeap}; + #[derive(Copy, Clone, PartialEq)] struct FaceId { id: usize, diff --git a/src/query/epa/epa3.rs b/src/query/epa/epa3.rs index bea8597e..a81a1ace 100644 --- a/src/query/epa/epa3.rs +++ b/src/query/epa/epa3.rs @@ -7,9 +7,14 @@ use crate::shape::{SupportMap, Triangle, TrianglePointLocation}; use crate::utils; use na::{self, Unit}; use num::Bounded; -use std::cmp::Ordering; +use core::cmp::Ordering; + +#[cfg(feature = "std")] use std::collections::BinaryHeap; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, collections::BinaryHeap}; + #[derive(Copy, Clone, PartialEq)] struct FaceId { id: usize, @@ -447,12 +452,14 @@ impl EPA { #[allow(dead_code)] fn print_silhouette(&self) { + #[cfg(feature = "std")] print!("Silhouette points: "); for i in 0..self.silhouette.len() { let edge = &self.silhouette[i]; let face = &self.faces[edge.face_id]; if !face.deleted { + #[cfg(feature = "std")] print!( "({}, {}) ", face.pts[(edge.opp_pt_id + 2) % 3], @@ -460,6 +467,7 @@ impl EPA { ); } } + #[cfg(feature = "std")] println!(""); } diff --git a/src/query/intersection_test/mod.rs b/src/query/intersection_test/mod.rs index fceb5383..144f6eac 100644 --- a/src/query/intersection_test/mod.rs +++ b/src/query/intersection_test/mod.rs @@ -5,7 +5,7 @@ pub use self::intersection_test_ball_ball::intersection_test_ball_ball; pub use self::intersection_test_ball_point_query::{ intersection_test_ball_point_query, intersection_test_point_query_ball, }; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] // TODO: remove this once we get rid of IntersectionCompositeShapeShapeBestFirstVisitor #[allow(deprecated)] pub use self::intersection_test_composite_shape_shape::{ @@ -30,7 +30,7 @@ pub use self::intersection_test_support_map_support_map::intersection_test_suppo mod intersection_test; mod intersection_test_ball_ball; mod intersection_test_ball_point_query; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod intersection_test_composite_shape_shape; mod intersection_test_cuboid_cuboid; mod intersection_test_cuboid_segment; diff --git a/src/query/mod.rs b/src/query/mod.rs index f95dc1cf..8024182b 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -27,7 +27,7 @@ pub use self::closest_points::{closest_points, ClosestPoints}; pub use self::contact::{contact, Contact}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::contact_manifolds::{ ContactManifold, ContactManifoldsWorkspace, TrackedContact, TypedWorkspaceData, WorkspaceData, }; @@ -37,7 +37,7 @@ pub use self::error::Unsupported; pub use self::intersection_test::intersection_test; pub use self::nonlinear_time_of_impact::{nonlinear_time_of_impact, NonlinearRigidMotion}; pub use self::point::{PointProjection, PointQuery, PointQueryWithLocation}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::query_dispatcher::PersistentQueryDispatcher; pub use self::query_dispatcher::{QueryDispatcher, QueryDispatcherChain}; pub use self::ray::{Ray, RayCast, RayIntersection, SimdRay}; @@ -47,11 +47,11 @@ pub use self::time_of_impact::{time_of_impact, TOIStatus, TOI}; mod clip; pub mod closest_points; pub mod contact; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod contact_manifolds; mod default_query_dispatcher; mod distance; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub mod epa; mod error; pub mod gjk; diff --git a/src/query/point/mod.rs b/src/query/point/mod.rs index f59160b1..c72fac72 100644 --- a/src/query/point/mod.rs +++ b/src/query/point/mod.rs @@ -1,13 +1,13 @@ //! Point inclusion and projection. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::point_composite_shape::{ PointCompositeShapeProjBestFirstVisitor, PointCompositeShapeProjWithFeatureBestFirstVisitor, PointCompositeShapeProjWithLocationBestFirstVisitor, }; #[doc(inline)] pub use self::point_query::{PointProjection, PointQuery, PointQueryWithLocation}; -#[cfg(feature = "std")] // TODO: can’t be used without std because of EPA +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::point_support_map::local_point_projection_on_support_map; mod point_aabb; @@ -26,7 +26,7 @@ mod point_heightfield; pub mod point_query; mod point_round_shape; mod point_segment; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod point_support_map; #[cfg(feature = "dim3")] mod point_tetrahedron; diff --git a/src/query/point/point_composite_shape.rs b/src/query/point/point_composite_shape.rs index f50ca15b..6e7012fd 100644 --- a/src/query/point/point_composite_shape.rs +++ b/src/query/point/point_composite_shape.rs @@ -15,10 +15,10 @@ use simba::simd::{SimdBool as _, SimdPartialOrd, SimdValue}; #[cfg(feature = "dim3")] use crate::utils::Array1; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::shape::{Compound, Polyline}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl PointQuery for Polyline { #[inline] fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { @@ -104,7 +104,7 @@ impl PointQuery for GenericTriMesh { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl PointQuery for Compound { #[inline] fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { @@ -128,7 +128,7 @@ impl PointQuery for Compound { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl PointQueryWithLocation for Polyline { type Location = (u32, SegmentPointLocation); diff --git a/src/query/point/point_support_map.rs b/src/query/point/point_support_map.rs index 78e2a181..4afad8fa 100644 --- a/src/query/point/point_support_map.rs +++ b/src/query/point/point_support_map.rs @@ -1,15 +1,15 @@ use na::Unit; use crate::math::{Isometry, Point, Real, Vector}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::query::epa::EPA; use crate::query::gjk::{self, CSOPoint, ConstantOrigin, VoronoiSimplex}; use crate::query::{PointProjection, PointQuery}; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::shape::ConvexPolygon; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::shape::ConvexPolyhedron; use crate::shape::{FeatureId, SupportMap}; diff --git a/src/query/query_dispatcher.rs b/src/query/query_dispatcher.rs index 8fb5891a..09a09f64 100644 --- a/src/query/query_dispatcher.rs +++ b/src/query/query_dispatcher.rs @@ -1,10 +1,13 @@ use crate::math::{Isometry, Real, Vector}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::query::{contact_manifolds::ContactManifoldsWorkspace, ContactManifold}; use crate::query::{ClosestPoints, Contact, NonlinearRigidMotion, Unsupported, TOI}; use crate::shape::Shape; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + +#[cfg(any(feature = "std", feature = "alloc"))] /// A query dispatcher for queries relying on spatial coherence, including contact-manifold computation. pub trait PersistentQueryDispatcher: QueryDispatcher { /// Compute all the contacts between two shapes. @@ -202,7 +205,7 @@ where ) -> Option); } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl PersistentQueryDispatcher for QueryDispatcherChain where diff --git a/src/query/ray/mod.rs b/src/query/ray/mod.rs index 654a0479..3a227253 100644 --- a/src/query/ray/mod.rs +++ b/src/query/ray/mod.rs @@ -18,7 +18,7 @@ pub mod ray; mod ray_aabb; mod ray_ball; mod ray_bounding_sphere; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod ray_composite_shape; mod ray_cuboid; mod ray_halfspace; diff --git a/src/query/ray/ray_support_map.rs b/src/query/ray/ray_support_map.rs index 21d6c720..af702cd2 100644 --- a/src/query/ray/ray_support_map.rs +++ b/src/query/ray/ray_support_map.rs @@ -7,9 +7,9 @@ use crate::math::Real; use crate::query; use crate::query::gjk::{self, CSOPoint, VoronoiSimplex}; use crate::query::{Ray, RayCast, RayIntersection}; -#[cfg(all(feature = "std", feature = "dim2"))] +#[cfg(all(any(feature = "std", feature = "alloc"), feature = "dim2"))] use crate::shape::ConvexPolygon; -#[cfg(all(feature = "std", feature = "dim3"))] +#[cfg(all(any(feature = "std", feature = "alloc"), feature = "dim3"))] use crate::shape::ConvexPolyhedron; use crate::shape::{Capsule, FeatureId, Segment, SupportMap}; #[cfg(feature = "dim3")] @@ -119,7 +119,7 @@ impl RayCast for Capsule { } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl RayCast for ConvexPolyhedron { fn cast_local_ray_and_get_normal( &self, @@ -138,7 +138,7 @@ impl RayCast for ConvexPolyhedron { } #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl RayCast for ConvexPolygon { fn cast_local_ray_and_get_normal( &self, diff --git a/src/query/split/mod.rs b/src/query/split/mod.rs index b3ee010c..44c9fe40 100644 --- a/src/query/split/mod.rs +++ b/src/query/split/mod.rs @@ -4,5 +4,5 @@ mod split; mod split_aabb; mod split_segment; -#[cfg(all(feature = "std", feature = "dim3"))] +#[cfg(all(any(feature = "std", feature = "alloc"), feature = "dim3"))] mod split_trimesh; diff --git a/src/query/split/split_trimesh.rs b/src/query/split/split_trimesh.rs index 90ad67c4..0d968eec 100644 --- a/src/query/split/split_trimesh.rs +++ b/src/query/split/split_trimesh.rs @@ -5,8 +5,14 @@ use crate::query::{IntersectResult, PointQuery, SplitResult}; use crate::shape::{Cuboid, FeatureId, Polyline, Segment, Shape, TriMesh, TriMeshFlags, Triangle}; use crate::transformation; use crate::utils::{hashmap::HashMap, SortedPair, WBasis}; +#[cfg(any(feature = "std", feature = "alloc"))] use spade::{handles::FixedVertexHandle, ConstrainedDelaunayTriangulation, Triangulation as _}; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec}; + + +#[cfg(any(feature = "std", feature = "alloc"))] struct Triangulation { delaunay: ConstrainedDelaunayTriangulation>, basis: [Vector; 2], @@ -15,6 +21,7 @@ struct Triangulation { index2spade: HashMap, } +#[cfg(any(feature = "std", feature = "alloc"))] impl Triangulation { fn new(axis: UnitVector, basis_origin: Point) -> Self { Triangulation { @@ -65,11 +72,14 @@ impl TriMesh { /// Returns the result of the split. The first mesh returned is the piece lying on the negative /// half-space delimited by the splitting plane. The second mesh returned is the piece lying on the /// positive half-space delimited by the splitting plane. + #[cfg(feature = "std")] pub fn canonical_split(&self, axis: usize, bias: Real, epsilon: Real) -> SplitResult { // TODO: optimize this. self.local_split(&Vector::ith_axis(axis), bias, epsilon) } + + #[cfg(feature = "std")] /// Splits this mesh, transformed by `position` by a plane identified by its normal `local_axis` /// and the `bias` (i.e. the plane passes through the point equal to `normal * bias`). pub fn split( @@ -84,6 +94,8 @@ impl TriMesh { self.local_split(&local_axis, bias + added_bias, epsilon) } + + #[cfg(feature = "std")] /// Splits this mesh by a plane identified by its normal `local_axis` /// and the `bias` (i.e. the plane passes through the point equal to `normal * bias`). pub fn local_split( @@ -438,8 +450,14 @@ impl TriMesh { } }; + #[cfg(feature = "std")] let mut intersections_found = HashMap::default(); + #[cfg(feature = "alloc")] + let mut intersections_found: HashMap, usize> = HashMap::default(); + #[cfg(feature = "std")] let mut existing_vertices_found = HashMap::default(); + #[cfg(feature = "alloc")] + let mut existing_vertices_found: HashMap = HashMap::default(); let mut new_vertices = Vec::new(); for idx in indices.iter() { diff --git a/src/query/time_of_impact/mod.rs b/src/query/time_of_impact/mod.rs index 915c0c0d..ecd96a27 100644 --- a/src/query/time_of_impact/mod.rs +++ b/src/query/time_of_impact/mod.rs @@ -5,7 +5,7 @@ pub use self::time_of_impact_ball_ball::time_of_impact_ball_ball; pub use self::time_of_impact_halfspace_support_map::{ time_of_impact_halfspace_support_map, time_of_impact_support_map_halfspace, }; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::{ time_of_impact_composite_shape_shape::{ time_of_impact_composite_shape_shape, time_of_impact_shape_composite_shape, @@ -19,10 +19,10 @@ pub use self::{ mod time_of_impact; mod time_of_impact_ball_ball; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod time_of_impact_composite_shape_shape; mod time_of_impact_halfspace_support_map; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod time_of_impact_heightfield_shape; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod time_of_impact_support_map_support_map; diff --git a/src/query/time_of_impact/time_of_impact_heightfield_shape.rs b/src/query/time_of_impact/time_of_impact_heightfield_shape.rs index d265bd96..6dc12069 100644 --- a/src/query/time_of_impact/time_of_impact_heightfield_shape.rs +++ b/src/query/time_of_impact/time_of_impact_heightfield_shape.rs @@ -4,6 +4,9 @@ use crate::shape::{GenericHeightField, HeightFieldStorage, Shape}; #[cfg(feature = "dim3")] use crate::{bounding_volume::Aabb, query::RayCast}; +#[cfg(not(feature = "std"))] +use crate::na::ComplexField; + /// Time Of Impact between a moving shape and a heightfield. #[cfg(feature = "dim2")] pub fn time_of_impact_heightfield_shape( diff --git a/src/query/visitors/bounding_volume_intersections_visitor.rs b/src/query/visitors/bounding_volume_intersections_visitor.rs index a9e0d1d5..f933bf13 100644 --- a/src/query/visitors/bounding_volume_intersections_visitor.rs +++ b/src/query/visitors/bounding_volume_intersections_visitor.rs @@ -2,7 +2,7 @@ use crate::bounding_volume::{Aabb, SimdAabb}; use crate::math::SIMD_WIDTH; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; use simba::simd::SimdBool as _; -use std::marker::PhantomData; +use core::marker::PhantomData; /// Spatial partitioning data structure visitor collecting interferences with a given bounding volume. pub struct BoundingVolumeIntersectionsVisitor { diff --git a/src/query/visitors/mod.rs b/src/query/visitors/mod.rs index 80b40e25..95d6d5b4 100644 --- a/src/query/visitors/mod.rs +++ b/src/query/visitors/mod.rs @@ -2,9 +2,9 @@ #[cfg(feature = "std")] pub use self::aabb_sets_interferences_collector::AabbSetsInterferencesCollector; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::bounding_volume_intersections_simultaneous_visitor::BoundingVolumeIntersectionsSimultaneousVisitor; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::bounding_volume_intersections_visitor::BoundingVolumeIntersectionsVisitor; #[cfg(feature = "std")] pub use self::composite_closest_point_visitor::CompositeClosestPointVisitor; @@ -16,9 +16,9 @@ pub use self::ray_intersections_visitor::RayIntersectionsVisitor; #[cfg(feature = "std")] mod aabb_sets_interferences_collector; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod bounding_volume_intersections_simultaneous_visitor; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod bounding_volume_intersections_visitor; #[cfg(feature = "std")] mod composite_closest_point_visitor; diff --git a/src/shape/composite_shape.rs b/src/shape/composite_shape.rs index be0bda0e..2df04f24 100644 --- a/src/shape/composite_shape.rs +++ b/src/shape/composite_shape.rs @@ -7,7 +7,7 @@ use crate::utils::DefaultStorage; /// /// A composite shape is composed of several shapes. For example, this can /// be a convex decomposition of a concave shape; or a triangle-mesh. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub trait SimdCompositeShape { /// Applies a function to one sub-shape of this composite shape. fn map_part_at(&self, shape_id: u32, f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape)); @@ -39,7 +39,7 @@ pub trait TypedSimdCompositeShape { fn typed_qbvh(&self) -> &GenericQbvh; } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl<'a> TypedSimdCompositeShape for dyn SimdCompositeShape + 'a { type PartShape = dyn Shape; type PartId = u32; diff --git a/src/shape/compound.rs b/src/shape/compound.rs index 024fded9..34321a94 100644 --- a/src/shape/compound.rs +++ b/src/shape/compound.rs @@ -12,6 +12,9 @@ use crate::shape::{Shape, SharedShape, SimdCompositeShape, TypedSimdCompositeSha use crate::transformation::hertel_mehlhorn; use crate::utils::DefaultStorage; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + /// A compound shape with an aabb bounding volume. /// /// A compound shape is a shape composed of the union of several simpler shape. This is diff --git a/src/shape/convex_polygon.rs b/src/shape/convex_polygon.rs index 7ef31b94..2a50c5d0 100644 --- a/src/shape/convex_polygon.rs +++ b/src/shape/convex_polygon.rs @@ -16,6 +16,9 @@ pub struct ConvexPolygon { normals: Vec>>, } +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl ConvexPolygon { /// Creates a new 2D convex polygon from an arbitrary set of points. /// diff --git a/src/shape/convex_polyhedron.rs b/src/shape/convex_polyhedron.rs index f5e1bd6d..4ffd77c3 100644 --- a/src/shape/convex_polyhedron.rs +++ b/src/shape/convex_polyhedron.rs @@ -6,12 +6,12 @@ use crate::utils::{self, SortedPair}; use na::{self, ComplexField, Point2, Unit}; use std::f64; -#[cfg(not(feature = "std"))] -use na::ComplexField; // for .abs() - #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", @@ -139,7 +139,10 @@ impl ConvexPolyhedron { let mut edges = Vec::::new(); let mut faces = Vec::::new(); let mut triangles = Vec::new(); + #[cfg(feature = "std")] let mut edge_map = HashMap::default(); + #[cfg(feature = "alloc")] + let mut edge_map: HashMap, u32> = HashMap::default(); let mut faces_adj_to_vertex = Vec::new(); let mut edges_adj_to_vertex = Vec::new(); diff --git a/src/shape/heightfield2.rs b/src/shape/heightfield2.rs index 9d998cda..3dd2c1fb 100644 --- a/src/shape/heightfield2.rs +++ b/src/shape/heightfield2.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "std"))] use na::ComplexField; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use na::DVector; use std::ops::Range; @@ -32,7 +32,7 @@ pub trait HeightFieldStorage { type Status: Array1; } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl HeightFieldStorage for DefaultStorage { type Heights = DVector; type Status = DVector; @@ -101,7 +101,7 @@ where } /// A 2D heightfield. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub type HeightField = GenericHeightField; /// A 2D heightfield stored in the CUDA memory, initializable from the host. @@ -112,7 +112,7 @@ pub type CudaHeightField = GenericHeightField; #[cfg(feature = "cuda")] pub type CudaHeightFieldPtr = GenericHeightField; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl HeightField { /// Creates a new 2D heightfield with the given heights and scale factor. pub fn new(heights: DVector, scale: Vector) -> Self { diff --git a/src/shape/heightfield3.rs b/src/shape/heightfield3.rs index 591731cc..bcffd268 100644 --- a/src/shape/heightfield3.rs +++ b/src/shape/heightfield3.rs @@ -1,5 +1,5 @@ use crate::utils::DefaultStorage; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use na::DMatrix; use std::ops::Range; @@ -47,7 +47,7 @@ pub trait HeightFieldStorage { type Status: Array2; } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl HeightFieldStorage for DefaultStorage { type Heights = DMatrix; type Status = DMatrix; @@ -118,7 +118,7 @@ where } /// A 3D heightfield. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub type HeightField = GenericHeightField; /// A 3D heightfield stored in the CUDA memory, initializable from the host. @@ -129,7 +129,7 @@ pub type CudaHeightField = GenericHeightField; #[cfg(feature = "cuda")] pub type CudaHeightFieldPtr = GenericHeightField; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl HeightField { /// Initializes a new heightfield with the given heights and a scaling factor. pub fn new(heights: DMatrix, scale: Vector) -> Self { diff --git a/src/shape/mod.rs b/src/shape/mod.rs index d1b69c7f..5d7a51b6 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -18,14 +18,13 @@ pub use self::shape::{Shape, ShapeType, TypedShape}; pub use self::support_map::SupportMap; pub use self::triangle::{Triangle, TriangleOrientation, TrianglePointLocation}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::{ - composite_shape::SimdCompositeShape, compound::Compound, polyline::Polyline, - shared_shape::SharedShape, + composite_shape::SimdCompositeShape, compound::Compound, polyline::Polyline, shared_shape::SharedShape }; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::convex_polygon::ConvexPolygon; #[cfg(feature = "dim2")] pub use self::heightfield2::*; @@ -35,7 +34,7 @@ pub use self::polygonal_feature2d::PolygonalFeature; #[cfg(feature = "dim3")] pub use self::cone::Cone; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::convex_polyhedron::ConvexPolyhedron; #[cfg(feature = "dim3")] pub use self::cylinder::Cylinder; @@ -60,22 +59,22 @@ pub type RoundCuboid = RoundShape; pub type RoundTriangle = RoundShape; /// A convex polyhedron dilated by a sphere (so it has round corners). #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub type RoundConvexPolyhedron = RoundShape; /// A convex polygon dilated by a sphere (so it has round corners). #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub type RoundConvexPolygon = RoundShape; mod ball; mod capsule; #[doc(hidden)] pub mod composite_shape; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod compound; mod cuboid; mod half_space; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod polyline; mod round_shape; mod segment; @@ -86,7 +85,7 @@ pub mod support_map; mod triangle; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod convex_polygon; #[cfg(feature = "dim2")] mod heightfield2; @@ -94,7 +93,7 @@ mod heightfield2; #[cfg(feature = "dim3")] mod cone; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod convex_polyhedron; #[cfg(feature = "dim3")] mod cylinder; @@ -110,6 +109,6 @@ pub(crate) mod trimesh; mod feature_id; #[cfg(feature = "dim2")] mod polygonal_feature2d; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod shared_shape; mod trimesh_storage; diff --git a/src/shape/polygonal_feature2d.rs b/src/shape/polygonal_feature2d.rs index 89edac49..b45f2119 100644 --- a/src/shape/polygonal_feature2d.rs +++ b/src/shape/polygonal_feature2d.rs @@ -1,5 +1,5 @@ use crate::math::{Isometry, Point, Real, Vector}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::query::{self, ContactManifold, TrackedContact}; use crate::shape::{PackedFeatureId, Segment}; @@ -47,7 +47,7 @@ impl PolygonalFeature { } /// Computes the contacts between two polygonal features. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn contacts( pos12: &Isometry, pos21: &Isometry, @@ -76,7 +76,7 @@ impl PolygonalFeature { /// Compute contacts points between a face and a vertex. /// /// This method assume we already know that at least one contact exists. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn face_vertex_contacts( pos12: &Isometry, face1: &Self, @@ -107,7 +107,7 @@ impl PolygonalFeature { } /// Computes the contacts between two polygonal faces. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn face_face_contacts( pos12: &Isometry, face1: &Self, diff --git a/src/shape/polygonal_feature3d.rs b/src/shape/polygonal_feature3d.rs index c61e826b..d92ac3b5 100644 --- a/src/shape/polygonal_feature3d.rs +++ b/src/shape/polygonal_feature3d.rs @@ -1,6 +1,6 @@ use crate::approx::AbsDiffEq; use crate::math::{Isometry, Point, Real, Vector}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::query::{ContactManifold, TrackedContact}; use crate::shape::{PackedFeatureId, Segment, Triangle}; use crate::utils::WBasis; @@ -72,7 +72,7 @@ impl PolygonalFeature { } /// Computes all the contacts between two polygonal features. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn contacts( pos12: &Isometry, _pos21: &Isometry, @@ -94,7 +94,7 @@ impl PolygonalFeature { } } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn contacts_edge_edge( pos12: &Isometry, face1: &PolygonalFeature, @@ -210,7 +210,7 @@ impl PolygonalFeature { } } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn contacts_face_face( pos12: &Isometry, face1: &PolygonalFeature, diff --git a/src/shape/polyline.rs b/src/shape/polyline.rs index 64be51a7..a31f6895 100644 --- a/src/shape/polyline.rs +++ b/src/shape/polyline.rs @@ -9,6 +9,9 @@ use crate::utils::DefaultStorage; #[cfg(not(feature = "std"))] use na::ComplexField; // for .abs() +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + #[derive(Clone)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( diff --git a/src/shape/shape.rs b/src/shape/shape.rs index 1b482d14..f66f89bf 100644 --- a/src/shape/shape.rs +++ b/src/shape/shape.rs @@ -4,7 +4,7 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::query::{PointQuery, RayCast}; #[cfg(feature = "serde-serialize")] use crate::shape::SharedShape; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::shape::{composite_shape::SimdCompositeShape, Compound, HeightField, Polyline, TriMesh}; use crate::shape::{ Ball, Capsule, Cuboid, FeatureId, HalfSpace, PolygonalFeatureMap, RoundCuboid, RoundShape, @@ -14,17 +14,20 @@ use crate::shape::{ use crate::shape::{Cone, Cylinder, RoundCone, RoundCylinder}; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::shape::{ConvexPolyhedron, RoundConvexPolyhedron}; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use crate::shape::{ConvexPolygon, RoundConvexPolygon}; use downcast_rs::{impl_downcast, DowncastSync}; use na::{RealField, Unit}; use num::Zero; use num_derive::FromPrimitive; +#[cfg(feature = "alloc")] +use alloc::boxed::Box; + #[derive(Copy, Clone, Debug, FromPrimitive, PartialEq, Eq, Hash)] /// Enum representing the type of a shape. pub enum ShapeType { @@ -100,24 +103,24 @@ pub enum TypedShape<'a> { /// A triangle shape. Triangle(&'a Triangle), /// A triangle mesh shape. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] TriMesh(&'a TriMesh), /// A set of segments. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] Polyline(&'a Polyline), /// A shape representing a full half-space. HalfSpace(&'a HalfSpace), /// A heightfield shape. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] HeightField(&'a HeightField), /// A Compound shape. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] Compound(&'a Compound), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] ConvexPolygon(&'a ConvexPolygon), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] /// A convex polyhedron. ConvexPolyhedron(&'a ConvexPolyhedron), #[cfg(feature = "dim3")] @@ -144,11 +147,11 @@ pub enum TypedShape<'a> { RoundCone(&'a RoundCone), /// A convex polyhedron with rounded corners. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] RoundConvexPolyhedron(&'a RoundConvexPolyhedron), /// A convex polygon with rounded corners. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] RoundConvexPolygon(&'a RoundConvexPolygon), /// A custom user-defined shape with a type identified by a number. Custom(u32), @@ -170,24 +173,24 @@ pub(crate) enum DeserializableTypedShape { /// A triangle shape. Triangle(Triangle), /// A triangle mesh shape. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] TriMesh(TriMesh), /// A set of segments. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] Polyline(Polyline), /// A shape representing a full half-space. HalfSpace(HalfSpace), /// A heightfield shape. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] HeightField(HeightField), /// A Compound shape. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] Compound(Compound), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] ConvexPolygon(ConvexPolygon), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] /// A convex polyhedron. ConvexPolyhedron(ConvexPolyhedron), #[cfg(feature = "dim3")] @@ -214,11 +217,11 @@ pub(crate) enum DeserializableTypedShape { RoundCone(RoundCone), /// A convex polyhedron with rounded corners. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] RoundConvexPolyhedron(RoundConvexPolyhedron), /// A convex polygon with rounded corners. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] RoundConvexPolygon(RoundConvexPolygon), /// A custom user-defined shape identified by a number. Custom(u32), @@ -234,20 +237,20 @@ impl DeserializableTypedShape { DeserializableTypedShape::Capsule(s) => Some(SharedShape::new(s)), DeserializableTypedShape::Segment(s) => Some(SharedShape::new(s)), DeserializableTypedShape::Triangle(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::TriMesh(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::Polyline(s) => Some(SharedShape::new(s)), DeserializableTypedShape::HalfSpace(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::HeightField(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::Compound(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::ConvexPolygon(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::ConvexPolyhedron(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim3")] DeserializableTypedShape::Cylinder(s) => Some(SharedShape::new(s)), @@ -260,10 +263,10 @@ impl DeserializableTypedShape { #[cfg(feature = "dim3")] DeserializableTypedShape::RoundCone(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::RoundConvexPolyhedron(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] DeserializableTypedShape::RoundConvexPolygon(s) => Some(SharedShape::new(s)), DeserializableTypedShape::Custom(_) => None, } @@ -278,7 +281,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { fn compute_local_bounding_sphere(&self) -> BoundingSphere; /// Clones this shape into a boxed trait-object. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box; /// Computes the [`Aabb`] of this shape with the given position. @@ -323,7 +326,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { None } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { None } @@ -422,45 +425,45 @@ impl dyn Shape { } /// Converts this abstract shape to a compound shape, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_compound(&self) -> Option<&Compound> { self.downcast_ref() } /// Converts this abstract shape to a mutable compound shape, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_compound_mut(&mut self) -> Option<&mut Compound> { self.downcast_mut() } /// Converts this abstract shape to a triangle mesh, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_trimesh(&self) -> Option<&TriMesh> { self.downcast_ref() } /// Converts this abstract shape to a mutable triangle mesh, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_trimesh_mut(&mut self) -> Option<&mut TriMesh> { self.downcast_mut() } /// Converts this abstract shape to a polyline, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_polyline(&self) -> Option<&Polyline> { self.downcast_ref() } /// Converts this abstract shape to a mutable polyline, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_polyline_mut(&mut self) -> Option<&mut Polyline> { self.downcast_mut() } /// Converts this abstract shape to a heightfield, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_heightfield(&self) -> Option<&HeightField> { self.downcast_ref() } /// Converts this abstract shape to a mutable heightfield, if it is one. - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_heightfield_mut(&mut self) -> Option<&mut HeightField> { self.downcast_mut() } @@ -485,37 +488,37 @@ impl dyn Shape { /// Converts this abstract shape to a convex polygon, if it is one. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_convex_polygon(&self) -> Option<&ConvexPolygon> { self.downcast_ref() } /// Converts this abstract shape to a mutable convex polygon, if it is one. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_convex_polygon_mut(&mut self) -> Option<&mut ConvexPolygon> { self.downcast_mut() } /// Converts this abstract shape to a round convex polygon, if it is one. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_round_convex_polygon(&self) -> Option<&RoundConvexPolygon> { self.downcast_ref() } /// Converts this abstract shape to a mutable round convex polygon, if it is one. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_round_convex_polygon_mut(&mut self) -> Option<&mut RoundConvexPolygon> { self.downcast_mut() } #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_convex_polyhedron(&self) -> Option<&ConvexPolyhedron> { self.downcast_ref() } #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_convex_polyhedron_mut(&mut self) -> Option<&mut ConvexPolyhedron> { self.downcast_mut() } @@ -566,20 +569,20 @@ impl dyn Shape { /// Converts this abstract shape to a round convex polyhedron, if it is one. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_round_convex_polyhedron(&self) -> Option<&RoundConvexPolyhedron> { self.downcast_ref() } /// Converts this abstract shape to a mutable round convex polyhedron, if it is one. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn as_round_convex_polyhedron_mut(&mut self) -> Option<&mut RoundConvexPolyhedron> { self.downcast_mut() } } impl Shape for Ball { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -636,7 +639,7 @@ impl Shape for Ball { } impl Shape for Cuboid { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -695,7 +698,7 @@ impl Shape for Cuboid { } impl Shape for Capsule { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -746,7 +749,7 @@ impl Shape for Capsule { } impl Shape for Triangle { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -809,7 +812,7 @@ impl Shape for Triangle { } impl Shape for Segment { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -867,7 +870,7 @@ impl Shape for Segment { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Shape for Compound { fn clone_box(&self) -> Box { Box::new(self.clone()) @@ -909,13 +912,13 @@ impl Shape for Compound { }) } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { Some(self as &dyn SimdCompositeShape) } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Shape for Polyline { fn clone_box(&self) -> Box { Box::new(self.clone()) @@ -955,13 +958,13 @@ impl Shape for Polyline { Real::frac_pi_4() } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { Some(self as &dyn SimdCompositeShape) } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Shape for TriMesh { fn clone_box(&self) -> Box { Box::new(self.clone()) @@ -1002,13 +1005,13 @@ impl Shape for TriMesh { Real::frac_pi_4() } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { Some(self as &dyn SimdCompositeShape) } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Shape for HeightField { fn clone_box(&self) -> Box { Box::new(self.clone()) @@ -1050,7 +1053,7 @@ impl Shape for HeightField { } #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Shape for ConvexPolygon { fn clone_box(&self) -> Box { Box::new(self.clone()) @@ -1113,7 +1116,7 @@ impl Shape for ConvexPolygon { } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Shape for ConvexPolyhedron { fn clone_box(&self) -> Box { Box::new(self.clone()) @@ -1178,7 +1181,7 @@ impl Shape for ConvexPolyhedron { #[cfg(feature = "dim3")] impl Shape for Cylinder { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -1230,7 +1233,7 @@ impl Shape for Cylinder { #[cfg(feature = "dim3")] impl Shape for Cone { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -1284,7 +1287,7 @@ impl Shape for Cone { } impl Shape for HalfSpace { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -1329,7 +1332,7 @@ impl Shape for HalfSpace { macro_rules! impl_shape_for_round_shape( ($($S: ty, $Tag: ident);*) => {$( impl Shape for RoundShape<$S> { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] fn clone_box(&self) -> Box { Box::new(self.clone()) } @@ -1388,7 +1391,7 @@ impl_shape_for_round_shape!( Triangle, RoundTriangle ); #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl_shape_for_round_shape!(ConvexPolygon, RoundConvexPolygon); #[cfg(feature = "dim3")] impl_shape_for_round_shape!( @@ -1397,5 +1400,5 @@ impl_shape_for_round_shape!( ); #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl_shape_for_round_shape!(ConvexPolyhedron, RoundConvexPolyhedron); diff --git a/src/shape/shared_shape.rs b/src/shape/shared_shape.rs index 5935029f..ca2b1096 100644 --- a/src/shape/shared_shape.rs +++ b/src/shape/shared_shape.rs @@ -11,9 +11,14 @@ use crate::shape::{ use crate::shape::{Cone, ConvexPolyhedron, Cylinder}; use crate::transformation::vhacd::{VHACDParameters, VHACD}; use na::Unit; -use std::ops::Deref; +use core::ops::Deref; + +#[cfg(feature = "std")] use std::sync::Arc; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec, sync::Arc}; + /// The shape of a collider. #[derive(Clone)] pub struct SharedShape(pub Arc); diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index c282fbfb..9fa0da27 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -16,7 +16,14 @@ use { std::collections::HashSet, }; -#[cfg(all(feature = "dim2", feature = "std"))] +#[cfg(feature = "alloc")] +use { + crate::shape::composite_shape::SimdCompositeShape, + hashbrown::{HashSet, HashMap, hash_map::Entry}, + alloc::{vec::Vec, vec} +}; + +#[cfg(all(feature = "dim2", any(feature = "std", feature = "alloc")))] use crate::transformation::ear_clipping::triangulate_ear_clipping; #[cfg(feature = "cuda")] @@ -387,7 +394,7 @@ impl CudaTriMesh { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl TriMesh { /// Creates a new triangle mesh from a vertex buffer and an index buffer. pub fn new(vertices: Vec>, indices: Vec<[u32; 3]>) -> Self { @@ -747,7 +754,14 @@ impl TriMesh { /// index buffer if some of the vertices of this trimesh are duplicated. fn compute_pseudo_normals(&mut self) { let mut vertices_pseudo_normal = vec![Vector::zeros(); self.vertices().len()]; + + #[cfg(feature = "alloc")] + let mut edges_pseudo_normal: HashMap, na::Vector3> = HashMap::default(); + #[cfg(feature = "alloc")] + let mut edges_multiplicity: HashMap, i32> = HashMap::default(); + #[cfg(feature = "std")] let mut edges_pseudo_normal = HashMap::default(); + #[cfg(feature = "std")] let mut edges_multiplicity = HashMap::default(); for idx in self.indices() { @@ -855,7 +869,7 @@ impl TriMesh { } let mut topology = TriMeshTopology::::default(); - let mut half_edge_map = HashMap::default(); + let mut half_edge_map: HashMap<(u32, u32), u32> = HashMap::default(); topology.vertices.resize( self.vertices.len(), @@ -1132,7 +1146,7 @@ impl RayCast for TriMesh { */ #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl From> for TriMesh { fn from(heightfield: crate::shape::GenericHeightField) -> Self { let (vtx, idx) = heightfield.to_trimesh(); @@ -1141,7 +1155,7 @@ impl From } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl From for TriMesh { fn from(cuboid: Cuboid) -> Self { let (vtx, idx) = cuboid.to_trimesh(); @@ -1149,7 +1163,7 @@ impl From for TriMesh { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl SimdCompositeShape for TriMesh { fn map_part_at(&self, i: u32, f: &mut dyn FnMut(Option<&Isometry>, &dyn Shape)) { let tri = self.triangle(i); diff --git a/src/shape/trimesh_storage.rs b/src/shape/trimesh_storage.rs index 914ad142..514fef12 100644 --- a/src/shape/trimesh_storage.rs +++ b/src/shape/trimesh_storage.rs @@ -8,6 +8,9 @@ use crate::utils::CudaArray1; #[cfg(feature = "cuda")] use crate::utils::{CudaArrayPointer1, CudaStorage, CudaStoragePtr}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + /// Trait describing all the types needed for storing a triangle mesh’s data. pub trait TriMeshStorage { /// Storage needed to store a Qbvh. @@ -32,7 +35,7 @@ pub trait TriMeshStorage { type ArrayVectorTriple: Array1<[Vector; 3]>; } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl TriMeshStorage for DefaultStorage { type QbvhStorage = Self; type ArrayTopoVertex = Vec; diff --git a/src/transformation/convex_hull2.rs b/src/transformation/convex_hull2.rs index 41832da7..5d30f2f9 100644 --- a/src/transformation/convex_hull2.rs +++ b/src/transformation/convex_hull2.rs @@ -5,6 +5,9 @@ use crate::transformation::convex_hull_utils::{indexed_support_point_id, support use na::{self, Point2, Vector2}; use num_traits::Zero; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + /// Computes the convex hull of a set of 2d points. /// /// The computed convex-hull have its points given in counter-clockwise order. diff --git a/src/transformation/convex_hull3/convex_hull.rs b/src/transformation/convex_hull3/convex_hull.rs index cd59bdfa..d492424d 100644 --- a/src/transformation/convex_hull3/convex_hull.rs +++ b/src/transformation/convex_hull3/convex_hull.rs @@ -6,6 +6,10 @@ use crate::transformation::convex_hull_utils::{indexed_support_point_id, normali use crate::utils; use na::{self, Point3}; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec}; + + /// Computes the convex hull of a set of 3d points. pub fn convex_hull(points: &[Point3]) -> (Vec>, Vec<[u32; 3]>) { try_convex_hull(points).unwrap() diff --git a/src/transformation/convex_hull3/error.rs b/src/transformation/convex_hull3/error.rs index ea879c0f..7299783c 100644 --- a/src/transformation/convex_hull3/error.rs +++ b/src/transformation/convex_hull3/error.rs @@ -13,7 +13,7 @@ pub enum ConvexHullError { } impl std::fmt::Display for ConvexHullError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { ConvexHullError::InternalError(reason) => write!(f, "InternalError({})", reason), ConvexHullError::MissingSupportPoint => write!(f, "MissingSupportPoint"), @@ -22,4 +22,5 @@ impl std::fmt::Display for ConvexHullError { } } +#[cfg(feature = "std")] impl std::error::Error for ConvexHullError {} diff --git a/src/transformation/convex_hull3/initial_mesh.rs b/src/transformation/convex_hull3/initial_mesh.rs index 573687e5..a734e762 100644 --- a/src/transformation/convex_hull3/initial_mesh.rs +++ b/src/transformation/convex_hull3/initial_mesh.rs @@ -7,6 +7,9 @@ use crate::utils; use na::{Point2, Point3, Vector3}; use std::cmp::Ordering; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec}; + #[derive(Debug)] pub enum InitialMesh { Facets(Vec), diff --git a/src/transformation/convex_hull3/triangle_facet.rs b/src/transformation/convex_hull3/triangle_facet.rs index fe1a0a0b..2960190c 100644 --- a/src/transformation/convex_hull3/triangle_facet.rs +++ b/src/transformation/convex_hull3/triangle_facet.rs @@ -3,6 +3,9 @@ use crate::shape::Triangle; use na::{Point3, Vector3}; use num::Bounded; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + #[derive(Debug)] pub struct TriangleFacet { pub valid: bool, diff --git a/src/transformation/convex_hull3/validation.rs b/src/transformation/convex_hull3/validation.rs index a4c62352..96bd6854 100644 --- a/src/transformation/convex_hull3/validation.rs +++ b/src/transformation/convex_hull3/validation.rs @@ -29,7 +29,10 @@ pub fn check_facet_links(ifacet: usize, facets: &[TriangleFacet]) { pub fn check_convex_hull(points: &[Point3], triangles: &[[u32; 3]]) { use crate::utils::hashmap::{Entry, HashMap}; use crate::utils::SortedPair; + #[cfg(feature = "std")] let mut edges = HashMap::default(); + #[cfg(feature = "alloc")] + let mut edges: HashMap, EdgeData> = HashMap::default(); struct EdgeData { adjascent_triangles: [usize; 2], @@ -46,6 +49,7 @@ pub fn check_convex_hull(points: &[Point3], triangles: &[[u32; 3]]) { for i in 0..points.len() { for j in i + 1..points.len() { if points[i] == points[j] { + #[cfg(feature = "std")] println!("Duplicate: {}", points[i]); panic!("Found duplicate points.") } diff --git a/src/transformation/ear_clipping.rs b/src/transformation/ear_clipping.rs index faacc9cc..a070f5d1 100644 --- a/src/transformation/ear_clipping.rs +++ b/src/transformation/ear_clipping.rs @@ -6,6 +6,9 @@ use crate::{ utils::point_in_triangle::{corner_direction, is_point_in_triangle, Orientation}, }; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec}; + /// The information stored for each vertex in the ear clipping algorithm. #[derive(Clone, Default)] struct VertexInfo { diff --git a/src/transformation/hertel_mehlhorn.rs b/src/transformation/hertel_mehlhorn.rs index 208b9193..88a6b0ba 100644 --- a/src/transformation/hertel_mehlhorn.rs +++ b/src/transformation/hertel_mehlhorn.rs @@ -4,6 +4,9 @@ use crate::math::{Point, Real}; use crate::utils::point_in_triangle::{corner_direction, Orientation}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + /// Checks if the counter-clockwise polygon `poly` has an edge going counter-clockwise from `p1` to `p2`. /// Returns the edge point's indices in the second polygon. Returns `None` if none were found. fn find_edge_index_in_polygon(p1: u32, p2: u32, indices: &[u32]) -> Option<(usize, usize)> { diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index a473c459..a4a450fd 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -4,8 +4,15 @@ use crate::query::{visitors::BoundingVolumeIntersectionsSimultaneousVisitor, Poi use crate::shape::{FeatureId, TriMesh, Triangle}; use crate::utils::WBasis; use na::{Point2, Vector2}; +#[cfg(any(feature = "std", feature = "alloc"))] use spade::{handles::FixedVertexHandle, ConstrainedDelaunayTriangulation, Triangulation as _}; + +#[cfg(feature = "std")] use std::collections::{HashMap, HashSet}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; +#[cfg(feature = "alloc")] +use hashbrown::{HashMap, HashSet}; /// Computes the intersection of two meshes. /// diff --git a/src/transformation/mesh_intersection/mod.rs b/src/transformation/mesh_intersection/mod.rs index e9b0d6b9..aef45080 100644 --- a/src/transformation/mesh_intersection/mod.rs +++ b/src/transformation/mesh_intersection/mod.rs @@ -1,11 +1,16 @@ +use crate::math::Real; + +// std required mostly due to spade which is not no_std + +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::mesh_intersection::intersect_meshes; pub use self::mesh_intersection_error::MeshIntersectionError; pub(self) use triangle_triangle_intersection::*; -use crate::math::Real; - +#[cfg(any(feature = "std", feature = "alloc"))] mod mesh_intersection; mod mesh_intersection_error; + mod triangle_triangle_intersection; pub(self) const EPS: Real = 1.0e-6; diff --git a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs index 038b6664..f2e30fbe 100644 --- a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs +++ b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs @@ -5,6 +5,9 @@ use crate::shape::{FeatureId, Segment, Triangle}; use crate::transformation::polygon_intersection::PolylinePointLocation; use crate::utils::WBasis; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + #[derive(Copy, Clone, Debug, Default)] pub struct TriangleTriangleIntersectionPoint { pub p1: Point, diff --git a/src/transformation/mod.rs b/src/transformation/mod.rs index 93fd346e..4b31e9b2 100644 --- a/src/transformation/mod.rs +++ b/src/transformation/mod.rs @@ -6,7 +6,7 @@ pub(crate) use self::convex_hull2::convex_hull2_idx; pub use self::convex_hull2::{convex_hull2 as convex_hull, convex_hull2_idx as convex_hull_idx}; #[cfg(feature = "dim3")] pub use self::convex_hull3::{check_convex_hull, convex_hull, try_convex_hull, ConvexHullError}; -#[cfg(feature = "dim3")] +#[cfg(all(feature = "dim3", any(feature = "std", feature = "alloc")))] pub use self::mesh_intersection::intersect_meshes; pub use self::polygon_intersection::{ convex_polygons_intersection, convex_polygons_intersection_points, @@ -18,8 +18,10 @@ mod convex_hull3; pub(crate) mod convex_hull_utils; mod polygon_intersection; +#[cfg(any(feature = "std", feature = "alloc"))] /// Approximate convex decomposition using the VHACD algorithm. pub mod vhacd; +#[cfg(any(feature = "std", feature = "alloc"))] /// Voxelization of a 2D polyline or 3D triangle mesh. pub mod voxelization; diff --git a/src/transformation/polygon_intersection.rs b/src/transformation/polygon_intersection.rs index 6e78f6cb..618e0a2e 100644 --- a/src/transformation/polygon_intersection.rs +++ b/src/transformation/polygon_intersection.rs @@ -4,6 +4,9 @@ use crate::math::Real; use crate::shape::{SegmentPointLocation, Triangle, TriangleOrientation}; use crate::utils::{self, SegmentsIntersection}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + #[derive(Copy, Clone, Debug, PartialEq, Eq)] enum InFlag { PIn, diff --git a/src/transformation/to_outline/ball_to_outline.rs b/src/transformation/to_outline/ball_to_outline.rs index 0d645efc..6c962922 100644 --- a/src/transformation/to_outline/ball_to_outline.rs +++ b/src/transformation/to_outline/ball_to_outline.rs @@ -6,6 +6,9 @@ use na::{self, Point3, RealField}; #[cfg(not(feature = "std"))] use na::ComplexField; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + impl Ball { /// Outlines this ball’s shape using polylines. pub fn to_outline(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/capsule_to_outline.rs b/src/transformation/to_outline/capsule_to_outline.rs index 9edc8c2a..b5d1c5a6 100644 --- a/src/transformation/to_outline/capsule_to_outline.rs +++ b/src/transformation/to_outline/capsule_to_outline.rs @@ -3,6 +3,9 @@ use crate::shape::{Capsule, Cylinder}; use crate::transformation::utils; use na::{self, Point3}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + impl Capsule { /// Outlines this capsule’s shape using polylines. pub fn to_outline(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/cone_to_outline.rs b/src/transformation/to_outline/cone_to_outline.rs index 1934b459..4268ac01 100644 --- a/src/transformation/to_outline/cone_to_outline.rs +++ b/src/transformation/to_outline/cone_to_outline.rs @@ -3,6 +3,9 @@ use crate::shape::Cone; use crate::transformation::utils; use na::{self, Point3, Vector3}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl Cone { /// Outlines this cone’s shape using polylines. pub fn to_outline(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/convex_polyhedron_to_outline.rs b/src/transformation/to_outline/convex_polyhedron_to_outline.rs index 53595249..30d8558d 100644 --- a/src/transformation/to_outline/convex_polyhedron_to_outline.rs +++ b/src/transformation/to_outline/convex_polyhedron_to_outline.rs @@ -2,6 +2,9 @@ use crate::math::Real; use crate::shape::ConvexPolyhedron; use na::Point3; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + impl ConvexPolyhedron { /// Outlines this convex polyhedron’s shape using polylines. pub fn to_outline(&self) -> (Vec>, Vec<[u32; 3]>) { diff --git a/src/transformation/to_outline/cuboid_to_outline.rs b/src/transformation/to_outline/cuboid_to_outline.rs index 0552d07a..d4aec9bc 100644 --- a/src/transformation/to_outline/cuboid_to_outline.rs +++ b/src/transformation/to_outline/cuboid_to_outline.rs @@ -3,6 +3,9 @@ use crate::math::{Point, Real, Vector}; use crate::shape::Cuboid; use crate::transformation::utils; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl Aabb { /// Outlines this Aabb’s shape using polylines. pub fn to_outline(&self) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/cylinder_to_outline.rs b/src/transformation/to_outline/cylinder_to_outline.rs index 64e5ca0b..804171f2 100644 --- a/src/transformation/to_outline/cylinder_to_outline.rs +++ b/src/transformation/to_outline/cylinder_to_outline.rs @@ -3,6 +3,9 @@ use crate::shape::Cylinder; use crate::transformation::utils; use na::{self, Point3, Vector3}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl Cylinder { /// Outlines this cylinder’s shape using polylines. pub fn to_outline(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/heightfield_to_outline.rs b/src/transformation/to_outline/heightfield_to_outline.rs index 13e7a597..276edc68 100644 --- a/src/transformation/to_outline/heightfield_to_outline.rs +++ b/src/transformation/to_outline/heightfield_to_outline.rs @@ -2,6 +2,9 @@ use crate::math::Real; use crate::shape::{GenericHeightField, HeightFieldCellStatus, HeightFieldStorage}; use na::Point3; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + impl GenericHeightField { /// Outlines this heightfield’s shape using polylines. pub fn to_outline(&self) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/round_cone_to_outline.rs b/src/transformation/to_outline/round_cone_to_outline.rs index cb1e3c86..dc6c7927 100644 --- a/src/transformation/to_outline/round_cone_to_outline.rs +++ b/src/transformation/to_outline/round_cone_to_outline.rs @@ -3,6 +3,9 @@ use crate::shape::RoundCone; use crate::transformation::utils; use na::{self, Point3, Vector3}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundCone { /// Outlines this round cone’s shape using polylines. pub fn to_outline( diff --git a/src/transformation/to_outline/round_convex_polyhedron_to_outline.rs b/src/transformation/to_outline/round_convex_polyhedron_to_outline.rs index 0cf49766..f463278e 100644 --- a/src/transformation/to_outline/round_convex_polyhedron_to_outline.rs +++ b/src/transformation/to_outline/round_convex_polyhedron_to_outline.rs @@ -3,6 +3,9 @@ use crate::shape::RoundConvexPolyhedron; use crate::transformation::utils; use na::Point3; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundConvexPolyhedron { /// Outlines this round convex polyhedron’s shape using polylines. pub fn to_outline(&self, nsubdivs: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/round_cuboid_to_outline.rs b/src/transformation/to_outline/round_cuboid_to_outline.rs index a8366ad3..5e503025 100644 --- a/src/transformation/to_outline/round_cuboid_to_outline.rs +++ b/src/transformation/to_outline/round_cuboid_to_outline.rs @@ -3,6 +3,9 @@ use crate::math::{Point, Real, Vector}; use crate::shape::RoundCuboid; use crate::transformation::utils; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundCuboid { /// Outlines this round cuboid’s surface with polylines. pub fn to_outline(&self, nsubdivs: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_outline/round_cylinder_to_outline.rs b/src/transformation/to_outline/round_cylinder_to_outline.rs index 3cc600ab..a084535b 100644 --- a/src/transformation/to_outline/round_cylinder_to_outline.rs +++ b/src/transformation/to_outline/round_cylinder_to_outline.rs @@ -3,6 +3,9 @@ use crate::shape::RoundCylinder; use crate::transformation::utils; use na::{self, Point3}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundCylinder { /// Outlines this round cylinder’s shape using polylines. pub fn to_outline( diff --git a/src/transformation/to_outline/round_triangle_to_outline.rs b/src/transformation/to_outline/round_triangle_to_outline.rs index a2c12e6c..7b0ae3a7 100644 --- a/src/transformation/to_outline/round_triangle_to_outline.rs +++ b/src/transformation/to_outline/round_triangle_to_outline.rs @@ -3,6 +3,9 @@ use crate::math::{Point, Real, Vector}; use crate::shape::RoundTriangle; use crate::transformation::utils; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundTriangle { /// Outlines this round triangle’s surface with polylines. pub fn to_outline(&self, nsubdivs: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_polyline/ball_to_polyline.rs b/src/transformation/to_polyline/ball_to_polyline.rs index adb0938a..aa33a95d 100644 --- a/src/transformation/to_polyline/ball_to_polyline.rs +++ b/src/transformation/to_polyline/ball_to_polyline.rs @@ -3,6 +3,9 @@ use crate::shape::Ball; use crate::transformation::utils; use na::{self, Point2, RealField}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + impl Ball { /// Discretize the boundary of this ball as a polygonal line. pub fn to_polyline(&self, nsubdivs: u32) -> Vec> { diff --git a/src/transformation/to_polyline/capsule_to_polyline.rs b/src/transformation/to_polyline/capsule_to_polyline.rs index 33d0ad38..581b8326 100644 --- a/src/transformation/to_polyline/capsule_to_polyline.rs +++ b/src/transformation/to_polyline/capsule_to_polyline.rs @@ -3,6 +3,9 @@ use crate::shape::Capsule; use crate::transformation::utils; use na::{self, Point2, RealField, Vector2}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec}; + impl Capsule { /// Discretize the boundary of this capsule as a polygonal line. pub fn to_polyline(&self, nsubdiv: u32) -> Vec> { diff --git a/src/transformation/to_polyline/cuboid_to_polyline.rs b/src/transformation/to_polyline/cuboid_to_polyline.rs index c644b201..e26adc7a 100644 --- a/src/transformation/to_polyline/cuboid_to_polyline.rs +++ b/src/transformation/to_polyline/cuboid_to_polyline.rs @@ -3,6 +3,9 @@ use crate::shape::Cuboid; use crate::transformation::utils; use na::{self, Point2}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl Cuboid { /// Discretize the boundary of this cuboid as a polygonal line. pub fn to_polyline(&self) -> Vec> { diff --git a/src/transformation/to_polyline/heightfield_to_polyline.rs b/src/transformation/to_polyline/heightfield_to_polyline.rs index 4e8df586..f01e0a06 100644 --- a/src/transformation/to_polyline/heightfield_to_polyline.rs +++ b/src/transformation/to_polyline/heightfield_to_polyline.rs @@ -2,6 +2,9 @@ use crate::math::Real; use crate::shape::HeightField; use na::Point2; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl HeightField { /// Rasterize this heightfield as a (potentially discontinuous) polyline. pub fn to_polyline(&self) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/transformation/to_polyline/round_convex_polygon_to_polyline.rs b/src/transformation/to_polyline/round_convex_polygon_to_polyline.rs index 617eb609..21bfad83 100644 --- a/src/transformation/to_polyline/round_convex_polygon_to_polyline.rs +++ b/src/transformation/to_polyline/round_convex_polygon_to_polyline.rs @@ -3,6 +3,9 @@ use crate::shape::RoundConvexPolygon; use crate::transformation::utils; use na::{self, Point2}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundConvexPolygon { /// Discretize the boundary of this round convex polygon as a polygonal line. pub fn to_polyline(&self, border_subdivs: u32) -> Vec> { diff --git a/src/transformation/to_polyline/round_cuboid_to_polyline.rs b/src/transformation/to_polyline/round_cuboid_to_polyline.rs index 3eaf2e03..c2de333e 100644 --- a/src/transformation/to_polyline/round_cuboid_to_polyline.rs +++ b/src/transformation/to_polyline/round_cuboid_to_polyline.rs @@ -3,6 +3,9 @@ use crate::shape::RoundCuboid; use crate::transformation::utils; use na::{self, Point2}; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, vec}; + impl RoundCuboid { /// Discretize the boundary of this round cuboid as a polygonal line. pub fn to_polyline(&self, border_subdivs: u32) -> Vec> { diff --git a/src/transformation/to_trimesh/ball_to_trimesh.rs b/src/transformation/to_trimesh/ball_to_trimesh.rs index cfe41ba4..c546db2b 100644 --- a/src/transformation/to_trimesh/ball_to_trimesh.rs +++ b/src/transformation/to_trimesh/ball_to_trimesh.rs @@ -3,6 +3,9 @@ use crate::shape::Ball; use crate::transformation::utils; use na::{self, ComplexField, Point3, RealField}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl Ball { /// Discretize the boundary of this ball as a triangle-mesh. pub fn to_trimesh( diff --git a/src/transformation/to_trimesh/capsule_to_trimesh.rs b/src/transformation/to_trimesh/capsule_to_trimesh.rs index 9fd12880..0d652edd 100644 --- a/src/transformation/to_trimesh/capsule_to_trimesh.rs +++ b/src/transformation/to_trimesh/capsule_to_trimesh.rs @@ -3,6 +3,9 @@ use crate::shape::Capsule; use crate::transformation::utils; use na::{self, Point3}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl Capsule { /// Discretize the boundary of this capsule as a triangle-mesh. pub fn to_trimesh( diff --git a/src/transformation/to_trimesh/cone_to_trimesh.rs b/src/transformation/to_trimesh/cone_to_trimesh.rs index f9f6a447..845ab59d 100644 --- a/src/transformation/to_trimesh/cone_to_trimesh.rs +++ b/src/transformation/to_trimesh/cone_to_trimesh.rs @@ -3,6 +3,9 @@ use crate::shape::Cone; use crate::transformation::utils; use na::{self, Point3, RealField, Vector3}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl Cone { /// Discretize the boundary of this cone as a triangle-mesh. pub fn to_trimesh(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 3]>) { diff --git a/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs b/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs index c86c2b18..b28cdfdf 100644 --- a/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs +++ b/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs @@ -2,6 +2,9 @@ use crate::math::Real; use crate::shape::ConvexPolyhedron; use na::Point3; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl ConvexPolyhedron { /// Discretize the boundary of this convex polyhedron as a triangle-mesh. pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { diff --git a/src/transformation/to_trimesh/cuboid_to_trimesh.rs b/src/transformation/to_trimesh/cuboid_to_trimesh.rs index 1c763a22..e4b6ec62 100644 --- a/src/transformation/to_trimesh/cuboid_to_trimesh.rs +++ b/src/transformation/to_trimesh/cuboid_to_trimesh.rs @@ -4,6 +4,9 @@ use crate::shape::Cuboid; use crate::transformation::utils; use na::{self, Point3}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl Aabb { /// Discretize the boundary of this Aabb as a triangle-mesh. pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { diff --git a/src/transformation/to_trimesh/cylinder_to_trimesh.rs b/src/transformation/to_trimesh/cylinder_to_trimesh.rs index d9c7c730..56d2bc18 100644 --- a/src/transformation/to_trimesh/cylinder_to_trimesh.rs +++ b/src/transformation/to_trimesh/cylinder_to_trimesh.rs @@ -3,6 +3,9 @@ use crate::shape::Cylinder; use crate::transformation::utils; use na::{self, Point3, RealField, Vector3}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl Cylinder { /// Discretize the boundary of this cylinder as a triangle-mesh. pub fn to_trimesh(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 3]>) { diff --git a/src/transformation/to_trimesh/heightfield_to_trimesh.rs b/src/transformation/to_trimesh/heightfield_to_trimesh.rs index 6e615d38..9666099b 100644 --- a/src/transformation/to_trimesh/heightfield_to_trimesh.rs +++ b/src/transformation/to_trimesh/heightfield_to_trimesh.rs @@ -2,6 +2,9 @@ use crate::math::Real; use crate::shape::{GenericHeightField, HeightFieldStorage}; use na::Point3; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + impl GenericHeightField { /// Discretize the boundary of this heightfield as a triangle-mesh. pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { diff --git a/src/transformation/utils.rs b/src/transformation/utils.rs index 978541d2..e8321e07 100644 --- a/src/transformation/utils.rs +++ b/src/transformation/utils.rs @@ -5,6 +5,9 @@ use crate::na::ComplexField; #[cfg(feature = "dim3")] use {crate::math::DIM, num::Zero}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + /// Applies in-place a transformation to an array of points. pub fn transform(points: &mut [Point], m: Isometry) { points.iter_mut().for_each(|p| *p = m * *p); diff --git a/src/transformation/vhacd/vhacd.rs b/src/transformation/vhacd/vhacd.rs index f7fd489b..f441f1f8 100644 --- a/src/transformation/vhacd/vhacd.rs +++ b/src/transformation/vhacd/vhacd.rs @@ -19,8 +19,16 @@ use crate::math::{Point, Real, Vector, DIM}; use crate::transformation::vhacd::VHACDParameters; use crate::transformation::voxelization::{VoxelSet, VoxelizedVolume}; + +#[cfg(feature = "std")] use std::sync::Arc; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, sync::Arc}; + +#[cfg(not(feature = "std"))] +use na::ComplexField; + #[cfg(feature = "dim2")] type ConvexHull = Vec>; #[cfg(feature = "dim3")] diff --git a/src/transformation/voxelization/voxel_set.rs b/src/transformation/voxelization/voxel_set.rs index 2f9a3f37..2244c75a 100644 --- a/src/transformation/voxelization/voxel_set.rs +++ b/src/transformation/voxelization/voxel_set.rs @@ -20,8 +20,13 @@ use super::{FillMode, VoxelizedVolume}; use crate::bounding_volume::Aabb; use crate::math::{Matrix, Point, Real, Vector, DIM}; use crate::transformation::vhacd::CutPlane; + +#[cfg(feature = "std")] use std::sync::Arc; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec, sync::Arc}; + #[cfg(feature = "dim2")] type ConvexHull = Vec>; #[cfg(feature = "dim3")] diff --git a/src/transformation/voxelization/voxelized_volume.rs b/src/transformation/voxelization/voxelized_volume.rs index d4eee154..16534e66 100644 --- a/src/transformation/voxelization/voxelized_volume.rs +++ b/src/transformation/voxelization/voxelized_volume.rs @@ -20,8 +20,13 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real, Vector, DIM}; use crate::query; use crate::transformation::voxelization::{Voxel, VoxelSet}; + +#[cfg(feature = "std")] use std::sync::Arc; +#[cfg(feature = "alloc")] +use alloc::{vec::Vec, sync::Arc}; + /// Controls how the voxelization determines which voxel needs /// to be considered empty, and which ones will be considered full. #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/src/utils/array.rs b/src/utils/array.rs index 1eead7e2..b8336fce 100644 --- a/src/utils/array.rs +++ b/src/utils/array.rs @@ -1,7 +1,10 @@ use core::ops::IndexMut; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] use na::{DMatrix, DVector, Scalar}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + /// Abstraction over a 1D array. pub trait Array1: IndexMut { /// The number of heights on this storage. @@ -25,7 +28,7 @@ pub trait Array1: IndexMut { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Array1 for Vec { #[inline] fn len(&self) -> usize { @@ -33,7 +36,7 @@ impl Array1 for Vec { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Array1 for DVector { #[inline] fn len(&self) -> usize { @@ -55,7 +58,7 @@ pub trait Array2 { fn set(&mut self, i: usize, j: usize, val: Self::Item); } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] impl Array2 for DMatrix { type Item = T; diff --git a/src/utils/cleanup.rs b/src/utils/cleanup.rs index b2e853b9..583ec1b6 100644 --- a/src/utils/cleanup.rs +++ b/src/utils/cleanup.rs @@ -1,6 +1,10 @@ use crate::math::{Point, Real}; use std::iter; +#[cfg(feature = "alloc")] +use alloc::{vec, vec::Vec}; + + /// Given an index buffer, remove from `points` every point that is not indexed. pub fn remove_unused_points(points: &mut Vec>, idx: &mut [[u32; 3]]) { let mut used: Vec = iter::repeat(false).take(points.len()).collect(); diff --git a/src/utils/hashmap.rs b/src/utils/hashmap.rs index 934b980e..bfb8a27a 100644 --- a/src/utils/hashmap.rs +++ b/src/utils/hashmap.rs @@ -51,10 +51,12 @@ pub fn deserialize_hashmap_capacity< */ #[cfg(feature = "enhanced-determinism")] pub type FxHashMap32 = indexmap::IndexMap>; -#[cfg(feature = "enhanced-determinism")] +#[cfg(all(feature = "enhanced-determinism", feature = "std"))] pub use {self::FxHashMap32 as HashMap, indexmap::map::Entry}; -#[cfg(not(feature = "enhanced-determinism"))] +#[cfg(all(not(feature = "enhanced-determinism"), feature = "std"))] pub use {rustc_hash::FxHashMap as HashMap, std::collections::hash_map::Entry}; +#[cfg(all(not(feature = "std"), feature = "alloc"))] +pub use {hashbrown::HashMap, hashbrown::hash_map::Entry}; const K: u32 = 0x9e3779b9; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index c6001272..349e7b27 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -6,7 +6,7 @@ pub use self::center::center; pub use self::deterministic_state::DeterministicState; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub use self::cleanup::remove_unused_points; pub(crate) use self::inv::inv; pub use self::isometry_ops::{IsometryOps, IsometryOpt}; @@ -47,7 +47,7 @@ mod as_bytes; mod ccw_face_normal; mod center; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] mod cleanup; mod consts; mod cov; @@ -58,7 +58,7 @@ mod cuda_device_pointer; #[cfg(feature = "std")] mod deterministic_state; mod hashable_partial_eq; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "alloc"))] pub mod hashmap; #[cfg(feature = "std")] mod interval;