From 735d1df0b3321b4a34b040451f93d3e8eea7f714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 28 Apr 2024 17:24:05 +0200 Subject: [PATCH] fix no-std build --- src/bounding_volume/mod.rs | 2 ++ src/partitioning/mod.rs | 1 + src/partitioning/visitor.rs | 6 ++++++ src/query/default_query_dispatcher.rs | 4 ++-- src/query/mod.rs | 1 + src/query/point/mod.rs | 2 ++ src/query/point/point_composite_shape.rs | 4 ---- src/query/query_dispatcher.rs | 6 ++++-- src/query/ray/mod.rs | 1 + src/query/visitors/mod.rs | 12 ------------ src/shape/composite_shape.rs | 1 + src/shape/mod.rs | 13 ++++++++++--- src/shape/triangle_pseudo_normals.rs | 5 ++++- src/shape/trimesh.rs | 9 +-------- 14 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/bounding_volume/mod.rs b/src/bounding_volume/mod.rs index 4587f99f..53cfb658 100644 --- a/src/bounding_volume/mod.rs +++ b/src/bounding_volume/mod.rs @@ -23,6 +23,7 @@ mod aabb_convex_polygon; mod aabb_convex_polyhedron; mod aabb_cuboid; mod aabb_halfspace; +#[cfg(feature = "std")] mod aabb_heightfield; mod aabb_support_map; mod aabb_triangle; @@ -45,6 +46,7 @@ mod bounding_sphere_cuboid; #[cfg(feature = "dim3")] mod bounding_sphere_cylinder; mod bounding_sphere_halfspace; +#[cfg(feature = "std")] mod bounding_sphere_heightfield; #[cfg(feature = "std")] mod bounding_sphere_polyline; diff --git a/src/partitioning/mod.rs b/src/partitioning/mod.rs index 0aa07138..cf86ef42 100644 --- a/src/partitioning/mod.rs +++ b/src/partitioning/mod.rs @@ -14,6 +14,7 @@ pub use self::visitor::{ /// A quaternary bounding-volume-hierarchy. #[deprecated(note = "Renamed to Qbvh")] +#[cfg(feature = "std")] pub type SimdQbvh = Qbvh; #[cfg(feature = "std")] diff --git a/src/partitioning/visitor.rs b/src/partitioning/visitor.rs index 5d9b899b..dc751c94 100644 --- a/src/partitioning/visitor.rs +++ b/src/partitioning/visitor.rs @@ -1,5 +1,8 @@ use crate::math::{Real, SimdBool, SimdReal, SIMD_WIDTH}; + +#[cfg(feature = "std")] use crate::partitioning::qbvh::QbvhNode; +#[cfg(feature = "std")] use crate::partitioning::SimdNodeIndex; /// The next action to be taken by a BVH traversal algorithm after having visited a node with some data. @@ -116,6 +119,7 @@ pub trait SimdSimultaneousVisitor { */ /// Trait implemented by visitor called during the parallel traversal of a spatial partitioning data structure. +#[cfg(feature = "std")] pub trait ParallelSimdVisitor: Sync { /// Execute an operation on the content of a node of the spatial partitioning structure. /// @@ -129,6 +133,7 @@ pub trait ParallelSimdVisitor: Sync { ) -> SimdVisitStatus; } +#[cfg(feature = "std")] impl ParallelSimdVisitor for F where F: Sync + Fn(&QbvhNode, Option<[Option<&LeafData>; SIMD_WIDTH]>) -> SimdVisitStatus, @@ -146,6 +151,7 @@ where /// Trait implemented by visitor called during a parallel simultaneous spatial partitioning /// data structure traversal. #[cfg(feature = "parallel")] +#[cfg(feature = "std")] pub trait ParallelSimdSimultaneousVisitor: Sync { /// Visitor state data that will be passed down the recursion. type Data: Copy + Sync + Default; diff --git a/src/query/default_query_dispatcher.rs b/src/query/default_query_dispatcher.rs index 626ba5bd..2b826eca 100644 --- a/src/query/default_query_dispatcher.rs +++ b/src/query/default_query_dispatcher.rs @@ -1,12 +1,12 @@ use crate::math::{Isometry, Point, Real, Vector}; -use crate::query::contact_manifolds::NormalConstraints; use crate::query::{ self, details::NonlinearTOIMode, ClosestPoints, Contact, NonlinearRigidMotion, QueryDispatcher, Unsupported, TOI, }; #[cfg(feature = "std")] use crate::query::{ - contact_manifolds::ContactManifoldsWorkspace, query_dispatcher::PersistentQueryDispatcher, + contact_manifolds::{ContactManifoldsWorkspace, NormalConstraints}, + query_dispatcher::PersistentQueryDispatcher, ContactManifold, }; use crate::shape::{HalfSpace, Segment, Shape, ShapeType}; diff --git a/src/query/mod.rs b/src/query/mod.rs index f95dc1cf..763d8cd0 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -63,6 +63,7 @@ mod ray; pub mod sat; mod split; mod time_of_impact; +#[cfg(feature = "std")] pub mod visitors; /// Queries dedicated to specific pairs of shapes. diff --git a/src/query/point/mod.rs b/src/query/point/mod.rs index f59160b1..2e3e3067 100644 --- a/src/query/point/mod.rs +++ b/src/query/point/mod.rs @@ -14,6 +14,7 @@ mod point_aabb; mod point_ball; mod point_bounding_sphere; mod point_capsule; +#[cfg(feature = "std")] mod point_composite_shape; #[cfg(feature = "dim3")] mod point_cone; @@ -21,6 +22,7 @@ mod point_cuboid; #[cfg(feature = "dim3")] mod point_cylinder; mod point_halfspace; +#[cfg(feature = "std")] mod point_heightfield; #[doc(hidden)] pub mod point_query; diff --git a/src/query/point/point_composite_shape.rs b/src/query/point/point_composite_shape.rs index 502d5d50..d28dd5b5 100644 --- a/src/query/point/point_composite_shape.rs +++ b/src/query/point/point_composite_shape.rs @@ -11,10 +11,8 @@ use crate::shape::{ use na; use simba::simd::{SimdBool as _, SimdPartialOrd, SimdValue}; -#[cfg(feature = "std")] use crate::shape::{Compound, Polyline}; -#[cfg(feature = "std")] impl PointQuery for Polyline { #[inline] fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { @@ -100,7 +98,6 @@ impl PointQuery for TriMesh { } } -#[cfg(feature = "std")] impl PointQuery for Compound { #[inline] fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { @@ -124,7 +121,6 @@ impl PointQuery for Compound { } } -#[cfg(feature = "std")] impl PointQueryWithLocation for Polyline { type Location = (u32, SegmentPointLocation); diff --git a/src/query/query_dispatcher.rs b/src/query/query_dispatcher.rs index 61780596..203e73f0 100644 --- a/src/query/query_dispatcher.rs +++ b/src/query/query_dispatcher.rs @@ -1,7 +1,9 @@ use crate::math::{Isometry, Real, Vector}; -use crate::query::contact_manifolds::NormalConstraints; #[cfg(feature = "std")] -use crate::query::{contact_manifolds::ContactManifoldsWorkspace, ContactManifold}; +use crate::query::{ + contact_manifolds::{ContactManifoldsWorkspace, NormalConstraints}, + ContactManifold, +}; use crate::query::{ClosestPoints, Contact, NonlinearRigidMotion, Unsupported, TOI}; use crate::shape::Shape; diff --git a/src/query/ray/mod.rs b/src/query/ray/mod.rs index 654a0479..71c90f7b 100644 --- a/src/query/ray/mod.rs +++ b/src/query/ray/mod.rs @@ -22,6 +22,7 @@ mod ray_bounding_sphere; mod ray_composite_shape; mod ray_cuboid; mod ray_halfspace; +#[cfg(feature = "std")] mod ray_heightfield; mod ray_round_shape; mod ray_support_map; diff --git a/src/query/visitors/mod.rs b/src/query/visitors/mod.rs index 80b40e25..6b5a3e34 100644 --- a/src/query/visitors/mod.rs +++ b/src/query/visitors/mod.rs @@ -1,29 +1,17 @@ //! Visitors for performing geometric queries exploiting spatial partitioning data structures. -#[cfg(feature = "std")] pub use self::aabb_sets_interferences_collector::AabbSetsInterferencesCollector; -#[cfg(feature = "std")] pub use self::bounding_volume_intersections_simultaneous_visitor::BoundingVolumeIntersectionsSimultaneousVisitor; -#[cfg(feature = "std")] pub use self::bounding_volume_intersections_visitor::BoundingVolumeIntersectionsVisitor; -#[cfg(feature = "std")] pub use self::composite_closest_point_visitor::CompositeClosestPointVisitor; pub use self::composite_point_containment_test::CompositePointContainmentTest; -#[cfg(feature = "std")] pub use self::point_intersections_visitor::PointIntersectionsVisitor; -#[cfg(feature = "std")] pub use self::ray_intersections_visitor::RayIntersectionsVisitor; -#[cfg(feature = "std")] mod aabb_sets_interferences_collector; -#[cfg(feature = "std")] mod bounding_volume_intersections_simultaneous_visitor; -#[cfg(feature = "std")] mod bounding_volume_intersections_visitor; -#[cfg(feature = "std")] mod composite_closest_point_visitor; mod composite_point_containment_test; -#[cfg(feature = "std")] mod point_intersections_visitor; -#[cfg(feature = "std")] mod ray_intersections_visitor; diff --git a/src/shape/composite_shape.rs b/src/shape/composite_shape.rs index 6a5aa9bb..95571fc2 100644 --- a/src/shape/composite_shape.rs +++ b/src/shape/composite_shape.rs @@ -20,6 +20,7 @@ pub trait SimdCompositeShape { fn qbvh(&self) -> &Qbvh; } +#[cfg(feature = "std")] pub trait TypedSimdCompositeShape { type PartShape: ?Sized + Shape; type PartNormalConstraints: ?Sized + NormalConstraints; diff --git a/src/shape/mod.rs b/src/shape/mod.rs index b9c08095..3e115dd7 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -2,8 +2,6 @@ pub use self::ball::Ball; pub use self::capsule::Capsule; -#[doc(inline)] -pub use self::composite_shape::TypedSimdCompositeShape; pub use self::cuboid::Cuboid; pub use self::feature_id::{FeatureId, PackedFeatureId}; pub use self::half_space::HalfSpace; @@ -20,7 +18,9 @@ pub use self::triangle::{Triangle, TriangleOrientation, TrianglePointLocation}; #[cfg(feature = "std")] pub use self::{ - composite_shape::SimdCompositeShape, compound::Compound, polyline::Polyline, + composite_shape::{SimdCompositeShape, TypedSimdCompositeShape}, + compound::Compound, + polyline::Polyline, shared_shape::SharedShape, }; @@ -28,6 +28,7 @@ pub use self::{ #[cfg(feature = "std")] pub use self::convex_polygon::ConvexPolygon; #[cfg(feature = "dim2")] +#[cfg(feature = "std")] pub use self::heightfield2::*; #[cfg(feature = "dim2")] pub use self::polygonal_feature2d::PolygonalFeature; @@ -40,12 +41,14 @@ pub use self::convex_polyhedron::ConvexPolyhedron; #[cfg(feature = "dim3")] pub use self::cylinder::Cylinder; #[cfg(feature = "dim3")] +#[cfg(feature = "std")] pub use self::heightfield3::*; #[cfg(feature = "dim3")] pub use self::polygonal_feature3d::PolygonalFeature; #[cfg(feature = "dim3")] pub use self::tetrahedron::{Tetrahedron, TetrahedronPointLocation}; pub use self::triangle_pseudo_normals::TrianglePseudoNormals; +#[cfg(feature = "std")] pub use self::trimesh::*; /// A cylinder dilated by a sphere (so it has round corners). @@ -69,6 +72,7 @@ pub type RoundConvexPolygon = RoundShape; mod ball; mod capsule; +#[cfg(feature = "std")] #[doc(hidden)] pub mod composite_shape; #[cfg(feature = "std")] @@ -89,6 +93,7 @@ mod triangle; #[cfg(feature = "std")] mod convex_polygon; #[cfg(feature = "dim2")] +#[cfg(feature = "std")] mod heightfield2; #[cfg(feature = "dim3")] @@ -99,12 +104,14 @@ mod convex_polyhedron; #[cfg(feature = "dim3")] mod cylinder; #[cfg(feature = "dim3")] +#[cfg(feature = "std")] mod heightfield3; #[cfg(feature = "dim3")] mod polygonal_feature3d; mod polygonal_feature_map; #[cfg(feature = "dim3")] mod tetrahedron; +#[cfg(feature = "std")] pub(crate) mod trimesh; // TODO: move this elsewhere? mod feature_id; diff --git a/src/shape/triangle_pseudo_normals.rs b/src/shape/triangle_pseudo_normals.rs index 505cace4..c4392c7a 100644 --- a/src/shape/triangle_pseudo_normals.rs +++ b/src/shape/triangle_pseudo_normals.rs @@ -1,7 +1,9 @@ use crate::math::{Real, UnitVector, Vector}; -use crate::query::details::NormalConstraints; use na::Vector3; +#[cfg(feature = "std")] +use crate::query::details::NormalConstraints; + // NOTE: ideally, the normal cone should take into account the point where the normal cone is // considered. But as long as we assume that the triangles are one-way we can get away with // just relying on the normal directions. @@ -26,6 +28,7 @@ pub struct TrianglePseudoNormals { pub edges: [UnitVector; 3], } +#[cfg(feature = "std")] impl NormalConstraints for TrianglePseudoNormals { /// Projects the given direction to it is contained in the polygonal /// cone defined `self`. diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index 5d9643f8..c0d55240 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -8,14 +8,13 @@ use crate::utils::HashablePartialEq; #[cfg(feature = "dim3")] use {crate::shape::Cuboid, crate::utils::SortedPair, na::Unit}; -#[cfg(feature = "std")] use { crate::shape::composite_shape::SimdCompositeShape, crate::utils::hashmap::{Entry, HashMap}, std::collections::HashSet, }; -#[cfg(all(feature = "dim2", feature = "std"))] +#[cfg(feature = "dim2")] use crate::transformation::ear_clipping::triangulate_ear_clipping; use crate::query::details::NormalConstraints; @@ -38,7 +37,6 @@ pub enum TopologyError { }, } -#[cfg(feature = "std")] impl std::fmt::Display for TopologyError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -54,7 +52,6 @@ impl std::fmt::Display for TopologyError { } } -#[cfg(feature = "std")] impl std::error::Error for TopologyError {} /// The set of pseudo-normals of a triangle mesh. @@ -269,7 +266,6 @@ impl fmt::Debug for TriMesh { } } -#[cfg(feature = "std")] 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 { @@ -973,7 +969,6 @@ impl TriMesh { } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] impl From for TriMesh { fn from(heightfield: crate::shape::HeightField) -> Self { let (vtx, idx) = heightfield.to_trimesh(); @@ -982,7 +977,6 @@ impl From for TriMesh { } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] impl From for TriMesh { fn from(cuboid: Cuboid) -> Self { let (vtx, idx) = cuboid.to_trimesh(); @@ -990,7 +984,6 @@ impl From for TriMesh { } } -#[cfg(feature = "std")] impl SimdCompositeShape for TriMesh { fn map_part_at( &self,