From 6f9cdc8fd1ab29dd81c88c494ad6e1c5843a565b Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 04:02:23 +0200 Subject: [PATCH 01/12] Improve `no_std` compatibility (WIP) --- Cargo.toml | 14 +- crates/parry2d-f64/Cargo.toml | 22 ++- crates/parry2d/Cargo.toml | 24 ++- crates/parry2d/examples/common_macroquad2d.rs | 2 +- crates/parry2d/examples/convex_hull2d.rs | 2 +- crates/parry2d/examples/raycasts_animated.rs | 2 +- crates/parry2d/examples/solid_ray_cast2d.rs | 8 +- crates/parry2d/tests/geometry/ray_cast.rs | 26 +-- .../parry2d/tests/geometry/time_of_impact2.rs | 6 +- crates/parry3d-f64/Cargo.toml | 30 ++- crates/parry3d/Cargo.toml | 41 ++++- crates/parry3d/benches/bounding_volume/mod.rs | 14 +- crates/parry3d/benches/common/default_gen.rs | 5 +- crates/parry3d/benches/common/mod.rs | 2 + crates/parry3d/benches/query/ray.rs | 12 +- crates/parry3d/benches/support_map/mod.rs | 6 +- crates/parry3d/examples/bounding_sphere3d.rs | 2 +- crates/parry3d/examples/common_macroquad3d.rs | 13 +- crates/parry3d/examples/convex_hull3d.rs | 2 +- crates/parry3d/examples/getting_started.rs | 2 +- crates/parry3d/examples/solid_ray_cast3d.rs | 8 +- .../parry3d/tests/geometry/cuboid_ray_cast.rs | 6 +- crates/parry3d/tests/geometry/mod.rs | 6 + .../tests/geometry/trimesh_intersection.rs | 13 +- src/bounding_volume/aabb.rs | 3 +- src/bounding_volume/aabb_utils.rs | 2 +- src/bounding_volume/mod.rs | 16 +- src/bounding_volume/simd_aabb.rs | 2 +- src/lib.rs | 14 +- src/mass_properties/mass_properties.rs | 13 +- .../mass_properties_trimesh3d.rs | 2 + src/mass_properties/mod.rs | 16 +- src/partitioning/mod.rs | 6 +- src/partitioning/qbvh/build.rs | 1 + src/partitioning/qbvh/qbvh.rs | 1 + src/partitioning/qbvh/traversal.rs | 2 +- src/partitioning/qbvh/update.rs | 5 +- src/partitioning/qbvh/update/tests.rs | 5 +- src/partitioning/visitor.rs | 8 +- src/query/clip/clip_aabb_line.rs | 2 +- src/query/clip/clip_aabb_polygon.rs | 1 + src/query/clip/clip_halfspace_polygon.rs | 1 + src/query/clip/clip_segment_segment.rs | 8 +- src/query/clip/mod.rs | 6 +- src/query/closest_points/closest_points.rs | 2 +- src/query/closest_points/mod.rs | 4 +- src/query/contact/contact.rs | 2 +- src/query/contact/mod.rs | 8 +- .../contact_manifolds/contact_manifold.rs | 4 +- .../contact_manifolds_capsule_capsule.rs | 2 +- ...nifolds_composite_shape_composite_shape.rs | 13 +- ...contact_manifolds_composite_shape_shape.rs | 4 +- .../contact_manifolds_halfspace_pfm.rs | 2 +- ...t_manifolds_heightfield_composite_shape.rs | 4 +- .../contact_manifolds_heightfield_shape.rs | 4 +- .../contact_manifolds_trimesh_shape.rs | 6 +- .../contact_manifolds_workspace.rs | 1 + .../polygon_polygon_contact_generator.rs | 8 +- src/query/default_query_dispatcher.rs | 17 +- src/query/distance/mod.rs | 4 +- src/query/epa/epa2.rs | 4 +- src/query/epa/epa3.rs | 8 +- src/query/error.rs | 6 +- src/query/gjk/cso_point.rs | 2 +- src/query/gjk/voronoi_simplex3.rs | 2 +- src/query/intersection_test/mod.rs | 4 +- src/query/mod.rs | 12 +- src/query/nonlinear_shape_cast/mod.rs | 4 +- ...near_shape_cast_support_map_support_map.rs | 2 +- src/query/point/mod.rs | 10 +- src/query/point/point_round_shape.rs | 6 +- src/query/point/point_support_map.rs | 6 +- src/query/query_dispatcher.rs | 7 +- src/query/ray/mod.rs | 6 +- src/query/ray/ray_aabb.rs | 2 +- src/query/ray/ray_support_map.rs | 10 +- src/query/ray/ray_triangle.rs | 2 +- src/query/sat/sat_cuboid_cuboid.rs | 2 +- src/query/shape_cast/mod.rs | 8 +- src/query/split/mod.rs | 2 +- src/query/split/split_trimesh.rs | 7 +- .../aabb_sets_interferences_collector.rs | 1 + ...lume_intersections_simultaneous_visitor.rs | 2 +- .../bounding_volume_intersections_visitor.rs | 2 +- .../visitors/point_intersections_visitor.rs | 2 +- .../visitors/ray_intersections_visitor.rs | 2 +- src/shape/ball.rs | 5 +- src/shape/capsule.rs | 6 +- src/shape/composite_shape.rs | 6 +- src/shape/compound.rs | 1 + src/shape/cone.rs | 6 +- src/shape/convex_polygon.rs | 1 + src/shape/convex_polyhedron.rs | 13 +- src/shape/cuboid.rs | 2 +- src/shape/cylinder.rs | 6 +- src/shape/heightfield2.rs | 6 +- src/shape/heightfield3.rs | 6 +- src/shape/mod.rs | 34 ++-- src/shape/polygonal_feature2d.rs | 8 +- src/shape/polygonal_feature3d.rs | 8 +- src/shape/polygonal_feature_map.rs | 2 +- src/shape/polyline.rs | 8 +- src/shape/segment.rs | 2 +- src/shape/shape.rs | 172 +++++++++--------- src/shape/shared_shape.rs | 7 +- src/shape/tetrahedron.rs | 4 +- src/shape/triangle.rs | 4 +- src/shape/triangle_pseudo_normals.rs | 11 +- src/shape/trimesh.rs | 12 +- src/transformation/convex_hull2.rs | 3 +- .../convex_hull3/convex_hull.rs | 3 +- .../convex_hull3/initial_mesh.rs | 3 +- src/transformation/convex_hull3/mod.rs | 1 + .../convex_hull3/triangle_facet.rs | 1 + src/transformation/convex_hull3/validation.rs | 5 +- src/transformation/ear_clipping.rs | 1 + src/transformation/hertel_mehlhorn.rs | 2 + .../mesh_intersection/mesh_intersection.rs | 5 +- .../triangle_triangle_intersection.rs | 4 + src/transformation/mod.rs | 4 +- src/transformation/polygon_intersection.rs | 5 +- .../to_outline/ball_to_outline.rs | 1 + .../to_outline/capsule_to_outline.rs | 1 + .../to_outline/cone_to_outline.rs | 1 + .../to_outline/cuboid_to_outline.rs | 1 + .../to_outline/cylinder_to_outline.rs | 1 + .../to_outline/round_cone_to_outline.rs | 1 + .../round_convex_polyhedron_to_outline.rs | 1 + .../to_outline/round_cuboid_to_outline.rs | 1 + .../to_outline/round_cylinder_to_outline.rs | 1 + .../to_polyline/ball_to_polyline.rs | 1 + .../to_polyline/capsule_to_polyline.rs | 1 + .../to_polyline/cuboid_to_polyline.rs | 1 + .../to_polyline/heightfield_to_polyline.rs | 1 + .../round_convex_polygon_to_polyline.rs | 1 + .../to_polyline/round_cuboid_to_polyline.rs | 1 + .../to_trimesh/ball_to_trimesh.rs | 1 + .../to_trimesh/capsule_to_trimesh.rs | 1 + .../to_trimesh/cone_to_trimesh.rs | 1 + .../convex_polyhedron_to_trimesh.rs | 1 + .../to_trimesh/cuboid_to_trimesh.rs | 1 + .../to_trimesh/cylinder_to_trimesh.rs | 1 + .../to_trimesh/heightfield_to_trimesh.rs | 1 + src/transformation/utils.rs | 9 +- src/transformation/vhacd/vhacd.rs | 7 +- src/transformation/voxelization/voxel_set.rs | 3 +- .../voxelization/voxelized_volume.rs | 3 +- src/utils/as_bytes.rs | 4 +- src/utils/cleanup.rs | 3 +- src/utils/deterministic_state.rs | 2 +- src/utils/fx_hasher.rs | 4 +- src/utils/hashable_partial_eq.rs | 2 +- src/utils/hashmap.rs | 12 +- src/utils/hashset.rs | 14 +- src/utils/interval.rs | 3 +- src/utils/isometry_ops.rs | 2 +- src/utils/mod.rs | 16 +- src/utils/point_in_poly2d.rs | 2 +- src/utils/point_in_triangle.rs | 6 +- src/utils/sdp_matrix.rs | 2 +- src/utils/segments_intersection.rs | 2 +- src/utils/sorted_pair.rs | 12 +- src/utils/weighted_value.rs | 2 +- src/utils/z_order.rs | 2 +- 164 files changed, 640 insertions(+), 449 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e08c42f..9e0524fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,10 @@ [workspace] -members = ["crates/parry2d", "crates/parry3d", "crates/parry2d-f64", "crates/parry3d-f64"] +members = [ + "crates/parry2d", + "crates/parry3d", + "crates/parry2d-f64", + "crates/parry3d-f64", +] resolver = "2" [workspace.lints] @@ -9,6 +14,11 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(feature, values("wavefront"))', ] } +[workspace.lints.clippy] +alloc_instead_of_core = "warn" +std_instead_of_alloc = "warn" +std_instead_of_core = "warn" + [patch.crates-io] parry2d = { path = "crates/parry2d" } parry3d = { path = "crates/parry3d" } @@ -17,4 +27,4 @@ parry3d-f64 = { path = "crates/parry3d-f64" } #simba = { path = "../simba" } #simba = { git = "https://github.com/dimforge/simba", rev = "45a5266eb36ed9d25907e9bf9130cd4ac846a748" } -#nalgebra = { git = "https://github.com/dimforge/nalgebra", rev = "0cf79aef0e6155befc3279a3145f1940822b8377" } \ No newline at end of file +#nalgebra = { git = "https://github.com/dimforge/nalgebra", rev = "0cf79aef0e6155befc3279a3145f1940822b8377" } diff --git a/crates/parry2d-f64/Cargo.toml b/crates/parry2d-f64/Cargo.toml index abe18ea2..4cf13c3b 100644 --- a/crates/parry2d-f64/Cargo.toml +++ b/crates/parry2d-f64/Cargo.toml @@ -20,17 +20,17 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "alloc"] required-features = ["dim2", "f64"] std = [ "nalgebra/std", "slab", - "rustc-hash", "simba/std", "arrayvec/std", "spade", "thiserror/std", - "ena" + "ena", + "spade/std", ] dim2 = [] f64 = [] @@ -39,6 +39,7 @@ serde-serialize = [ "nalgebra/serde-serialize", "arrayvec/serde", "bitflags/serde", + "spade/serde", ] rkyv-serialize = [ "rkyv/validation", @@ -50,7 +51,7 @@ simd-stable = ["simba/wide", "simd-is-enabled"] simd-nightly = ["simba/portable_simd", "simd-is-enabled"] enhanced-determinism = ["simba/libm_force", "indexmap"] parallel = ["rayon"] -alloc = [] +alloc = ["nalgebra/alloc", "hashbrown"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically @@ -76,17 +77,24 @@ serde = { version = "1.0", optional = true, features = ["derive"] } rkyv = { version = "0.7.41", optional = true } num-derive = "0.4" indexmap = { version = "2", features = ["serde"], optional = true } -rustc-hash = { version = "2", optional = true } +hashbrown = { version = "0.15", optional = true, default-features = false, features = [ + "default-hasher", +] } cust_core = { version = "0.1", optional = true } -spade = { version = "2", optional = true } # Make this optional? +spade = { version = "2", optional = true, default-features = false } # Make this optional? +robust = { version = "1.1", optional = true, default-features = false, features = [ + # Force `no_std` for `robust`, which is used by `spade`. + "no_std", +] } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } log = "0.4" ordered-float = { version = "5", default-features = false } thiserror = { version = "2", default-features = false } -ena = { version = "0.14.3", optional = true } +ena = { version = "0.14.3", optional = true, default-features = false } [dev-dependencies] +parry2d-f64 = { path = ".", features = ["std"] } simba = { version = "0.9", default-features = false } oorandom = "11" ptree = "0.4.0" diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index bcd12d7a..4cd7c9af 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -20,17 +20,17 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "alloc"] required-features = ["dim2", "f32"] std = [ + "alloc", "nalgebra/std", "slab", - "rustc-hash", "simba/std", "arrayvec/std", - "spade", + "spade/std", "thiserror/std", - "ena" + "ena", ] dim2 = [] f32 = [] @@ -39,6 +39,7 @@ serde-serialize = [ "nalgebra/serde-serialize", "arrayvec/serde", "bitflags/serde", + "spade/serde", ] rkyv-serialize = [ "rkyv/validation", @@ -50,7 +51,7 @@ simd-stable = ["simba/wide", "simd-is-enabled"] simd-nightly = ["simba/portable_simd", "simd-is-enabled"] enhanced-determinism = ["simba/libm_force", "indexmap"] parallel = ["rayon"] -alloc = [] +alloc = ["nalgebra/alloc", "hashbrown"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically @@ -76,17 +77,24 @@ serde = { version = "1.0", optional = true, features = ["derive"] } rkyv = { version = "0.7.41", optional = true } num-derive = "0.4" indexmap = { version = "2", features = ["serde"], optional = true } -rustc-hash = { version = "2", optional = true } +hashbrown = { version = "0.15", optional = true, default-features = false, features = [ + "default-hasher", +] } cust_core = { version = "0.1", optional = true } -spade = { version = "2", optional = true } +spade = { version = "2", optional = true, default-features = false } +robust = { version = "1.1", optional = true, default-features = false, features = [ + # Force `no_std` for `robust`, which is used by `spade`. + "no_std", +] } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } ordered-float = { version = "5", default-features = false } log = "0.4" thiserror = { version = "2", default-features = false } -ena = { version = "0.14.3", optional = true } +ena = { version = "0.14.3", optional = true, default-features = false } [dev-dependencies] +parry2d = { path = ".", features = ["std"] } simba = { version = "0.9", default-features = false } oorandom = "11" ptree = "0.4.0" diff --git a/crates/parry2d/examples/common_macroquad2d.rs b/crates/parry2d/examples/common_macroquad2d.rs index 6d37fae5..aada9964 100644 --- a/crates/parry2d/examples/common_macroquad2d.rs +++ b/crates/parry2d/examples/common_macroquad2d.rs @@ -1,4 +1,4 @@ -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; +use core::f32::consts::{FRAC_PI_2, FRAC_PI_4}; use macroquad::prelude::*; use macroquad::{ diff --git a/crates/parry2d/examples/convex_hull2d.rs b/crates/parry2d/examples/convex_hull2d.rs index 85e8fdc9..3a5f0ec6 100644 --- a/crates/parry2d/examples/convex_hull2d.rs +++ b/crates/parry2d/examples/convex_hull2d.rs @@ -1,6 +1,6 @@ mod common_macroquad2d; -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; +use core::f32::consts::{FRAC_PI_2, FRAC_PI_4}; use common_macroquad2d::{draw_point, draw_polygon, lissajous_2d_with_params, na_from_mquad}; use macroquad::prelude::*; diff --git a/crates/parry2d/examples/raycasts_animated.rs b/crates/parry2d/examples/raycasts_animated.rs index 19999653..3aa85fe8 100644 --- a/crates/parry2d/examples/raycasts_animated.rs +++ b/crates/parry2d/examples/raycasts_animated.rs @@ -35,7 +35,7 @@ async fn main() { Point2::new(2.0, 2.0), UnitComplex::new(animation_rotation * i as f32) * -Vector2::x(), ); - let toi = cube.cast_ray(&cube_pose, &ray, std::f32::MAX, true); + let toi = cube.cast_ray(&cube_pose, &ray, f32::MAX, true); /* * diff --git a/crates/parry2d/examples/solid_ray_cast2d.rs b/crates/parry2d/examples/solid_ray_cast2d.rs index 89450627..78223df9 100644 --- a/crates/parry2d/examples/solid_ray_cast2d.rs +++ b/crates/parry2d/examples/solid_ray_cast2d.rs @@ -12,7 +12,7 @@ fn main() { // Solid cast. assert_eq!( cuboid - .cast_ray(&Isometry2::identity(), &ray_inside, std::f32::MAX, true) + .cast_ray(&Isometry2::identity(), &ray_inside, f32::MAX, true) .unwrap(), 0.0 ); @@ -20,16 +20,16 @@ fn main() { // Non-solid cast. assert_eq!( cuboid - .cast_ray(&Isometry2::identity(), &ray_inside, std::f32::MAX, false) + .cast_ray(&Isometry2::identity(), &ray_inside, f32::MAX, false) .unwrap(), 2.0 ); // The other ray does not intersect this shape. assert!(cuboid - .cast_ray(&Isometry2::identity(), &ray_miss, std::f32::MAX, false) + .cast_ray(&Isometry2::identity(), &ray_miss, f32::MAX, false) .is_none()); assert!(cuboid - .cast_ray(&Isometry2::identity(), &ray_miss, std::f32::MAX, true) + .cast_ray(&Isometry2::identity(), &ray_miss, f32::MAX, true) .is_none()); } diff --git a/crates/parry2d/tests/geometry/ray_cast.rs b/crates/parry2d/tests/geometry/ray_cast.rs index de37fd60..41fdbd97 100644 --- a/crates/parry2d/tests/geometry/ray_cast.rs +++ b/crates/parry2d/tests/geometry/ray_cast.rs @@ -9,7 +9,7 @@ fn issue_178_parallel_raycast() { let ray = Ray::new(Point2::new(0.0, 0.0), Vector2::new(0.0, 1.0)); let seg = Segment::new(Point2::new(2.0, 1.0), Point2::new(2.0, 0.0)); - let cast = seg.cast_ray(&m1, &ray, std::f32::MAX, true); + let cast = seg.cast_ray(&m1, &ray, f32::MAX, true); assert!(cast.is_none()); } @@ -19,7 +19,7 @@ fn parallel_raycast() { let ray = Ray::new(Point2::new(0.0, 0.0), Vector2::new(0.0, 1.0)); let seg = Segment::new(Point2::new(2.0, 1.0), Point2::new(2.0, -1.0)); - let cast = seg.cast_ray(&m1, &ray, std::f32::MAX, true); + let cast = seg.cast_ray(&m1, &ray, f32::MAX, true); assert!(cast.is_none()); } @@ -29,7 +29,7 @@ fn collinear_raycast_starting_on_segment() { let ray = Ray::new(Point2::new(0.0, 0.0), Vector2::new(0.0, 1.0)); let seg = Segment::new(Point2::new(0.0, 1.0), Point2::new(0.0, -1.0)); - let cast = seg.cast_ray(&m1, &ray, std::f32::MAX, true); + let cast = seg.cast_ray(&m1, &ray, f32::MAX, true); assert_eq!(cast, Some(0.0)); } @@ -39,7 +39,7 @@ fn collinear_raycast_starting_below_segment() { let ray = Ray::new(Point2::new(0.0, -2.0), Vector2::new(0.0, 1.0)); let seg = Segment::new(Point2::new(0.0, 1.0), Point2::new(0.0, -1.0)); - let cast = seg.cast_ray(&m1, &ray, std::f32::MAX, true); + let cast = seg.cast_ray(&m1, &ray, f32::MAX, true); assert_eq!(cast, Some(1.0)); } @@ -49,7 +49,7 @@ fn collinear_raycast_starting_above_segment() { let ray = Ray::new(Point2::new(0.0, 2.0), Vector2::new(0.0, 1.0)); let seg = Segment::new(Point2::new(0.0, 1.0), Point2::new(0.0, -1.0)); - let cast = seg.cast_ray(&m1, &ray, std::f32::MAX, true); + let cast = seg.cast_ray(&m1, &ray, f32::MAX, true); assert_eq!(cast, None); } @@ -57,14 +57,14 @@ fn collinear_raycast_starting_above_segment() { fn perpendicular_raycast_starting_behind_segment() { let segment = Segment::new(Point2::new(0.0f32, -10.0), Point2::new(0.0, 10.0)); let ray = Ray::new(Point2::new(-1.0, 0.0), Vector2::new(1.0, 0.0)); - assert!(segment.intersects_local_ray(&ray, std::f32::MAX)); + assert!(segment.intersects_local_ray(&ray, f32::MAX)); } #[test] fn perpendicular_raycast_starting_in_front_of_segment() { let segment = Segment::new(Point2::new(0.0f32, -10.0), Point2::new(0.0, 10.0)); let ray = Ray::new(Point2::new(1.0, 0.0), Vector2::new(1.0, 0.0)); - assert!(!segment.intersects_local_ray(&ray, std::f32::MAX)); + assert!(!segment.intersects_local_ray(&ray, f32::MAX)); } #[test] @@ -72,7 +72,7 @@ fn perpendicular_raycast_starting_on_segment() { let segment = Segment::new(Point2::new(0.0f32, -10.0), Point2::new(0.0, 10.0)); let ray = Ray::new(Point2::new(0.0, 3.0), Vector2::new(1.0, 0.0)); - let cast = segment.cast_local_ray(&ray, std::f32::MAX, true); + let cast = segment.cast_local_ray(&ray, f32::MAX, true); assert_eq!(cast, Some(0.0)); } @@ -80,14 +80,14 @@ fn perpendicular_raycast_starting_on_segment() { fn perpendicular_raycast_starting_above_segment() { let segment = Segment::new(Point2::new(0.0f32, -10.0), Point2::new(0.0, 10.0)); let ray = Ray::new(Point2::new(0.0, 11.0), Vector2::new(1.0, 0.0)); - assert!(!segment.intersects_local_ray(&ray, std::f32::MAX)); + assert!(!segment.intersects_local_ray(&ray, f32::MAX)); } #[test] fn perpendicular_raycast_starting_below_segment() { let segment = Segment::new(Point2::new(0.0f32, -10.0), Point2::new(0.0, 10.0)); let ray = Ray::new(Point2::new(0.0, -11.0), Vector2::new(1.0, 0.0)); - assert!(!segment.intersects_local_ray(&ray, std::f32::MAX)); + assert!(!segment.intersects_local_ray(&ray, f32::MAX)); } #[test] @@ -99,7 +99,7 @@ fn raycast_starting_outside_of_triangle() { ); let ray = Ray::new(Point2::new(-10.0, 0.0), Vector2::new(1.0, 0.0)); let intersect = triangle - .cast_local_ray_and_get_normal(&ray, std::f32::MAX, true) + .cast_local_ray_and_get_normal(&ray, f32::MAX, true) .expect("No intersection"); assert_ne!(intersect.time_of_impact, 0.0); @@ -114,7 +114,7 @@ fn raycast_starting_inside_of_triangle() { ); let ray = Ray::new(Point2::new(2.0, 0.0), Vector2::new(1.0, 0.0)); let intersect = triangle - .cast_local_ray_and_get_normal(&ray, std::f32::MAX, true) + .cast_local_ray_and_get_normal(&ray, f32::MAX, true) .expect("No intersection"); assert_eq!(intersect.time_of_impact, 0.0); @@ -129,7 +129,7 @@ fn raycast_starting_on_edge_of_triangle() { ); let ray = Ray::new(Point2::new(0.0, 0.0), Vector2::new(1.0, 0.0)); let intersect = triangle - .cast_local_ray_and_get_normal(&ray, std::f32::MAX, true) + .cast_local_ray_and_get_normal(&ray, f32::MAX, true) .expect("No intersection"); assert_eq!(intersect.time_of_impact, 0.0); diff --git a/crates/parry2d/tests/geometry/time_of_impact2.rs b/crates/parry2d/tests/geometry/time_of_impact2.rs index bdfafeda..35d8a4f2 100644 --- a/crates/parry2d/tests/geometry/time_of_impact2.rs +++ b/crates/parry2d/tests/geometry/time_of_impact2.rs @@ -152,7 +152,7 @@ fn cast_shapes_should_return_toi_for_ball_and_rotated_polyline() { let ball_isometry = Isometry2::identity(); let ball_velocity = Vector2::new(1.0, 0.0); let ball = Ball::new(0.5); - let polyline_isometry = Isometry2::rotation(-std::f32::consts::FRAC_PI_2); + let polyline_isometry = Isometry2::rotation(-core::f32::consts::FRAC_PI_2); let polyline_velocity = Vector2::zeros(); let polyline = Polyline::new(vec![Point2::new(1.0, 1.0), Point2::new(-1.0, 1.0)], None); @@ -184,7 +184,7 @@ fn cast_shapes_should_return_toi_for_ball_and_rotated_segment() { let ball_isometry = Isometry2::identity(); let ball_velocity = Vector2::new(1.0, 0.0); let ball = Ball::new(0.5); - let segment_isometry = Isometry2::rotation(-std::f32::consts::FRAC_PI_2); + let segment_isometry = Isometry2::rotation(-core::f32::consts::FRAC_PI_2); let segment_velocity = Vector2::zeros(); let segment = Segment::new(Point2::new(1.0, 1.0), Point2::new(-1.0, 1.0)); @@ -216,7 +216,7 @@ fn cast_shapes_should_return_toi_for_rotated_segment_and_ball() { let ball_isometry = Isometry2::identity(); let ball_velocity = Vector2::new(1.0, 0.0); let ball = Ball::new(0.5); - let segment_isometry = Isometry2::rotation(-std::f32::consts::FRAC_PI_2); + let segment_isometry = Isometry2::rotation(-core::f32::consts::FRAC_PI_2); let segment_velocity = Vector2::zeros(); let segment = Segment::new(Point2::new(1.0, 1.0), Point2::new(-1.0, 1.0)); diff --git a/crates/parry3d-f64/Cargo.toml b/crates/parry3d-f64/Cargo.toml index 49c36892..4f800ba9 100644 --- a/crates/parry3d-f64/Cargo.toml +++ b/crates/parry3d-f64/Cargo.toml @@ -20,21 +20,25 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "alloc"] required-features = ["dim3", "f64"] std = [ "nalgebra/std", "slab", - "rustc-hash", "simba/std", "arrayvec/std", - "spade", + "spade/std", "thiserror/std", - "ena" + "ena", ] dim3 = [] f64 = [] -serde-serialize = ["serde", "nalgebra/serde-serialize", "bitflags/serde"] +serde-serialize = [ + "serde", + "nalgebra/serde-serialize", + "bitflags/serde", + "spade/serde", +] rkyv-serialize = [ "rkyv/validation", "nalgebra/rkyv-serialize", @@ -47,7 +51,7 @@ enhanced-determinism = ["simba/libm_force", "indexmap"] parallel = ["rayon"] # Adds `TriMesh:to_obj_file` function. wavefront = ["obj"] -alloc = [] +alloc = ["nalgebra/alloc", "hashbrown"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically @@ -73,20 +77,28 @@ serde = { version = "1.0", optional = true, features = ["derive", "rc"] } rkyv = { version = "0.7.41", optional = true } num-derive = "0.4" indexmap = { version = "2", features = ["serde"], optional = true } -rustc-hash = { version = "2", optional = true } +hashbrown = { version = "0.15", optional = true, default-features = false, features = [ + "default-hasher", +] } +foldhash = { version = "0.1", optional = true, default-features = false } cust_core = { version = "0.1", optional = true } -spade = { version = "2.9", optional = true } # Make this optional? +spade = { version = "2.9", optional = true, default-features = false } # Make this optional? +robust = { version = "1.1", optional = true, default-features = false, features = [ + # Force `no_std` for `robust`, which is used by `spade`. + "no_std", +] } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } rstar = "0.12.0" obj = { version = "0.10.2", optional = true } -ena = { version = "0.14.3", optional = true } +ena = { version = "0.14.3", optional = true, default-features = false } log = "0.4" ordered-float = { version = "5", default-features = false } thiserror = { version = "2", default-features = false } [dev-dependencies] +parry3d-f64 = { path = ".", features = ["std"] } oorandom = "11" ptree = "0.4.0" rand = { version = "0.8" } diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index 29075f64..a2e67102 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -20,21 +20,25 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "alloc"] required-features = ["dim3", "f32"] std = [ "nalgebra/std", "slab", - "rustc-hash", "simba/std", "arrayvec/std", - "spade", + "spade/std", "thiserror/std", - "ena" + "ena", ] dim3 = [] f32 = [] -serde-serialize = ["serde", "nalgebra/serde-serialize", "bitflags/serde"] +serde-serialize = [ + "serde", + "nalgebra/serde-serialize", + "bitflags/serde", + "spade/serde", +] rkyv-serialize = [ "rkyv/validation", "nalgebra/rkyv-serialize", @@ -48,7 +52,7 @@ enhanced-determinism = ["simba/libm_force", "indexmap"] parallel = ["rayon"] # Adds `TriMesh:to_obj_file` function. wavefront = ["obj"] -alloc = [] +alloc = ["nalgebra/alloc", "hashbrown"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically @@ -74,9 +78,15 @@ serde = { version = "1.0", optional = true, features = ["derive", "rc"] } rkyv = { version = "0.7.41", optional = true } num-derive = "0.4" indexmap = { version = "2", features = ["serde"], optional = true } -rustc-hash = { version = "2", optional = true } +hashbrown = { version = "0.15", optional = true, default-features = false, features = [ + "default-hasher", +] } cust_core = { version = "0.1", optional = true } -spade = { version = "2.9", optional = true } # Make this optional? +spade = { version = "2.9", optional = true, default-features = false } # Make this optional? +robust = { version = "1.1", optional = true, default-features = false, features = [ + # Force `no_std` for `robust`, which is used by `spade`. + "no_std", +] } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } log = "0.4" @@ -84,9 +94,10 @@ ordered-float = { version = "5", default-features = false } thiserror = { version = "2", default-features = false } rstar = "0.12.0" obj = { version = "0.10.2", optional = true } -ena = { version = "0.14.3", optional = true } +ena = { version = "0.14.3", optional = true, default-features = false } [dev-dependencies] +parry3d = { path = ".", features = ["std"] } oorandom = "11" ptree = "0.4.0" rand = { version = "0.8" } @@ -136,16 +147,19 @@ doc-scrape-examples = true [[example]] name = "convex3d" path = "examples/convex3d.rs" +required-features = ["alloc"] doc-scrape-examples = true [[example]] name = "convex_hull3d" path = "examples/convex_hull3d.rs" +required-features = ["alloc"] doc-scrape-examples = true [[example]] name = "convex_try_new3d" path = "examples/convex_try_new3d.rs" +required-features = ["alloc"] doc-scrape-examples = true [[example]] @@ -171,6 +185,7 @@ doc-scrape-examples = true [[example]] name = "mesh3d" path = "examples/mesh3d.rs" +required-features = ["alloc"] doc-scrape-examples = true [[example]] @@ -181,11 +196,13 @@ doc-scrape-examples = true [[example]] name = "plane_intersection" path = "examples/plane_intersection.rs" +required-features = ["alloc"] doc-scrape-examples = true [[example]] name = "polyline3d" path = "examples/polyline3d.rs" +required-features = ["alloc"] doc-scrape-examples = true [[example]] @@ -193,6 +210,12 @@ name = "proximity_query3d" path = "examples/proximity_query3d.rs" doc-scrape-examples = true +[[example]] +name = "project_point3d" +path = "examples/project_point3d.rs" +required-features = ["alloc"] +doc-scrape-examples = true + [[example]] name = "solid_point_query3d" path = "examples/solid_point_query3d.rs" diff --git a/crates/parry3d/benches/bounding_volume/mod.rs b/crates/parry3d/benches/bounding_volume/mod.rs index 1fab09f3..89813973 100644 --- a/crates/parry3d/benches/bounding_volume/mod.rs +++ b/crates/parry3d/benches/bounding_volume/mod.rs @@ -1,10 +1,12 @@ -use crate::common::{generate, generate_trimesh_around_origin, unref}; +#[cfg(feature = "alloc")] +use crate::common::generate_trimesh_around_origin; +use crate::common::{generate, unref}; use na::Isometry3; use parry3d::bounding_volume::BoundingVolume; use parry3d::bounding_volume::{Aabb, BoundingSphere}; -use parry3d::shape::{ - Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle, -}; +use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; +#[cfg(feature = "alloc")] +use parry3d::shape::{ConvexPolyhedron, TriMesh}; use rand::SeedableRng; use rand_isaac::IsaacRng; use test::Bencher; @@ -132,12 +134,14 @@ bench_method!( m: Isometry3 ); +#[cfg(feature = "alloc")] bench_method!( bench_convex_aabb, aabb: Aabb, c: ConvexPolyhedron, m: Isometry3 ); +#[cfg(feature = "alloc")] bench_method!( bench_convex_bounding_sphere, bounding_sphere: BoundingSphere, @@ -145,12 +149,14 @@ bench_method!( m: Isometry3 ); +#[cfg(feature = "alloc")] bench_method_gen!( bench_mesh_aabb, aabb: Aabb, mesh: TriMesh = generate_trimesh_around_origin, m: Isometry3 = generate ); +#[cfg(feature = "alloc")] bench_method_gen!( bench_mesh_bounding_sphere, bounding_sphere: BoundingSphere, diff --git a/crates/parry3d/benches/common/default_gen.rs b/crates/parry3d/benches/common/default_gen.rs index ed52d896..cb47bbec 100644 --- a/crates/parry3d/benches/common/default_gen.rs +++ b/crates/parry3d/benches/common/default_gen.rs @@ -5,7 +5,9 @@ use na::{ use parry3d::bounding_volume::{Aabb, BoundingSphere}; use parry3d::math::{Point, Real, Vector}; use parry3d::query::Ray; -use parry3d::shape::{Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, Triangle}; +#[cfg(feature = "alloc")] +use parry3d::shape::ConvexPolyhedron; +use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; use rand::distributions::{Distribution, Standard}; use rand::Rng; @@ -120,6 +122,7 @@ where } } +#[cfg(feature = "alloc")] impl DefaultGen for ConvexPolyhedron where Standard: Distribution, diff --git a/crates/parry3d/benches/common/mod.rs b/crates/parry3d/benches/common/mod.rs index 746805fc..b7779566 100644 --- a/crates/parry3d/benches/common/mod.rs +++ b/crates/parry3d/benches/common/mod.rs @@ -1,7 +1,9 @@ pub use self::default_gen::generate; +#[cfg(feature = "alloc")] pub use self::generators::generate_trimesh_around_origin; pub use self::unref::unref; mod default_gen; +#[cfg(feature = "alloc")] mod generators; mod unref; diff --git a/crates/parry3d/benches/query/ray.rs b/crates/parry3d/benches/query/ray.rs index df51b430..bec0240f 100644 --- a/crates/parry3d/benches/query/ray.rs +++ b/crates/parry3d/benches/query/ray.rs @@ -1,10 +1,12 @@ -use crate::common::{generate, generate_trimesh_around_origin, unref}; +#[cfg(feature = "alloc")] +use crate::common::generate_trimesh_around_origin; +use crate::common::{generate, unref}; use na::Isometry3; use parry3d::bounding_volume::{Aabb, BoundingSphere}; use parry3d::query::{Ray, RayCast}; -use parry3d::shape::{ - Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle, -}; +use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; +#[cfg(feature = "alloc")] +use parry3d::shape::{ConvexPolyhedron, TriMesh}; use rand::SeedableRng; use rand_isaac::IsaacRng; use test::Bencher; @@ -154,6 +156,7 @@ bench_method!( solid: bool ); +#[cfg(feature = "alloc")] bench_method!( bench_ray_against_convex_with_normal, cast_ray_and_get_normal, @@ -164,6 +167,7 @@ bench_method!( solid: bool ); +#[cfg(feature = "alloc")] bench_method_gen!( bench_ray_against_trimesh_with_normal, cast_ray_and_get_normal, diff --git a/crates/parry3d/benches/support_map/mod.rs b/crates/parry3d/benches/support_map/mod.rs index 4be9a900..46021a67 100644 --- a/crates/parry3d/benches/support_map/mod.rs +++ b/crates/parry3d/benches/support_map/mod.rs @@ -1,7 +1,9 @@ use crate::common::{generate, unref}; use na::{Isometry3, Vector3}; +#[cfg(feature = "alloc")] +use parry3d::shape::ConvexPolyhedron; +use parry3d::shape::SupportMap; use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; -use parry3d::shape::{ConvexPolyhedron, SupportMap}; use rand::SeedableRng; use rand_isaac::IsaacRng; use test::Bencher; @@ -59,7 +61,7 @@ bench_method!( m: Isometry3, dir: Vector3 ); - +#[cfg(feature = "alloc")] bench_method!( bench_convex_support_map, support_point, diff --git a/crates/parry3d/examples/bounding_sphere3d.rs b/crates/parry3d/examples/bounding_sphere3d.rs index 0d3a4d82..0d2c181c 100644 --- a/crates/parry3d/examples/bounding_sphere3d.rs +++ b/crates/parry3d/examples/bounding_sphere3d.rs @@ -2,7 +2,7 @@ mod common_macroquad3d; extern crate nalgebra as na; -use std::ops::Rem; +use core::ops::Rem; use common_macroquad3d::{lissajous_3d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; diff --git a/crates/parry3d/examples/common_macroquad3d.rs b/crates/parry3d/examples/common_macroquad3d.rs index bd3617fa..57c5be0b 100644 --- a/crates/parry3d/examples/common_macroquad3d.rs +++ b/crates/parry3d/examples/common_macroquad3d.rs @@ -1,4 +1,4 @@ -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; +use core::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; use macroquad::{ color::{Color, WHITE}, @@ -36,9 +36,9 @@ pub fn hue_to_rgb(h: f32) -> (f32, f32, f32) { let kg = (3.0 + h * 6.0).rem_euclid(6.0); let kb = (1.0 + h * 6.0).rem_euclid(6.0); - let r = 1.0 - kr.min(4.0 - kr).min(1.0).max(0.0); - let g = 1.0 - kg.min(4.0 - kg).min(1.0).max(0.0); - let b = 1.0 - kb.min(4.0 - kb).min(1.0).max(0.0); + let r = 1.0 - kr.min(4.0 - kr).clamp(0.0, 1.0); + let g = 1.0 - kg.min(4.0 - kg).clamp(0.0, 1.0); + let b = 1.0 - kb.min(4.0 - kb).clamp(0.0, 1.0); (r, g, b) } @@ -120,10 +120,7 @@ pub fn mquad_mesh_from_points( let vertices: Vec = mquad_compute_normals_and_bake_light(&mquad_points, &mquad_indices, light_pos); // Regenerate the index for each vertex. - let indices: Vec = (0..vertices.len() * 3) - .into_iter() - .map(|i| i as u16) - .collect(); + let indices: Vec = (0..vertices.len() * 3).map(|i| i as u16).collect(); let mesh = Mesh { vertices, indices, diff --git a/crates/parry3d/examples/convex_hull3d.rs b/crates/parry3d/examples/convex_hull3d.rs index 7b009605..fff14fa1 100644 --- a/crates/parry3d/examples/convex_hull3d.rs +++ b/crates/parry3d/examples/convex_hull3d.rs @@ -1,6 +1,6 @@ mod common_macroquad3d; -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; +use core::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; use common_macroquad3d::{ lissajous_3d_with_params, mquad_from_na, mquad_mesh_from_points, na_from_mquad, diff --git a/crates/parry3d/examples/getting_started.rs b/crates/parry3d/examples/getting_started.rs index b8aaa870..0776f4c2 100644 --- a/crates/parry3d/examples/getting_started.rs +++ b/crates/parry3d/examples/getting_started.rs @@ -8,5 +8,5 @@ fn main() { let cube = Cuboid::new(Vector3::new(1.0f32, 1.0, 1.0)); let ray = Ray::new(Point3::new(0.0f32, 0.0, -1.0), Vector3::z()); - assert!(cube.intersects_ray(&Isometry3::identity(), &ray, std::f32::MAX)); + assert!(cube.intersects_ray(&Isometry3::identity(), &ray, f32::MAX)); } diff --git a/crates/parry3d/examples/solid_ray_cast3d.rs b/crates/parry3d/examples/solid_ray_cast3d.rs index 36b31335..0dc9afab 100644 --- a/crates/parry3d/examples/solid_ray_cast3d.rs +++ b/crates/parry3d/examples/solid_ray_cast3d.rs @@ -12,7 +12,7 @@ fn main() { // Solid cast. assert_eq!( cuboid - .cast_ray(&Isometry3::identity(), &ray_inside, std::f32::MAX, true) + .cast_ray(&Isometry3::identity(), &ray_inside, f32::MAX, true) .unwrap(), 0.0 ); @@ -20,16 +20,16 @@ fn main() { // Non-solid cast. assert_eq!( cuboid - .cast_ray(&Isometry3::identity(), &ray_inside, std::f32::MAX, false) + .cast_ray(&Isometry3::identity(), &ray_inside, f32::MAX, false) .unwrap(), 2.0 ); // The other ray does not intersect this shape. assert!(cuboid - .cast_ray(&Isometry3::identity(), &ray_miss, std::f32::MAX, false) + .cast_ray(&Isometry3::identity(), &ray_miss, f32::MAX, false) .is_none()); assert!(cuboid - .cast_ray(&Isometry3::identity(), &ray_miss, std::f32::MAX, true) + .cast_ray(&Isometry3::identity(), &ray_miss, f32::MAX, true) .is_none()); } diff --git a/crates/parry3d/tests/geometry/cuboid_ray_cast.rs b/crates/parry3d/tests/geometry/cuboid_ray_cast.rs index 9c1cf7c2..7f8f9e43 100644 --- a/crates/parry3d/tests/geometry/cuboid_ray_cast.rs +++ b/crates/parry3d/tests/geometry/cuboid_ray_cast.rs @@ -31,7 +31,7 @@ where let position = Isometry3::from_parts(Translation3::identity(), rotation); let intersection = shape - .cast_ray_and_get_normal(&position, &ray, std::f32::MAX, true) + .cast_ray_and_get_normal(&position, &ray, f32::MAX, true) .expect(&format!( "Ray {:?} did not hit Shape {} rotated with {:?}", ray, name, rotation @@ -61,14 +61,14 @@ where assert!( shape - .cast_ray_and_get_normal(&position, &new_ray, std::f32::MAX, true) + .cast_ray_and_get_normal(&position, &new_ray, f32::MAX, true) .is_none(), "Ray {:#?} from outside Shape {} rotated with {:#?} did hit at t={}", ray, name, rotation, shape - .cast_ray_and_get_normal(&position, &new_ray, std::f32::MAX, true) + .cast_ray_and_get_normal(&position, &new_ray, f32::MAX, true) .expect("recurring ray cast produced a different answer") .time_of_impact ); diff --git a/crates/parry3d/tests/geometry/mod.rs b/crates/parry3d/tests/geometry/mod.rs index 25a4e755..e28c8a2b 100644 --- a/crates/parry3d/tests/geometry/mod.rs +++ b/crates/parry3d/tests/geometry/mod.rs @@ -1,12 +1,18 @@ mod aabb_scale; mod ball_ball_toi; mod ball_triangle_toi; +#[cfg(feature = "alloc")] mod convex_hull; mod cuboid_ray_cast; +#[cfg(feature = "alloc")] mod cylinder_cuboid_contact; +#[cfg(feature = "alloc")] mod epa3; mod still_objects_toi; mod time_of_impact3; +#[cfg(feature = "alloc")] mod trimesh_connected_components; +#[cfg(feature = "alloc")] mod trimesh_intersection; +#[cfg(feature = "alloc")] mod trimesh_trimesh_toi; diff --git a/crates/parry3d/tests/geometry/trimesh_intersection.rs b/crates/parry3d/tests/geometry/trimesh_intersection.rs index 94df835c..fd195e4c 100644 --- a/crates/parry3d/tests/geometry/trimesh_intersection.rs +++ b/crates/parry3d/tests/geometry/trimesh_intersection.rs @@ -29,7 +29,7 @@ fn build_diamond(position: &Isometry) -> TriMesh { fn trimesh_plane_edge_intersection() { let mesh = build_diamond(&Isometry::identity()); - let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 0.5, std::f32::EPSILON); + let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 0.5, core::f32::EPSILON); assert!(matches!(result, IntersectResult::Intersect(_))); @@ -47,7 +47,7 @@ fn trimesh_plane_edge_intersection() { fn trimesh_plane_vertex_intersection() { let mesh = build_diamond(&Isometry::identity()); - let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 0.0, std::f32::EPSILON); + let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 0.0, core::f32::EPSILON); assert!(matches!(result, IntersectResult::Intersect(_))); @@ -65,7 +65,7 @@ fn trimesh_plane_vertex_intersection() { fn trimesh_plane_mixed_intersection() { let mesh = build_diamond(&Isometry::identity()); - let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(0), 0.0, std::f32::EPSILON); + let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(0), 0.0, core::f32::EPSILON); assert!(matches!(result, IntersectResult::Intersect(_))); @@ -85,7 +85,7 @@ fn trimesh_plane_multi_intersection() { let mut mesh = build_diamond(&Isometry::identity()); mesh.append(&build_diamond(&Isometry::translation(-5.0, 0.0, 0.0))); - let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 0.5, std::f32::EPSILON); + let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 0.5, core::f32::EPSILON); assert!(matches!(result, IntersectResult::Intersect(_))); @@ -108,7 +108,8 @@ fn trimesh_plane_multi_intersection() { fn trimesh_plane_above() { let mesh = build_diamond(&Isometry::identity()); - let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), -5.0, std::f32::EPSILON); + let result = + mesh.intersection_with_local_plane(&Vector3::ith_axis(2), -5.0, core::f32::EPSILON); assert!(matches!(result, IntersectResult::Positive)); } @@ -117,7 +118,7 @@ fn trimesh_plane_above() { fn trimesh_plane_below() { let mesh = build_diamond(&Isometry::identity()); - let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 5.0, std::f32::EPSILON); + let result = mesh.intersection_with_local_plane(&Vector3::ith_axis(2), 5.0, core::f32::EPSILON); assert!(matches!(result, IntersectResult::Negative)); } diff --git a/src/bounding_volume/aabb.rs b/src/bounding_volume/aabb.rs index d6d44426..f9720921 100644 --- a/src/bounding_volume/aabb.rs +++ b/src/bounding_volume/aabb.rs @@ -411,7 +411,7 @@ impl Aabb { } #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] pub fn intersects_spiral( &self, point: &Point, @@ -422,6 +422,7 @@ impl Aabb { ) -> bool { use crate::utils::WBasis; use crate::utils::{Interval, IntervalFunction}; + use alloc::vec; struct SpiralPlaneDistance { center: Point, diff --git a/src/bounding_volume/aabb_utils.rs b/src/bounding_volume/aabb_utils.rs index 79ac72d5..8ef75cda 100644 --- a/src/bounding_volume/aabb_utils.rs +++ b/src/bounding_volume/aabb_utils.rs @@ -1,4 +1,4 @@ -use std::iter::IntoIterator; +use core::iter::IntoIterator; use crate::bounding_volume::Aabb; use crate::math::{Isometry, Point, Real, Vector, DIM}; diff --git a/src/bounding_volume/mod.rs b/src/bounding_volume/mod.rs index 53cfb658..5b7dbf0d 100644 --- a/src/bounding_volume/mod.rs +++ b/src/bounding_volume/mod.rs @@ -16,14 +16,14 @@ pub mod bounding_volume; pub mod aabb; mod aabb_ball; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod aabb_convex_polygon; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod aabb_convex_polyhedron; mod aabb_cuboid; mod aabb_halfspace; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod aabb_heightfield; mod aabb_support_map; mod aabb_triangle; @@ -37,22 +37,22 @@ mod bounding_sphere_capsule; #[cfg(feature = "dim3")] mod bounding_sphere_cone; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod bounding_sphere_convex; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod bounding_sphere_convex_polygon; mod bounding_sphere_cuboid; #[cfg(feature = "dim3")] mod bounding_sphere_cylinder; mod bounding_sphere_halfspace; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod bounding_sphere_heightfield; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod bounding_sphere_polyline; mod bounding_sphere_segment; mod bounding_sphere_triangle; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod bounding_sphere_trimesh; mod bounding_sphere_utils; mod simd_aabb; diff --git a/src/bounding_volume/simd_aabb.rs b/src/bounding_volume/simd_aabb.rs index f17e4f9e..640bb4ce 100644 --- a/src/bounding_volume/simd_aabb.rs +++ b/src/bounding_volume/simd_aabb.rs @@ -62,7 +62,7 @@ impl<'de> serde::Deserialize<'de> for SimdAabb { impl<'de> serde::de::Visitor<'de> for Visitor { type Value = SimdAabb; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { write!( formatter, "two arrays containing at least {} floats", diff --git a/src/lib.rs b/src/lib.rs index ab47d350..ead0cea1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ the rust programming language. #![deny(unused_parens)] #![deny(non_upper_case_globals)] #![deny(unused_results)] +#![deny(unused_qualifications)] #![warn(missing_docs)] #![warn(unused_imports)] #![allow(missing_copy_implementations)] @@ -19,8 +20,7 @@ the rust programming language. #![allow(clippy::manual_range_contains)] // This usually makes it way more verbose that it could be. #![allow(clippy::type_complexity)] // Complains about closures that are fairly simple. #![doc(html_root_url = "http://docs.rs/parry/0.1.1")] -#![cfg_attr(not(feature = "std"), no_std)] -#![deny(unused_qualifications)] +#![no_std] #[cfg(all( feature = "simd-is-enabled", @@ -47,13 +47,13 @@ macro_rules! array( } ); -#[cfg(all(feature = "alloc", not(feature = "std")))] +#[cfg(feature = "std")] +extern crate std; + +#[cfg(feature = "alloc")] #[cfg_attr(test, macro_use)] extern crate alloc; -#[cfg(not(feature = "std"))] -extern crate core as std; - #[cfg(feature = "serde")] #[macro_use] extern crate serde; @@ -70,7 +70,7 @@ pub mod mass_properties; pub mod partitioning; pub mod query; pub mod shape; -#[cfg(feature = "std")] +#[cfg(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 fa863f02..2de45c5d 100644 --- a/src/mass_properties/mass_properties.rs +++ b/src/mass_properties/mass_properties.rs @@ -1,10 +1,10 @@ use crate::math::{AngVector, AngularInertia, Isometry, Point, Real, Rotation, Vector}; use crate::utils; +use core::ops::{Add, AddAssign, Sub, SubAssign}; use na::ComplexField; use num::Zero; -use std::ops::{Add, AddAssign, Sub, SubAssign}; #[cfg(feature = "dim3")] -use {na::Matrix3, std::ops::MulAssign}; +use {core::ops::MulAssign, na::Matrix3}; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; @@ -380,13 +380,15 @@ impl AddAssign for MassProperties { } } -#[cfg(feature = "std")] -impl std::iter::Sum for MassProperties { +#[cfg(feature = "alloc")] +impl core::iter::Sum for MassProperties { #[cfg(feature = "dim2")] fn sum(iter: I) -> Self where I: Iterator, { + use alloc::vec::Vec; + let mut total_mass = 0.0; let mut total_com = Point::origin(); let mut total_inertia = 0.0; @@ -421,6 +423,8 @@ impl std::iter::Sum for MassProperties { where I: Iterator, { + use alloc::vec::Vec; + let mut total_mass = 0.0; let mut total_com = Point::origin(); let mut total_inertia = Matrix3::zeros(); @@ -587,6 +591,7 @@ mod test { } #[test] + #[cfg(feature = "alloc")] fn mass_properties_sum_no_nan() { let mp: MassProperties = [MassProperties::zero()].iter().map(|v| *v).sum(); assert!(!mp.local_com.x.is_nan() && !mp.local_com.y.is_nan()); diff --git a/src/mass_properties/mass_properties_trimesh3d.rs b/src/mass_properties/mass_properties_trimesh3d.rs index aa7416d9..87f94cd9 100644 --- a/src/mass_properties/mass_properties_trimesh3d.rs +++ b/src/mass_properties/mass_properties_trimesh3d.rs @@ -182,6 +182,8 @@ pub fn trimesh_signed_volume_and_center_of_mass( #[cfg(test)] mod test { + use std::dbg; + use crate::math::Vector; use crate::{ mass_properties::MassProperties, diff --git a/src/mass_properties/mod.rs b/src/mass_properties/mod.rs index bebb8618..7cbec409 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(feature = "alloc")] mod mass_properties_compound; #[cfg(feature = "dim3")] mod mass_properties_cone; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod mass_properties_convex_polygon; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(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(feature = "alloc")] mod mass_properties_trimesh2d; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(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(feature = "alloc")] pub use super::mass_properties_convex_polygon::convex_polygon_area_and_center_of_mass; #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] pub use super::mass_properties_trimesh2d::trimesh_area_and_center_of_mass; #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(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/mod.rs b/src/partitioning/mod.rs index cf86ef42..f1f2720c 100644 --- a/src/partitioning/mod.rs +++ b/src/partitioning/mod.rs @@ -1,6 +1,6 @@ //! Spatial partitioning tools. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::qbvh::{ CenterDataSplitter, IndexedData, NodeIndex, Qbvh, QbvhDataGenerator, QbvhNode, QbvhNonOverlappingDataSplitter, QbvhProxy, QbvhUpdateWorkspace, SimdNodeIndex, @@ -14,9 +14,9 @@ pub use self::visitor::{ /// A quaternary bounding-volume-hierarchy. #[deprecated(note = "Renamed to Qbvh")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub type SimdQbvh = Qbvh; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod qbvh; mod visitor; diff --git a/src/partitioning/qbvh/build.rs b/src/partitioning/qbvh/build.rs index 1c4cdc16..e81381e5 100644 --- a/src/partitioning/qbvh/build.rs +++ b/src/partitioning/qbvh/build.rs @@ -3,6 +3,7 @@ use crate::math::Vector; use crate::math::{Point, Real}; use crate::query::SplitResult; use crate::simd::SimdReal; +use alloc::{vec, vec::Vec}; use simba::simd::SimdValue; use super::utils::split_indices_wrt_dim; diff --git a/src/partitioning/qbvh/qbvh.rs b/src/partitioning/qbvh/qbvh.rs index 705ad719..1c46f9a8 100644 --- a/src/partitioning/qbvh/qbvh.rs +++ b/src/partitioning/qbvh/qbvh.rs @@ -1,5 +1,6 @@ use crate::bounding_volume::{Aabb, SimdAabb}; use crate::math::{Real, Vector}; +use alloc::vec::Vec; use na::SimdValue; diff --git a/src/partitioning/qbvh/traversal.rs b/src/partitioning/qbvh/traversal.rs index 3ae08297..309154f7 100644 --- a/src/partitioning/qbvh/traversal.rs +++ b/src/partitioning/qbvh/traversal.rs @@ -9,9 +9,9 @@ use crate::partitioning::{ }; use crate::simd::SIMD_WIDTH; use crate::utils::WeightedValue; +use alloc::{collections::BinaryHeap, vec, vec::Vec}; use num::Bounded; use simba::simd::SimdBool; -use std::collections::BinaryHeap; #[cfg(feature = "parallel")] use { crate::partitioning::{ParallelSimdSimultaneousVisitor, ParallelSimdVisitor}, diff --git a/src/partitioning/qbvh/update.rs b/src/partitioning/qbvh/update.rs index 24363a60..bf074d17 100644 --- a/src/partitioning/qbvh/update.rs +++ b/src/partitioning/qbvh/update.rs @@ -4,6 +4,7 @@ use crate::math::Vector; use crate::math::{Point, Real}; use crate::partitioning::{CenterDataSplitter, QbvhProxy}; use crate::simd::{SimdReal, SIMD_WIDTH}; +use alloc::{vec, vec::Vec}; use simba::simd::{SimdBool, SimdValue}; use super::{IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhNodeFlags}; @@ -320,7 +321,7 @@ impl Qbvh { } first_iter = false; - std::mem::swap(&mut self.dirty_nodes, &mut workspace.dirty_parent_nodes); + core::mem::swap(&mut self.dirty_nodes, &mut workspace.dirty_parent_nodes); } num_changed @@ -403,7 +404,7 @@ impl Qbvh { workspace.to_sort.extend(0..workspace.orig_ids.len()); let root_id = NodeIndex::new(0, 0); - let mut indices = std::mem::take(&mut workspace.to_sort); + let mut indices = core::mem::take(&mut workspace.to_sort); let (id, aabb) = self.do_recurse_rebalance(&mut indices, workspace, root_id, margin); workspace.to_sort = indices; diff --git a/src/partitioning/qbvh/update/tests.rs b/src/partitioning/qbvh/update/tests.rs index 2f122b5d..1d9f0965 100644 --- a/src/partitioning/qbvh/update/tests.rs +++ b/src/partitioning/qbvh/update/tests.rs @@ -1,5 +1,6 @@ +use alloc::{borrow::Cow, string::String}; use rand::{rngs::StdRng, Rng, SeedableRng}; -use std::borrow::Cow; +use std::println; use crate::{ bounding_volume::Aabb, @@ -213,7 +214,7 @@ impl QbvhTester { let mut qbvh = Qbvh::new(); let workspace = QbvhUpdateWorkspace::default(); let aabbs = self.aabbs.clone(); - qbvh.clear_and_rebuild(aabbs.iter().map(|(index, aabb)| (index, aabb.clone())), 0.0); + qbvh.clear_and_rebuild(aabbs.iter().map(|(index, aabb)| (index, *aabb)), 0.0); QbvhTester { qbvh, workspace, diff --git a/src/partitioning/visitor.rs b/src/partitioning/visitor.rs index dd9f9b27..5b6c7b4c 100644 --- a/src/partitioning/visitor.rs +++ b/src/partitioning/visitor.rs @@ -1,6 +1,6 @@ use crate::math::{Real, SimdBool, SimdReal, SIMD_WIDTH}; -#[cfg(all(feature = "std", feature = "parallel"))] +#[cfg(all(feature = "alloc", feature = "parallel"))] use crate::partitioning::{qbvh::QbvhNode, SimdNodeIndex}; /// The next action to be taken by a BVH traversal algorithm after having visited a node with some data. @@ -117,7 +117,7 @@ pub trait SimdSimultaneousVisitor { */ /// Trait implemented by visitor called during the parallel traversal of a spatial partitioning data structure. -#[cfg(all(feature = "std", feature = "parallel"))] +#[cfg(all(feature = "alloc", feature = "parallel"))] pub trait ParallelSimdVisitor: Sync { /// Execute an operation on the content of a node of the spatial partitioning structure. /// @@ -131,7 +131,7 @@ pub trait ParallelSimdVisitor: Sync { ) -> SimdVisitStatus; } -#[cfg(all(feature = "std", feature = "parallel"))] +#[cfg(all(feature = "alloc", feature = "parallel"))] impl ParallelSimdVisitor for F where F: Sync + Fn(&QbvhNode, Option<[Option<&LeafData>; SIMD_WIDTH]>) -> SimdVisitStatus, @@ -148,7 +148,7 @@ where /// Trait implemented by visitor called during a parallel simultaneous spatial partitioning /// data structure traversal. -#[cfg(all(feature = "std", feature = "parallel"))] +#[cfg(all(feature = "alloc", feature = "parallel"))] pub trait ParallelSimdSimultaneousVisitor: Sync { /// Visitor state data that will be passed down the recursion. type Data: Copy + Sync + Default; diff --git a/src/query/clip/clip_aabb_line.rs b/src/query/clip/clip_aabb_line.rs index 724d3e74..b85133cb 100644 --- a/src/query/clip/clip_aabb_line.rs +++ b/src/query/clip/clip_aabb_line.rs @@ -92,7 +92,7 @@ pub fn clip_aabb_line( if inter_with_near_halfspace > inter_with_far_halfspace { flip_sides = true; - std::mem::swap( + core::mem::swap( &mut inter_with_near_halfspace, &mut inter_with_far_halfspace, ) diff --git a/src/query/clip/clip_aabb_polygon.rs b/src/query/clip/clip_aabb_polygon.rs index 92984512..2350c757 100644 --- a/src/query/clip/clip_aabb_polygon.rs +++ b/src/query/clip/clip_aabb_polygon.rs @@ -1,5 +1,6 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real, Vector}; +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 5a9e93a3..6bc2d376 100644 --- a/src/query/clip/clip_halfspace_polygon.rs +++ b/src/query/clip/clip_halfspace_polygon.rs @@ -1,5 +1,6 @@ use crate::math::{Point, Real, Vector}; use crate::query::{self, Ray}; +use alloc::vec::Vec; /// Cuts a polygon with the given half-space. /// diff --git a/src/query/clip/clip_segment_segment.rs b/src/query/clip/clip_segment_segment.rs index 72f326b4..d5e44701 100644 --- a/src/query/clip/clip_segment_segment.rs +++ b/src/query/clip/clip_segment_segment.rs @@ -27,13 +27,13 @@ pub fn clip_segment_segment_with_normal( if range1[1] < range1[0] { range1.swap(0, 1); features1.swap(0, 1); - std::mem::swap(&mut seg1.0, &mut seg1.1); + core::mem::swap(&mut seg1.0, &mut seg1.1); } if range2[1] < range2[0] { range2.swap(0, 1); features2.swap(0, 1); - std::mem::swap(&mut seg2.0, &mut seg2.1); + core::mem::swap(&mut seg2.0, &mut seg2.1); } if range2[0] > range1[1] || range1[0] > range2[1] { @@ -92,13 +92,13 @@ pub fn clip_segment_segment( if range1[1] < range1[0] { range1.swap(0, 1); features1.swap(0, 1); - std::mem::swap(&mut seg1.0, &mut seg1.1); + core::mem::swap(&mut seg1.0, &mut seg1.1); } if range2[1] < range2[0] { range2.swap(0, 1); features2.swap(0, 1); - std::mem::swap(&mut seg2.0, &mut seg2.1); + core::mem::swap(&mut seg2.0, &mut seg2.1); } if range2[0] > range1[1] || range1[0] > range2[1] { diff --git a/src/query/clip/mod.rs b/src/query/clip/mod.rs index 3a17f804..bb3aef0a 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(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(feature = "alloc")] mod clip_aabb_polygon; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod clip_halfspace_polygon; mod clip_segment_segment; diff --git a/src/query/closest_points/closest_points.rs b/src/query/closest_points/closest_points.rs index 987ebd71..76b6dc15 100644 --- a/src/query/closest_points/closest_points.rs +++ b/src/query/closest_points/closest_points.rs @@ -1,6 +1,6 @@ use crate::math::{Isometry, Point, Real}; -use std::mem; +use core::mem; /// Closest points information. #[derive(Debug, PartialEq, Clone, Copy)] diff --git a/src/query/closest_points/mod.rs b/src/query/closest_points/mod.rs index 43cae0b3..ee6c0948 100644 --- a/src/query/closest_points/mod.rs +++ b/src/query/closest_points/mod.rs @@ -5,7 +5,7 @@ pub use self::closest_points_ball_ball::closest_points_ball_ball; pub use self::closest_points_ball_convex_polyhedron::{ closest_points_ball_convex_polyhedron, closest_points_convex_polyhedron_ball, }; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::closest_points_composite_shape_shape::{ closest_points_composite_shape_shape, closest_points_shape_composite_shape, CompositeShapeAgainstShapeClosestPointsVisitor, @@ -32,7 +32,7 @@ pub use self::closest_points_support_map_support_map::closest_points_support_map mod closest_points; mod closest_points_ball_ball; mod closest_points_ball_convex_polyhedron; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod closest_points_composite_shape_shape; mod closest_points_cuboid_cuboid; mod closest_points_cuboid_triangle; diff --git a/src/query/contact/contact.rs b/src/query/contact/contact.rs index fad4b976..96426efe 100644 --- a/src/query/contact/contact.rs +++ b/src/query/contact/contact.rs @@ -1,6 +1,6 @@ use crate::math::{Isometry, Point, Real, Vector}; use na::{self, Unit}; -use std::mem; +use core::mem; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; diff --git a/src/query/contact/mod.rs b/src/query/contact/mod.rs index 6a6dcd9c..7271a27f 100644 --- a/src/query/contact/mod.rs +++ b/src/query/contact/mod.rs @@ -5,7 +5,7 @@ pub use self::contact_ball_ball::contact_ball_ball; pub use self::contact_ball_convex_polyhedron::{ contact_ball_convex_polyhedron, contact_convex_polyhedron_ball, }; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::contact_composite_shape_shape::{ contact_composite_shape_shape, contact_shape_composite_shape, }; @@ -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(feature = "alloc")] pub use self::contact_support_map_support_map::{ contact_support_map_support_map, contact_support_map_support_map_with_params, }; @@ -22,10 +22,10 @@ pub use self::contact_support_map_support_map::{ mod contact; mod contact_ball_ball; mod contact_ball_convex_polyhedron; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] 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(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 ec0392a6..d2761176 100644 --- a/src/query/contact_manifolds/contact_manifold.rs +++ b/src/query/contact_manifolds/contact_manifold.rs @@ -1,5 +1,7 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::PackedFeatureId; +#[cfg(feature = "dim3")] +use alloc::vec::Vec; #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] @@ -141,7 +143,7 @@ impl ContactManifold( // Traverse qbvh1 first. let ls_aabb2_1 = shape2.compute_aabb(&pos12).loosened(prediction); - let mut old_manifolds = std::mem::take(manifolds); + let mut old_manifolds = core::mem::take(manifolds); let mut leaf1_fn = |leaf1: &u32| { composite1.map_part_at( diff --git a/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs b/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs index 5d1651a6..7bcafe92 100644 --- a/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs +++ b/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs @@ -58,7 +58,7 @@ pub fn contact_manifold_halfspace_pfm<'a, ManifoldData, ContactData, S2>( // We do this clone to perform contact tracking and transfer impulses. // TODO: find a more efficient way of doing this. - let old_manifold_points = std::mem::take(&mut manifold.points); + let old_manifold_points = core::mem::take(&mut manifold.points); for i in 0..feature2.num_vertices { let vtx2 = feature2.vertices[i]; 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 d5bcd58c..198302d3 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs @@ -1,3 +1,5 @@ +use alloc::{boxed::Box, vec::Vec}; + use crate::bounding_volume::BoundingVolume; use crate::math::{Isometry, Real}; use crate::query::contact_manifolds::contact_manifolds_workspace::{ @@ -81,7 +83,7 @@ pub fn contact_manifolds_heightfield_composite_shape( let qbvh2 = composite2.qbvh(); let mut stack2 = Vec::new(); let ls_aabb2_1 = qbvh2.root_aabb().transform_by(pos12).loosened(prediction); - let mut old_manifolds = std::mem::take(manifolds); + let mut old_manifolds = core::mem::take(manifolds); heightfield1.map_elements_in_local_aabb(&ls_aabb2_1, &mut |leaf1, part1| { #[cfg(feature = "dim2")] diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs index bf63ed58..0c4f3095 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs @@ -1,3 +1,5 @@ +use alloc::{boxed::Box, vec::Vec}; + use crate::bounding_volume::BoundingVolume; use crate::math::{Isometry, Real}; use crate::query::contact_manifolds::contact_manifolds_workspace::{ @@ -115,7 +117,7 @@ pub fn contact_manifolds_heightfield_shape( */ // TODO: somehow precompute the Aabb and reuse it? let ls_aabb2 = shape2.compute_aabb(pos12).loosened(prediction); - let mut old_manifolds = std::mem::take(manifolds); + let mut old_manifolds = core::mem::take(manifolds); heightfield1.map_elements_in_local_aabb(&ls_aabb2, &mut |i, part1| { #[cfg(feature = "dim2")] diff --git a/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs b/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs index 4531bf56..b97ed4ee 100644 --- a/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_trimesh_shape.rs @@ -1,3 +1,5 @@ +use alloc::{boxed::Box, vec::Vec}; + use crate::bounding_volume::{Aabb, BoundingVolume}; use crate::math::{Isometry, Real}; use crate::query::contact_manifolds::contact_manifolds_workspace::{ @@ -116,12 +118,12 @@ pub fn contact_manifolds_trimesh_shape( new_local_aabb2.maxs += extra_margin; let local_aabb2 = new_local_aabb2; // .loosened(prediction * 2.0); // TODO: what would be the best value? - std::mem::swap( + core::mem::swap( &mut workspace.old_interferences, &mut workspace.interferences, ); - std::mem::swap(manifolds, &mut old_manifolds); + core::mem::swap(manifolds, &mut old_manifolds); // This assertion may fire due to the invalid triangle_ids that the // near-phase may return (due to SIMD sentinels). diff --git a/src/query/contact_manifolds/contact_manifolds_workspace.rs b/src/query/contact_manifolds/contact_manifolds_workspace.rs index 44097094..d2583560 100644 --- a/src/query/contact_manifolds/contact_manifolds_workspace.rs +++ b/src/query/contact_manifolds/contact_manifolds_workspace.rs @@ -1,5 +1,6 @@ #![allow(clippy::multiple_bound_locations)] // for impl_downcast +use alloc::boxed::Box; use downcast_rs::{impl_downcast, DowncastSync}; use crate::query::contact_manifolds::{ diff --git a/src/query/contact_manifolds/polygon_polygon_contact_generator.rs b/src/query/contact_manifolds/polygon_polygon_contact_generator.rs index ac2c60f8..2d2791c4 100644 --- a/src/query/contact_manifolds/polygon_polygon_contact_generator.rs +++ b/src/query/contact_manifolds/polygon_polygon_contact_generator.rs @@ -52,10 +52,10 @@ fn generate_contacts<'a>( let mut swapped = false; if sep2.0 > sep1.0 { - std::mem::swap(&mut sep1, &mut sep2); - std::mem::swap(&mut m1, &mut m2); - std::mem::swap(&mut p1, &mut p2); - std::mem::swap(&mut m12, &mut m21); + core::mem::swap(&mut sep1, &mut sep2); + core::mem::swap(&mut m1, &mut m2); + core::mem::swap(&mut p1, &mut p2); + core::mem::swap(&mut m12, &mut m21); manifold.swap_identifiers(); swapped = true; } diff --git a/src/query/default_query_dispatcher.rs b/src/query/default_query_dispatcher.rs index 19067c67..730713ff 100644 --- a/src/query/default_query_dispatcher.rs +++ b/src/query/default_query_dispatcher.rs @@ -4,13 +4,14 @@ use crate::query::{ self, details::NonlinearShapeCastMode, ClosestPoints, Contact, NonlinearRigidMotion, QueryDispatcher, ShapeCastHit, Unsupported, }; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use crate::query::{ contact_manifolds::{ContactManifoldsWorkspace, NormalConstraints}, query_dispatcher::PersistentQueryDispatcher, ContactManifold, }; use crate::shape::{HalfSpace, Segment, Shape, ShapeType}; +use alloc::vec::Vec; /// A dispatcher that exposes built-in queries #[derive(Debug, Clone)] @@ -63,7 +64,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { pos12, s1, s2, )) } else { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] if let Some(c1) = shape1.as_composite_shape() { return Ok(query::details::intersection_test_composite_shape_shape( self, pos12, c1, shape2, @@ -122,7 +123,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { pos12, s1, s2, )) } else { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] if let Some(c1) = shape1.as_composite_shape() { return Ok(query::details::distance_composite_shape_shape( self, pos12, c1, shape2, @@ -174,7 +175,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { pos12, shape1, b2, prediction, )) } else { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] if let (Some(s1), Some(s2)) = (shape1.as_support_map(), shape2.as_support_map()) { return Ok(query::details::contact_support_map_support_map( pos12, s1, s2, prediction, @@ -254,7 +255,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { pos12, s1, s2, max_dist, )) } else { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] if let Some(c1) = shape1.as_composite_shape() { return Ok(query::details::closest_points_composite_shape_shape( self, pos12, c1, shape2, max_dist, @@ -306,7 +307,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { options, )) } else { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] if let Some(heightfield1) = shape1.as_heightfield() { return query::details::cast_shapes_heightfield_shape( self, @@ -381,7 +382,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { ), ) } else { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] if let Some(c1) = shape1.as_composite_shape() { return Ok(query::details::cast_shapes_nonlinear_composite_shape_shape( self, @@ -417,7 +418,7 @@ impl QueryDispatcher for DefaultQueryDispatcher { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl PersistentQueryDispatcher for DefaultQueryDispatcher where diff --git a/src/query/distance/mod.rs b/src/query/distance/mod.rs index 9d243bea..7b927cf5 100644 --- a/src/query/distance/mod.rs +++ b/src/query/distance/mod.rs @@ -5,7 +5,7 @@ pub use self::distance_ball_ball::distance_ball_ball; pub use self::distance_ball_convex_polyhedron::{ distance_ball_convex_polyhedron, distance_convex_polyhedron_ball, }; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::distance_composite_shape_shape::{ distance_composite_shape_shape, distance_shape_composite_shape, CompositeShapeAgainstAnyDistanceVisitor, @@ -22,7 +22,7 @@ pub use self::distance_support_map_support_map::{ mod distance; mod distance_ball_ball; mod distance_ball_convex_polyhedron; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod distance_composite_shape_shape; mod distance_cuboid_cuboid; mod distance_halfspace_support_map; diff --git a/src/query/epa/epa2.rs b/src/query/epa/epa2.rs index 49961a80..60c8f693 100644 --- a/src/query/epa/epa2.rs +++ b/src/query/epa/epa2.rs @@ -1,7 +1,7 @@ //! Two-dimensional penetration depth queries using the Expanding Polytope Algorithm. -use std::cmp::Ordering; -use std::collections::BinaryHeap; +use alloc::{collections::BinaryHeap, vec::Vec}; +use core::cmp::Ordering; use na::{self, Unit}; use num::Bounded; diff --git a/src/query/epa/epa3.rs b/src/query/epa/epa3.rs index 5ed482d4..51f22a80 100644 --- a/src/query/epa/epa3.rs +++ b/src/query/epa/epa3.rs @@ -5,10 +5,11 @@ use crate::query::gjk::{self, CSOPoint, ConstantOrigin, VoronoiSimplex}; use crate::query::PointQueryWithLocation; use crate::shape::{SupportMap, Triangle, TrianglePointLocation}; use crate::utils; +use alloc::collections::BinaryHeap; +use alloc::vec::Vec; +use core::cmp::Ordering; use na::{self, Unit}; use num::Bounded; -use std::cmp::Ordering; -use std::collections::BinaryHeap; #[derive(Copy, Clone, PartialEq)] struct FaceId { @@ -467,7 +468,10 @@ impl EPA { } #[allow(dead_code)] + #[cfg(feature = "std")] fn print_silhouette(&self) { + use std::{print, println}; + print!("Silhouette points: "); for i in 0..self.silhouette.len() { let edge = &self.silhouette[i]; diff --git a/src/query/error.rs b/src/query/error.rs index 8c8e7582..ac042635 100644 --- a/src/query/error.rs +++ b/src/query/error.rs @@ -1,4 +1,4 @@ -use std::fmt; +use core::fmt; /// Error indicating that a query is not supported between certain shapes #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -10,5 +10,5 @@ impl fmt::Display for Unsupported { } } -#[cfg(feature = "std")] -impl std::error::Error for Unsupported {} +#[cfg(feature = "alloc")] +impl core::error::Error for Unsupported {} diff --git a/src/query/gjk/cso_point.rs b/src/query/gjk/cso_point.rs index 943f5b9d..3243012b 100644 --- a/src/query/gjk/cso_point.rs +++ b/src/query/gjk/cso_point.rs @@ -1,7 +1,7 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::SupportMap; use na::Unit; -use std::ops::Sub; +use core::ops::Sub; /// A point of a Configuration-Space Obstacle. /// diff --git a/src/query/gjk/voronoi_simplex3.rs b/src/query/gjk/voronoi_simplex3.rs index 8742e58d..6d79d352 100644 --- a/src/query/gjk/voronoi_simplex3.rs +++ b/src/query/gjk/voronoi_simplex3.rs @@ -6,7 +6,7 @@ use crate::shape::{ TrianglePointLocation, }; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; // for .abs() /// A simplex of dimension up to 3 that uses Voronoï regions for computing point projections. diff --git a/src/query/intersection_test/mod.rs b/src/query/intersection_test/mod.rs index a3efc8de..3cbd2e97 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(feature = "alloc")] pub use self::intersection_test_composite_shape_shape::{ intersection_test_composite_shape_shape, intersection_test_shape_composite_shape, IntersectionCompositeShapeShapeVisitor, @@ -28,7 +28,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(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 ed6e1537..34b458dc 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(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_shape_cast::{cast_shapes_nonlinear, NonlinearRigidMotion}; pub use self::point::{PointProjection, PointQuery, PointQueryWithLocation}; -#[cfg(feature = "std")] +#[cfg(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::split::{IntersectResult, SplitResult}; mod clip; pub mod closest_points; pub mod contact; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod contact_manifolds; mod default_query_dispatcher; mod distance; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub mod epa; mod error; pub mod gjk; @@ -63,7 +63,7 @@ mod ray; pub mod sat; mod shape_cast; mod split; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub mod visitors; /// Queries dedicated to specific pairs of shapes. @@ -71,7 +71,7 @@ pub mod details { pub use super::clip::*; pub use super::closest_points::*; pub use super::contact::*; - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] pub use super::contact_manifolds::*; pub use super::distance::*; pub use super::intersection_test::*; diff --git a/src/query/nonlinear_shape_cast/mod.rs b/src/query/nonlinear_shape_cast/mod.rs index a2882677..f17c129d 100644 --- a/src/query/nonlinear_shape_cast/mod.rs +++ b/src/query/nonlinear_shape_cast/mod.rs @@ -1,6 +1,6 @@ //! Implementation details of the `cast_shapes_nonlinear` function. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::nonlinear_shape_cast_composite_shape_shape::{ cast_shapes_nonlinear_composite_shape_shape, cast_shapes_nonlinear_shape_composite_shape, NonlinearTOICompositeShapeShapeBestFirstVisitor, @@ -12,7 +12,7 @@ pub use self::nonlinear_shape_cast_support_map_support_map::{ cast_shapes_nonlinear_support_map_support_map, NonlinearShapeCastMode, }; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod nonlinear_shape_cast_composite_shape_shape; //mod cast_shapes_nonlinear_halfspace_support_map; mod nonlinear_rigid_motion; diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs index a19a2a20..ec782aca 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs @@ -1,4 +1,4 @@ -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; // for .abs() use na::{RealField, Unit}; diff --git a/src/query/point/mod.rs b/src/query/point/mod.rs index 2e3e3067..4d95f495 100644 --- a/src/query/point/mod.rs +++ b/src/query/point/mod.rs @@ -1,20 +1,20 @@ //! Point inclusion and projection. -#[cfg(feature = "std")] +#[cfg(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(feature = "alloc")] pub use self::point_support_map::local_point_projection_on_support_map; mod point_aabb; mod point_ball; mod point_bounding_sphere; mod point_capsule; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod point_composite_shape; #[cfg(feature = "dim3")] mod point_cone; @@ -22,13 +22,13 @@ mod point_cuboid; #[cfg(feature = "dim3")] mod point_cylinder; mod point_halfspace; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod point_heightfield; #[doc(hidden)] pub mod point_query; mod point_round_shape; mod point_segment; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod point_support_map; #[cfg(feature = "dim3")] mod point_tetrahedron; diff --git a/src/query/point/point_round_shape.rs b/src/query/point/point_round_shape.rs index 64eabfce..ed01ea2b 100644 --- a/src/query/point/point_round_shape.rs +++ b/src/query/point/point_round_shape.rs @@ -8,12 +8,12 @@ use crate::shape::{FeatureId, RoundShape, SupportMap}; impl PointQuery for RoundShape { #[inline] fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { - #[cfg(not(feature = "std"))] // TODO: can’t be used without std because of EPA + #[cfg(not(feature = "alloc"))] return unimplemented!( - "The projection of points on a round shapes isn’t supported on no-std platforms yet." + "The projection of points on a round shape isn't supported without alloc yet." ); - #[cfg(feature = "std")] // TODO: can’t be used without std because of EPA + #[cfg(feature = "alloc")] return crate::query::details::local_point_projection_on_support_map( self, &mut VoronoiSimplex::new(), diff --git a/src/query/point/point_support_map.rs b/src/query/point/point_support_map.rs index 78e2a181..871dbef0 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(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(feature = "alloc")] use crate::shape::ConvexPolygon; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(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 7a355f50..a8b3d123 100644 --- a/src/query/query_dispatcher.rs +++ b/src/query/query_dispatcher.rs @@ -1,14 +1,15 @@ use crate::math::{Isometry, Real, Vector}; use crate::query::details::ShapeCastOptions; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use crate::query::{ contact_manifolds::{ContactManifoldsWorkspace, NormalConstraints}, ContactManifold, }; use crate::query::{ClosestPoints, Contact, NonlinearRigidMotion, ShapeCastHit, Unsupported}; use crate::shape::Shape; +use alloc::vec::Vec; -#[cfg(feature = "std")] +#[cfg(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. @@ -207,7 +208,7 @@ where ) -> Option); } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl PersistentQueryDispatcher for QueryDispatcherChain where diff --git a/src/query/ray/mod.rs b/src/query/ray/mod.rs index 71c90f7b..e47b1563 100644 --- a/src/query/ray/mod.rs +++ b/src/query/ray/mod.rs @@ -3,7 +3,7 @@ #[doc(inline)] pub use self::ray::{Ray, RayCast, RayIntersection}; pub use self::ray_ball::ray_toi_with_ball; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::ray_composite_shape::{ RayCompositeShapeToiAndNormalBestFirstVisitor, RayCompositeShapeToiBestFirstVisitor, }; @@ -18,11 +18,11 @@ pub mod ray; mod ray_aabb; mod ray_ball; mod ray_bounding_sphere; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod ray_composite_shape; mod ray_cuboid; mod ray_halfspace; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod ray_heightfield; mod ray_round_shape; mod ray_support_map; diff --git a/src/query/ray/ray_aabb.rs b/src/query/ray/ray_aabb.rs index 3cb4be40..66cbe5b7 100644 --- a/src/query/ray/ray_aabb.rs +++ b/src/query/ray/ray_aabb.rs @@ -1,4 +1,4 @@ -use std::mem; +use core::mem; use na; diff --git a/src/query/ray/ray_support_map.rs b/src/query/ray/ray_support_map.rs index b1bd386b..5438ac5a 100644 --- a/src/query/ray/ray_support_map.rs +++ b/src/query/ray/ray_support_map.rs @@ -1,5 +1,5 @@ use na; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; // for .abs() use crate::math::Real; @@ -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(feature = "alloc", feature = "dim2"))] use crate::shape::ConvexPolygon; -#[cfg(all(feature = "std", feature = "dim3"))] +#[cfg(all(feature = "alloc", feature = "dim3"))] use crate::shape::ConvexPolyhedron; use crate::shape::{Capsule, FeatureId, Segment, SupportMap}; #[cfg(feature = "dim3")] @@ -126,7 +126,7 @@ impl RayCast for Capsule { } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl RayCast for ConvexPolyhedron { fn cast_local_ray_and_get_normal( &self, @@ -145,7 +145,7 @@ impl RayCast for ConvexPolyhedron { } #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl RayCast for ConvexPolygon { fn cast_local_ray_and_get_normal( &self, diff --git a/src/query/ray/ray_triangle.rs b/src/query/ray/ray_triangle.rs index 602bab05..4de6d4bb 100644 --- a/src/query/ray/ray_triangle.rs +++ b/src/query/ray/ray_triangle.rs @@ -6,7 +6,7 @@ use crate::shape::{FeatureId, Triangle}; #[cfg(feature = "dim3")] use {crate::math::Point, na::Vector3}; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; // for .abs() impl RayCast for Triangle { diff --git a/src/query/sat/sat_cuboid_cuboid.rs b/src/query/sat/sat_cuboid_cuboid.rs index 3015e3bc..152af322 100644 --- a/src/query/sat/sat_cuboid_cuboid.rs +++ b/src/query/sat/sat_cuboid_cuboid.rs @@ -1,6 +1,6 @@ use crate::math::{Isometry, Real, Vector, DIM}; use crate::shape::{Cuboid, SupportMap}; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::RealField; // For .copysign() /// Computes the separation of two cuboids along `axis1`. diff --git a/src/query/shape_cast/mod.rs b/src/query/shape_cast/mod.rs index 95a82520..062615d6 100644 --- a/src/query/shape_cast/mod.rs +++ b/src/query/shape_cast/mod.rs @@ -5,7 +5,7 @@ pub use self::shape_cast_ball_ball::cast_shapes_ball_ball; pub use self::shape_cast_halfspace_support_map::{ cast_shapes_halfspace_support_map, cast_shapes_support_map_halfspace, }; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::{ shape_cast_composite_shape_shape::{ cast_shapes_composite_shape_shape, cast_shapes_shape_composite_shape, @@ -17,10 +17,10 @@ pub use self::{ mod shape_cast; mod shape_cast_ball_ball; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod shape_cast_composite_shape_shape; mod shape_cast_halfspace_support_map; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod shape_cast_heightfield_shape; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod shape_cast_support_map_support_map; diff --git a/src/query/split/mod.rs b/src/query/split/mod.rs index b3ee010c..cd59bff2 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(feature = "alloc", feature = "dim3"))] mod split_trimesh; diff --git a/src/query/split/split_trimesh.rs b/src/query/split/split_trimesh.rs index fa0e96df..c873dcfd 100644 --- a/src/query/split/split_trimesh.rs +++ b/src/query/split/split_trimesh.rs @@ -5,8 +5,9 @@ use crate::query::{IntersectResult, PointQuery, SplitResult}; use crate::shape::{Cuboid, FeatureId, Polyline, Segment, Shape, TriMesh, TriMeshFlags, Triangle}; use crate::transformation::{intersect_meshes, MeshIntersectionError}; use crate::utils::{hashmap::HashMap, SortedPair, WBasis}; +use alloc::{vec, vec::Vec}; +use core::cmp::Ordering; use spade::{handles::FixedVertexHandle, ConstrainedDelaunayTriangulation, Triangulation as _}; -use std::cmp::Ordering; struct Triangulation { delaunay: ConstrainedDelaunayTriangulation>, @@ -231,7 +232,7 @@ impl TriMesh { // The plane splits the triangle into 1 + 2 triangles. // First, make sure the edge indices are consecutive. if e2 != (e1 + 1) % 3 { - std::mem::swap(&mut e1, &mut e2); + core::mem::swap(&mut e1, &mut e2); } let ia = e2; // The first point of the second edge is the vertex shared by both edges. @@ -549,7 +550,7 @@ impl TriMesh { // The plane splits the triangle into 1 + 2 triangles. // First, make sure the edge indices are consecutive. if e2 != (e1 + 1) % 3 { - std::mem::swap(&mut e1, &mut e2); + core::mem::swap(&mut e1, &mut e2); } let ia = e2; // The first point of the second edge is the vertex shared by both edges. diff --git a/src/query/visitors/aabb_sets_interferences_collector.rs b/src/query/visitors/aabb_sets_interferences_collector.rs index e87bb484..250946cb 100644 --- a/src/query/visitors/aabb_sets_interferences_collector.rs +++ b/src/query/visitors/aabb_sets_interferences_collector.rs @@ -1,4 +1,5 @@ use crate::math::{Isometry, Matrix, Real}; +use alloc::vec::Vec; /// Spatial partitioning data structure visitor collecting interferences with a given bounding volume. pub struct AabbSetsInterferencesCollector<'a, T: 'a> { diff --git a/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs b/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs index d0e76dca..3be637bb 100644 --- a/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs +++ b/src/query/visitors/bounding_volume_intersections_simultaneous_visitor.rs @@ -1,9 +1,9 @@ use crate::bounding_volume::SimdAabb; use crate::math::{Isometry, Real, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdSimultaneousVisitStatus, SimdSimultaneousVisitor}; +use core::marker::PhantomData; use na::SimdValue; use simba::simd::SimdBool as _; -use std::marker::PhantomData; #[cfg(feature = "parallel")] use crate::partitioning::{QbvhNode, SimdNodeIndex}; diff --git a/src/query/visitors/bounding_volume_intersections_visitor.rs b/src/query/visitors/bounding_volume_intersections_visitor.rs index 050d17dc..0cfb604c 100644 --- a/src/query/visitors/bounding_volume_intersections_visitor.rs +++ b/src/query/visitors/bounding_volume_intersections_visitor.rs @@ -1,8 +1,8 @@ use crate::bounding_volume::{Aabb, SimdAabb}; use crate::math::SIMD_WIDTH; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; +use core::marker::PhantomData; use simba::simd::SimdBool as _; -use std::marker::PhantomData; /// Spatial partitioning data structure visitor collecting interferences with a given bounding volume. pub struct BoundingVolumeIntersectionsVisitor { diff --git a/src/query/visitors/point_intersections_visitor.rs b/src/query/visitors/point_intersections_visitor.rs index 98dd3e14..704e959e 100644 --- a/src/query/visitors/point_intersections_visitor.rs +++ b/src/query/visitors/point_intersections_visitor.rs @@ -1,8 +1,8 @@ use crate::bounding_volume::SimdAabb; use crate::math::{Point, Real, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; +use core::marker::PhantomData; use simba::simd::{SimdBool as _, SimdValue}; -use std::marker::PhantomData; // TODO: add a point cost fn. diff --git a/src/query/visitors/ray_intersections_visitor.rs b/src/query/visitors/ray_intersections_visitor.rs index 8f0e4d9d..aa5ef803 100644 --- a/src/query/visitors/ray_intersections_visitor.rs +++ b/src/query/visitors/ray_intersections_visitor.rs @@ -2,8 +2,8 @@ use crate::bounding_volume::SimdAabb; use crate::math::{Real, SimdReal, SIMD_WIDTH}; use crate::partitioning::{SimdVisitStatus, SimdVisitor}; use crate::query::{Ray, SimdRay}; +use core::marker::PhantomData; use simba::simd::{SimdBool as _, SimdValue}; -use std::marker::PhantomData; /// Bounding Volume Tree visitor collecting intersections with a given ray. pub struct RayIntersectionsVisitor<'a, T, F> { diff --git a/src/shape/ball.rs b/src/shape/ball.rs index 677246ab..746fe002 100644 --- a/src/shape/ball.rs +++ b/src/shape/ball.rs @@ -1,4 +1,3 @@ -#[cfg(feature = "std")] use either::Either; use na::Unit; @@ -33,7 +32,7 @@ impl Ball { /// ball. Instead, a convex polygon approximation (with `nsubdivs` /// subdivisions) is returned. Returns `None` if that approximation had degenerate /// normals (for example if the scaling factor along one axis is zero). - #[cfg(all(feature = "dim2", feature = "std"))] + #[cfg(all(feature = "dim2", feature = "alloc"))] #[inline] pub fn scaled( self, @@ -60,7 +59,7 @@ impl Ball { /// ball. Instead, a convex polygon approximation (with `nsubdivs` /// subdivisions) is returned. Returns `None` if that approximation had degenerate /// normals (for example if the scaling factor along one axis is zero). - #[cfg(all(feature = "dim3", feature = "std"))] + #[cfg(all(feature = "dim3", feature = "alloc"))] #[inline] pub fn scaled( self, diff --git a/src/shape/capsule.rs b/src/shape/capsule.rs index 357e2571..4f79796a 100644 --- a/src/shape/capsule.rs +++ b/src/shape/capsule.rs @@ -2,7 +2,7 @@ use crate::math::{Isometry, Point, Real, Rotation, Vector}; use crate::shape::{Segment, SupportMap}; use na::Unit; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use either::Either; #[cfg(feature = "rkyv")] @@ -109,7 +109,7 @@ impl Capsule { /// capsule. Instead, a convex polygon approximation (with `nsubdivs` /// subdivisions) is returned. Returns `None` if that approximation had degenerate /// normals (for example if the scaling factor along one axis is zero). - #[cfg(all(feature = "dim2", feature = "std"))] + #[cfg(all(feature = "dim2", feature = "alloc"))] pub fn scaled( self, scale: &Vector, @@ -139,7 +139,7 @@ impl Capsule { /// capsule. Instead, a convex polygon approximation (with `nsubdivs` /// subdivisions) is returned. Returns `None` if that approximation had degenerate /// normals (for example if the scaling factor along one axis is zero). - #[cfg(all(feature = "dim3", feature = "std"))] + #[cfg(all(feature = "dim3", feature = "alloc"))] pub fn scaled( self, scale: &Vector, diff --git a/src/shape/composite_shape.rs b/src/shape/composite_shape.rs index db69e46d..d3aaabf7 100644 --- a/src/shape/composite_shape.rs +++ b/src/shape/composite_shape.rs @@ -7,7 +7,7 @@ use crate::shape::Shape; /// /// 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(feature = "alloc")] pub trait SimdCompositeShape { /// Applies a function to one sub-shape of this composite shape. fn map_part_at( @@ -20,7 +20,7 @@ pub trait SimdCompositeShape { fn qbvh(&self) -> &Qbvh; } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub trait TypedSimdCompositeShape { type PartShape: ?Sized + Shape; type PartNormalConstraints: ?Sized + NormalConstraints; @@ -44,7 +44,7 @@ pub trait TypedSimdCompositeShape { fn typed_qbvh(&self) -> &Qbvh; } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl TypedSimdCompositeShape for dyn SimdCompositeShape + '_ { type PartShape = dyn Shape; type PartNormalConstraints = dyn NormalConstraints; diff --git a/src/shape/compound.rs b/src/shape/compound.rs index 7be11a95..9ca4e9c8 100644 --- a/src/shape/compound.rs +++ b/src/shape/compound.rs @@ -11,6 +11,7 @@ use crate::shape::{ConvexPolygon, TriMesh, Triangle}; use crate::shape::{Shape, SharedShape, SimdCompositeShape, TypedSimdCompositeShape}; #[cfg(feature = "dim2")] use crate::transformation::hertel_mehlhorn; +use alloc::vec::Vec; /// A compound shape with an aabb bounding volume. /// diff --git a/src/shape/cone.rs b/src/shape/cone.rs index beeabb6a..04b84e68 100644 --- a/src/shape/cone.rs +++ b/src/shape/cone.rs @@ -5,10 +5,10 @@ use crate::shape::SupportMap; use na; use num::Zero; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use either::Either; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::RealField; // for .copysign() #[cfg(feature = "rkyv")] @@ -50,7 +50,7 @@ impl Cone { /// cone. Instead, a convex polyhedral approximation (with `nsubdivs` /// subdivisions) is returned. Returns `None` if that approximation had degenerate /// normals (for example if the scaling factor along one axis is zero). - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[inline] pub fn scaled( self, diff --git a/src/shape/convex_polygon.rs b/src/shape/convex_polygon.rs index 8a5825ac..8c1f2f0e 100644 --- a/src/shape/convex_polygon.rs +++ b/src/shape/convex_polygon.rs @@ -1,6 +1,7 @@ use crate::math::{Point, Real, Vector}; use crate::shape::{FeatureId, PackedFeatureId, PolygonalFeature, PolygonalFeatureMap, SupportMap}; use crate::utils; +use alloc::vec::Vec; use na::{self, ComplexField, RealField, Unit}; /// A 2D convex polygon. diff --git a/src/shape/convex_polyhedron.rs b/src/shape/convex_polyhedron.rs index ed907e19..0e5b782d 100644 --- a/src/shape/convex_polyhedron.rs +++ b/src/shape/convex_polyhedron.rs @@ -3,11 +3,12 @@ use crate::shape::{FeatureId, PackedFeatureId, PolygonalFeature, PolygonalFeatur // use crate::transformation; use crate::utils::hashmap::{Entry, HashMap}; use crate::utils::{self, SortedPair}; -use na::{self, ComplexField, Point2, Unit}; -use std::f64; - +#[cfg(feature = "alloc")] +use alloc::vec::Vec; +use core::f64; #[cfg(not(feature = "std"))] -use na::ComplexField; // for .abs() +use na::ComplexField; // for .abs(), .sqrt(), and .sin_cos() +use na::{self, Point2, Unit}; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; @@ -134,7 +135,7 @@ impl ConvexPolyhedron { points: Vec>, indices: &[[u32; DIM]], ) -> Option { - let eps = ComplexField::sqrt(crate::math::DEFAULT_EPSILON); + let eps = crate::math::DEFAULT_EPSILON.sqrt(); let mut vertices = Vec::new(); let mut edges = Vec::::new(); @@ -461,7 +462,7 @@ impl ConvexPolyhedron { local_dir: &Unit>, eps: Real, ) -> FeatureId { - let (seps, ceps) = ComplexField::sin_cos(eps); + let (seps, ceps) = eps.sin_cos(); let support_pt_id = utils::point_cloud_support_point_id(local_dir.as_ref(), &self.points); let vertex = &self.vertices[support_pt_id]; diff --git a/src/shape/cuboid.rs b/src/shape/cuboid.rs index e03e27dc..a7aa88bb 100644 --- a/src/shape/cuboid.rs +++ b/src/shape/cuboid.rs @@ -7,7 +7,7 @@ use crate::shape::{FeatureId, PackedFeatureId, PolygonalFeature, SupportMap}; use crate::utils::WSign; use na::Unit; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::RealField; // for .copysign() #[cfg(feature = "rkyv")] diff --git a/src/shape/cylinder.rs b/src/shape/cylinder.rs index fb4c5444..e5d642f3 100644 --- a/src/shape/cylinder.rs +++ b/src/shape/cylinder.rs @@ -5,10 +5,10 @@ use crate::shape::SupportMap; use na; use num::Zero; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use either::Either; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::RealField; // for .copysign() #[cfg(feature = "rkyv")] @@ -52,7 +52,7 @@ impl Cylinder { /// cylinder. Instead, a convex polyhedral approximation (with `nsubdivs` /// subdivisions) is returned. Returns `None` if that approximation had degenerate /// normals (for example if the scaling factor along one axis is zero). - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[inline] pub fn scaled( self, diff --git a/src/shape/heightfield2.rs b/src/shape/heightfield2.rs index 245cc4cc..0c72ba5a 100644 --- a/src/shape/heightfield2.rs +++ b/src/shape/heightfield2.rs @@ -1,8 +1,8 @@ +use core::ops::Range; #[cfg(not(feature = "std"))] use na::ComplexField; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use na::DVector; -use std::ops::Range; use na::Point2; @@ -33,7 +33,7 @@ pub struct HeightField { aabb: Aabb, } -#[cfg(feature = "std")] +#[cfg(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 58c1b01b..d2549a48 100644 --- a/src/shape/heightfield3.rs +++ b/src/shape/heightfield3.rs @@ -1,6 +1,6 @@ -#[cfg(feature = "std")] +use core::ops::Range; +#[cfg(feature = "alloc")] use na::DMatrix; -use std::ops::Range; use crate::bounding_volume::Aabb; use crate::math::{Real, Vector}; @@ -76,7 +76,7 @@ pub struct HeightField { flags: HeightFieldFlags, } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl HeightField { /// Initializes a new heightfield with the given heights, scaling factor, and flags. pub fn new(heights: DMatrix, scale: Vector) -> Self { diff --git a/src/shape/mod.rs b/src/shape/mod.rs index 740edbc3..6df94b4e 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -16,7 +16,7 @@ pub use self::shape::{Shape, ShapeType, TypedShape}; pub use self::support_map::SupportMap; pub use self::triangle::{Triangle, TriangleOrientation, TrianglePointLocation}; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::{ composite_shape::{SimdCompositeShape, TypedSimdCompositeShape}, compound::Compound, @@ -25,10 +25,10 @@ pub use self::{ }; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::convex_polygon::ConvexPolygon; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::heightfield2::*; #[cfg(feature = "dim2")] pub use self::polygonal_feature2d::PolygonalFeature; @@ -36,19 +36,19 @@ pub use self::polygonal_feature2d::PolygonalFeature; #[cfg(feature = "dim3")] pub use self::cone::Cone; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::convex_polyhedron::ConvexPolyhedron; #[cfg(feature = "dim3")] pub use self::cylinder::Cylinder; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] 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")] +#[cfg(feature = "alloc")] pub use self::trimesh::*; /// A cylinder dilated by a sphere (so it has round corners). @@ -63,25 +63,25 @@ 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(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(feature = "alloc")] pub type RoundConvexPolygon = RoundShape; pub(crate) use self::round_shape::RoundShapeRef; mod ball; mod capsule; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] #[doc(hidden)] pub mod composite_shape; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod compound; mod cuboid; mod half_space; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod polyline; mod round_shape; mod segment; @@ -92,33 +92,33 @@ pub mod support_map; mod triangle; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod convex_polygon; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod heightfield2; #[cfg(feature = "dim3")] mod cone; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod convex_polyhedron; #[cfg(feature = "dim3")] mod cylinder; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod heightfield3; #[cfg(feature = "dim3")] mod polygonal_feature3d; mod polygonal_feature_map; #[cfg(feature = "dim3")] mod tetrahedron; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub(crate) mod trimesh; // TODO: move this elsewhere? mod feature_id; #[cfg(feature = "dim2")] mod polygonal_feature2d; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod shared_shape; mod triangle_pseudo_normals; diff --git a/src/shape/polygonal_feature2d.rs b/src/shape/polygonal_feature2d.rs index 65e33b45..a2c4c707 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(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(feature = "alloc")] pub fn contacts( pos12: &Isometry, pos21: &Isometry, @@ -75,7 +75,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(feature = "alloc")] pub fn face_vertex_contacts( pos12: &Isometry, face1: &Self, @@ -105,7 +105,7 @@ impl PolygonalFeature { } /// Computes the contacts between two polygonal faces. - #[cfg(feature = "std")] + #[cfg(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 ccc195f1..a3b00b6f 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(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(feature = "alloc")] pub fn contacts( pos12: &Isometry, _pos21: &Isometry, @@ -91,7 +91,7 @@ impl PolygonalFeature { } } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn contacts_edge_edge( pos12: &Isometry, face1: &PolygonalFeature, @@ -204,7 +204,7 @@ impl PolygonalFeature { } } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn contacts_face_face( pos12: &Isometry, face1: &PolygonalFeature, diff --git a/src/shape/polygonal_feature_map.rs b/src/shape/polygonal_feature_map.rs index d5c331e7..dda5c9d6 100644 --- a/src/shape/polygonal_feature_map.rs +++ b/src/shape/polygonal_feature_map.rs @@ -10,7 +10,7 @@ use { approx::AbsDiffEq, }; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::{ComplexField, RealField}; // for .abs() and .copysign() /// Trait implemented by convex shapes with features with polyhedral approximations. diff --git a/src/shape/polyline.rs b/src/shape/polyline.rs index 46662e12..e3db04ea 100644 --- a/src/shape/polyline.rs +++ b/src/shape/polyline.rs @@ -4,6 +4,8 @@ use crate::partitioning::Qbvh; use crate::query::{PointProjection, PointQueryWithLocation}; use crate::shape::composite_shape::SimdCompositeShape; use crate::shape::{FeatureId, Segment, SegmentPointLocation, Shape, TypedSimdCompositeShape}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; use crate::query::details::NormalConstraints; #[cfg(not(feature = "std"))] @@ -112,7 +114,7 @@ impl Polyline { unsafe { let len = self.indices.len() * 2; let data = self.indices.as_ptr() as *const u32; - std::slice::from_raw_parts(data, len) + core::slice::from_raw_parts(data, len) } } @@ -192,8 +194,8 @@ impl Polyline { // Start node reached: build polyline and start next component component_indices.push([(i - start_i) as u32, 0]); components.push(Polyline::new( - std::mem::take(&mut component_vertices), - Some(std::mem::take(&mut component_indices)), + core::mem::take(&mut component_vertices), + Some(core::mem::take(&mut component_indices)), )); if i + 1 < indices.len() { diff --git a/src/shape/segment.rs b/src/shape/segment.rs index 41b598cc..4089a416 100644 --- a/src/shape/segment.rs +++ b/src/shape/segment.rs @@ -3,8 +3,8 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::{FeatureId, SupportMap}; +use core::mem; use na::{self, Unit}; -use std::mem; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; diff --git a/src/shape/shape.rs b/src/shape/shape.rs index 23a7a074..893d0b34 100644 --- a/src/shape/shape.rs +++ b/src/shape/shape.rs @@ -1,14 +1,16 @@ +#[cfg(feature = "alloc")] +use alloc::{boxed::Box, vec::Vec}; use core::fmt::Debug; use crate::bounding_volume::{Aabb, BoundingSphere, BoundingVolume}; use crate::mass_properties::MassProperties; use crate::math::{Isometry, Point, Real, Vector}; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use crate::num::Float; use crate::query::{PointQuery, RayCast}; #[cfg(feature = "serde-serialize")] use crate::shape::SharedShape; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use crate::shape::{composite_shape::SimdCompositeShape, Compound, HeightField, Polyline, TriMesh}; use crate::shape::{ Ball, Capsule, Cuboid, FeatureId, HalfSpace, PolygonalFeatureMap, RoundCuboid, RoundShape, @@ -18,11 +20,11 @@ use crate::shape::{ use crate::shape::{Cone, Cylinder, RoundCone, RoundCylinder}; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use crate::shape::{ConvexPolyhedron, RoundConvexPolyhedron}; #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use crate::shape::{ConvexPolygon, RoundConvexPolygon}; use downcast_rs::{impl_downcast, DowncastSync}; use na::{RealField, Unit}; @@ -104,24 +106,24 @@ pub enum TypedShape<'a> { /// A triangle shape. Triangle(&'a Triangle), /// A triangle mesh shape. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] TriMesh(&'a TriMesh), /// A set of segments. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Polyline(&'a Polyline), /// A shape representing a full half-space. HalfSpace(&'a HalfSpace), /// A heightfield shape. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] HeightField(&'a HeightField), /// A Compound shape. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Compound(&'a Compound), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] ConvexPolygon(&'a ConvexPolygon), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] /// A convex polyhedron. ConvexPolyhedron(&'a ConvexPolyhedron), #[cfg(feature = "dim3")] @@ -146,11 +148,11 @@ pub enum TypedShape<'a> { RoundCone(&'a RoundCone), /// A convex polyhedron with rounded corners. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] RoundConvexPolyhedron(&'a RoundConvexPolyhedron), /// A convex polygon with rounded corners. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] RoundConvexPolygon(&'a RoundConvexPolygon), /// A custom user-defined shape. #[cfg_attr(feature = "serde-serialize", serde(skip))] @@ -164,20 +166,20 @@ impl Debug for TypedShape<'_> { Self::Capsule(arg0) => f.debug_tuple("Capsule").field(arg0).finish(), Self::Segment(arg0) => f.debug_tuple("Segment").field(arg0).finish(), Self::Triangle(arg0) => f.debug_tuple("Triangle").field(arg0).finish(), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::TriMesh(arg0) => f.debug_tuple("TriMesh").field(arg0).finish(), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::Polyline(arg0) => f.debug_tuple("Polyline").field(arg0).finish(), Self::HalfSpace(arg0) => f.debug_tuple("HalfSpace").field(arg0).finish(), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::HeightField(arg0) => f.debug_tuple("HeightField").field(arg0).finish(), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::Compound(arg0) => f.debug_tuple("Compound").field(arg0).finish(), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::ConvexPolygon(arg0) => f.debug_tuple("ConvexPolygon").field(arg0).finish(), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::ConvexPolyhedron(arg0) => f.debug_tuple("ConvexPolyhedron").field(arg0).finish(), #[cfg(feature = "dim3")] Self::Cylinder(arg0) => f.debug_tuple("Cylinder").field(arg0).finish(), @@ -190,12 +192,12 @@ impl Debug for TypedShape<'_> { #[cfg(feature = "dim3")] Self::RoundCone(arg0) => f.debug_tuple("RoundCone").field(arg0).finish(), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::RoundConvexPolyhedron(arg0) => { f.debug_tuple("RoundConvexPolyhedron").field(arg0).finish() } #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Self::RoundConvexPolygon(arg0) => { f.debug_tuple("RoundConvexPolygon").field(arg0).finish() } @@ -220,24 +222,24 @@ pub(crate) enum DeserializableTypedShape { /// A triangle shape. Triangle(Triangle), /// A triangle mesh shape. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] TriMesh(TriMesh), /// A set of segments. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Polyline(Polyline), /// A shape representing a full half-space. HalfSpace(HalfSpace), /// A heightfield shape. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] HeightField(HeightField), /// A Compound shape. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] Compound(Compound), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] ConvexPolygon(ConvexPolygon), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] /// A convex polyhedron. ConvexPolyhedron(ConvexPolyhedron), #[cfg(feature = "dim3")] @@ -264,11 +266,11 @@ pub(crate) enum DeserializableTypedShape { RoundCone(RoundCone), /// A convex polyhedron with rounded corners. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] RoundConvexPolyhedron(RoundConvexPolyhedron), /// A convex polygon with rounded corners. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] RoundConvexPolygon(RoundConvexPolygon), /// A custom user-defined shape. #[allow(dead_code)] @@ -285,20 +287,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(feature = "alloc")] DeserializableTypedShape::TriMesh(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::Polyline(s) => Some(SharedShape::new(s)), DeserializableTypedShape::HalfSpace(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::HeightField(s) => Some(SharedShape::new(s)), - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::Compound(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::ConvexPolygon(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::ConvexPolyhedron(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim3")] DeserializableTypedShape::Cylinder(s) => Some(SharedShape::new(s)), @@ -311,10 +313,10 @@ impl DeserializableTypedShape { #[cfg(feature = "dim3")] DeserializableTypedShape::RoundCone(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::RoundConvexPolyhedron(s) => Some(SharedShape::new(s)), #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] DeserializableTypedShape::RoundConvexPolygon(s) => Some(SharedShape::new(s)), DeserializableTypedShape::Custom => None, } @@ -331,7 +333,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { /// Clones this shape into a boxed trait-object. /// /// The boxed trait-object has the same concrete type as `Self`. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[deprecated = "renamed to `clone_dyn`"] fn clone_box(&self) -> Box { self.clone_dyn() @@ -340,7 +342,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { /// Clones this shape into a boxed trait-object. /// /// The boxed trait-object has the same concrete type as `Self`. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box; /// Scales this shape by `scale` into a boxed trait-object. @@ -348,7 +350,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { /// In some cases, the resulting shape doesn’t have the same type as Self. For example, /// if a non-uniform scale is provided and Self as a [`Ball`], then the result will be discretized /// (based on the `num_subdivisions` parameter) as a `ConvexPolyhedron` (in 3D) or `ConvexPolygon` (in 2D). - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option>; /// Computes the [`Aabb`] of this shape with the given position. @@ -393,7 +395,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { None } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { None } @@ -492,45 +494,45 @@ impl dyn Shape { } /// Converts this abstract shape to a compound shape, if it is one. - #[cfg(feature = "std")] + #[cfg(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(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(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(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(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(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(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(feature = "alloc")] pub fn as_heightfield_mut(&mut self) -> Option<&mut HeightField> { self.downcast_mut() } @@ -555,37 +557,37 @@ impl dyn Shape { /// Converts this abstract shape to a convex polygon, if it is one. #[cfg(feature = "dim2")] - #[cfg(feature = "std")] + #[cfg(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(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(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(feature = "alloc")] pub fn as_round_convex_polygon_mut(&mut self) -> Option<&mut RoundConvexPolygon> { self.downcast_mut() } #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] pub fn as_convex_polyhedron(&self) -> Option<&ConvexPolyhedron> { self.downcast_ref() } #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] pub fn as_convex_polyhedron_mut(&mut self) -> Option<&mut ConvexPolyhedron> { self.downcast_mut() } @@ -636,25 +638,25 @@ impl dyn Shape { /// Converts this abstract shape to a round convex polyhedron, if it is one. #[cfg(feature = "dim3")] - #[cfg(feature = "std")] + #[cfg(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(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(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) @@ -712,12 +714,12 @@ impl Shape for Ball { } impl Shape for Cuboid { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale))) } @@ -776,12 +778,12 @@ impl Shape for Cuboid { } impl Shape for Capsule { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) @@ -833,12 +835,12 @@ impl Shape for Capsule { } impl Shape for Triangle { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale))) } @@ -904,12 +906,12 @@ impl Shape for Triangle { } impl Shape for Segment { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale))) } @@ -967,7 +969,7 @@ impl Shape for Segment { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Shape for Compound { fn clone_dyn(&self) -> Box { Box::new(self.clone()) @@ -1029,13 +1031,13 @@ impl Shape for Compound { }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { Some(self as &dyn SimdCompositeShape) } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Shape for Polyline { fn clone_dyn(&self) -> Box { Box::new(self.clone()) @@ -1079,13 +1081,13 @@ impl Shape for Polyline { Real::frac_pi_4() } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { Some(self as &dyn SimdCompositeShape) } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Shape for TriMesh { fn clone_dyn(&self) -> Box { Box::new(self.clone()) @@ -1142,13 +1144,13 @@ impl Shape for TriMesh { return self.feature_normal(_feature); } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> { Some(self as &dyn SimdCompositeShape) } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Shape for HeightField { fn clone_dyn(&self) -> Box { Box::new(self.clone()) @@ -1194,7 +1196,7 @@ impl Shape for HeightField { } #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Shape for ConvexPolygon { fn clone_dyn(&self) -> Box { Box::new(self.clone()) @@ -1261,7 +1263,7 @@ impl Shape for ConvexPolygon { } #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Shape for ConvexPolyhedron { fn clone_dyn(&self) -> Box { Box::new(self.clone()) @@ -1330,12 +1332,12 @@ impl Shape for ConvexPolyhedron { #[cfg(feature = "dim3")] impl Shape for Cylinder { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) @@ -1388,12 +1390,12 @@ impl Shape for Cylinder { #[cfg(feature = "dim3")] impl Shape for Cone { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { let scaled = self.scaled(scale, num_subdivisions)?; Some(scaled.either::<_, _, Box>(|x| Box::new(x), |x| Box::new(x))) @@ -1448,12 +1450,12 @@ impl Shape for Cone { } impl Shape for HalfSpace { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(*self) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, _num_subdivisions: u32) -> Option> { Some(Box::new(self.scaled(scale)?)) } @@ -1501,12 +1503,12 @@ impl Shape for HalfSpace { macro_rules! impl_shape_for_round_shape( ($S: ty, $Tag: ident, $t: tt) => { impl Shape for RoundShape<$S> { - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn clone_dyn(&self) -> Box { Box::new(self.clone()) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn scale_dyn(&self, scale: &Vector, num_subdivisions: u32) -> Option> { $t(self, scale, num_subdivisions) } @@ -1585,7 +1587,7 @@ impl_shape_for_round_shape!( ); #[cfg(feature = "dim2")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl_shape_for_round_shape!( ConvexPolygon, RoundConvexPolygon, @@ -1650,7 +1652,7 @@ impl_shape_for_round_shape!( ); #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl_shape_for_round_shape!( ConvexPolyhedron, RoundConvexPolyhedron, diff --git a/src/shape/shared_shape.rs b/src/shape/shared_shape.rs index eb2beeff..be829e41 100644 --- a/src/shape/shared_shape.rs +++ b/src/shape/shared_shape.rs @@ -12,10 +12,11 @@ use crate::shape::{ #[cfg(feature = "dim3")] use crate::shape::{Cone, ConvexPolyhedron, Cylinder}; use crate::transformation::vhacd::{VHACDParameters, VHACD}; +use alloc::sync::Arc; +use alloc::{vec, vec::Vec}; +use core::fmt; +use core::ops::Deref; use na::Unit; -use std::fmt; -use std::ops::Deref; -use std::sync::Arc; use super::TriMeshBuilderError; diff --git a/src/shape/tetrahedron.rs b/src/shape/tetrahedron.rs index 649fda40..2282c876 100644 --- a/src/shape/tetrahedron.rs +++ b/src/shape/tetrahedron.rs @@ -3,10 +3,10 @@ use crate::math::{Matrix, Point, Real}; use crate::shape::{Segment, Triangle}; use crate::utils; +use core::mem; use na::Matrix3; -use std::mem; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; // for .abs() #[cfg(feature = "rkyv")] diff --git a/src/shape/triangle.rs b/src/shape/triangle.rs index d7da82c9..3cde3572 100644 --- a/src/shape/triangle.rs +++ b/src/shape/triangle.rs @@ -5,12 +5,12 @@ use crate::shape::SupportMap; use crate::shape::{PolygonalFeature, Segment}; use crate::utils; +use core::mem; use na::{self, ComplexField, Unit}; use num::Zero; -use std::mem; #[cfg(feature = "dim3")] -use {crate::shape::FeatureId, std::f64}; +use {crate::shape::FeatureId, core::f64}; #[cfg(feature = "dim2")] use crate::shape::PackedFeatureId; diff --git a/src/shape/triangle_pseudo_normals.rs b/src/shape/triangle_pseudo_normals.rs index 927d7333..4d94c107 100644 --- a/src/shape/triangle_pseudo_normals.rs +++ b/src/shape/triangle_pseudo_normals.rs @@ -1,7 +1,10 @@ -use crate::math::{Real, UnitVector, Vector}; +#[cfg(feature = "alloc")] +use crate::math::Vector; +use crate::math::{Real, UnitVector}; +#[cfg(feature = "alloc")] use na::Vector3; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] use crate::query::details::NormalConstraints; // NOTE: ideally, the normal cone should take into account the point where the normal cone is @@ -28,7 +31,7 @@ pub struct TrianglePseudoNormals { pub edges: [UnitVector; 3], } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl NormalConstraints for TrianglePseudoNormals { /// Projects the given direction to it is contained in the polygonal /// cone defined `self`. @@ -93,7 +96,7 @@ impl NormalConstraints for TrianglePseudoNormals { } #[cfg(test)] -#[cfg(feature = "dim3")] +#[cfg(all(feature = "dim3", feature = "alloc"))] mod test { use crate::math::{Real, Vector}; use crate::shape::TrianglePseudoNormals; diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index 72aa5956..45328d4f 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -3,7 +3,8 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::partitioning::Qbvh; use crate::shape::{FeatureId, Shape, Triangle, TrianglePseudoNormals, TypedSimdCompositeShape}; use crate::utils::HashablePartialEq; -use std::fmt; +use alloc::{vec, vec::Vec}; +use core::fmt; #[cfg(feature = "dim3")] use {crate::shape::Cuboid, crate::utils::SortedPair, na::Unit}; @@ -377,6 +378,7 @@ impl TriMesh { self.compute_topology(flags.contains(TriMeshFlags::DELETE_BAD_TOPOLOGY_TRIANGLES)); } + #[cfg(feature = "std")] if difference.intersects(TriMeshFlags::CONNECTED_COMPONENTS) { self.compute_connected_components(); } @@ -461,8 +463,8 @@ impl TriMesh { .map(|idx| [idx[0] + base_id, idx[1] + base_id, idx[2] + base_id]), ); - let vertices = std::mem::take(&mut self.vertices); - let indices = std::mem::take(&mut self.indices); + let vertices = core::mem::take(&mut self.vertices); + let indices = core::mem::take(&mut self.indices); *self = TriMesh::with_flags(vertices, indices, self.flags).unwrap(); } @@ -479,7 +481,7 @@ impl TriMesh { unsafe { let len = self.indices.len() * 3; let data = self.indices.as_ptr() as *const u32; - std::slice::from_raw_parts(data, len) + core::slice::from_raw_parts(data, len) } } @@ -805,6 +807,8 @@ impl TriMesh { // NOTE: this is private because that calculation is controlled by TriMeshFlags::CONNECTED_COMPONENTS // TODO: we should remove the CONNECTED_COMPONENTS flags and just have this be a free function. + // TODO: this should be no_std compatible once ena is or once we have an alternative for it. + #[cfg(feature = "std")] fn compute_connected_components(&mut self) { use ena::unify::{InPlaceUnificationTable, UnifyKey}; diff --git a/src/transformation/convex_hull2.rs b/src/transformation/convex_hull2.rs index 38b618ed..67c9bbb2 100644 --- a/src/transformation/convex_hull2.rs +++ b/src/transformation/convex_hull2.rs @@ -1,4 +1,5 @@ -use std::marker::PhantomData; +use alloc::vec::Vec; +use core::marker::PhantomData; use crate::math::Real; use crate::transformation::convex_hull_utils::{indexed_support_point_id, support_point_id}; diff --git a/src/transformation/convex_hull3/convex_hull.rs b/src/transformation/convex_hull3/convex_hull.rs index be19b161..9879206d 100644 --- a/src/transformation/convex_hull3/convex_hull.rs +++ b/src/transformation/convex_hull3/convex_hull.rs @@ -4,6 +4,7 @@ use crate::math::Real; use crate::transformation::convex_hull_utils::indexed_support_point_nth; use crate::transformation::convex_hull_utils::{indexed_support_point_id, normalize}; use crate::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point3}; /// Computes the convex hull of a set of 3d points. @@ -250,7 +251,7 @@ fn fix_silhouette_topology( } let mut removing = None; - let old_facets_and_idx = std::mem::take(out_facets_and_idx); + let old_facets_and_idx = core::mem::take(out_facets_and_idx); for i in 0..old_facets_and_idx.len() { let facet_id = (loop_start + i) % old_facets_and_idx.len(); diff --git a/src/transformation/convex_hull3/initial_mesh.rs b/src/transformation/convex_hull3/initial_mesh.rs index 9f4ca40c..77f1d621 100644 --- a/src/transformation/convex_hull3/initial_mesh.rs +++ b/src/transformation/convex_hull3/initial_mesh.rs @@ -4,8 +4,9 @@ use crate::shape::Triangle; use crate::transformation; use crate::transformation::convex_hull_utils::support_point_id; use crate::utils; +use alloc::{vec, vec::Vec}; +use core::cmp::Ordering; use na::{Point2, Point3, Vector3}; -use std::cmp::Ordering; #[derive(Debug)] pub enum InitialMesh { diff --git a/src/transformation/convex_hull3/mod.rs b/src/transformation/convex_hull3/mod.rs index 3f710074..9a87450b 100644 --- a/src/transformation/convex_hull3/mod.rs +++ b/src/transformation/convex_hull3/mod.rs @@ -3,6 +3,7 @@ use self::initial_mesh::{try_get_initial_mesh, InitialMesh}; use self::triangle_facet::TriangleFacet; use self::validation::check_facet_links; pub use convex_hull::{convex_hull, try_convex_hull}; +#[cfg(feature = "std")] pub use validation::check_convex_hull; mod convex_hull; diff --git a/src/transformation/convex_hull3/triangle_facet.rs b/src/transformation/convex_hull3/triangle_facet.rs index fe1a0a0b..691f2cc4 100644 --- a/src/transformation/convex_hull3/triangle_facet.rs +++ b/src/transformation/convex_hull3/triangle_facet.rs @@ -1,5 +1,6 @@ use crate::math::Real; use crate::shape::Triangle; +use alloc::vec::Vec; use na::{Point3, Vector3}; use num::Bounded; diff --git a/src/transformation/convex_hull3/validation.rs b/src/transformation/convex_hull3/validation.rs index 5b9fb5cd..d3268043 100644 --- a/src/transformation/convex_hull3/validation.rs +++ b/src/transformation/convex_hull3/validation.rs @@ -26,7 +26,10 @@ pub fn check_facet_links(ifacet: usize, facets: &[TriangleFacet]) { } /// Checks if a convex-hull is properly formed. +#[cfg(feature = "std")] pub fn check_convex_hull(points: &[Point3], triangles: &[[u32; 3]]) { + use std::println; + use crate::utils::hashmap::{Entry, HashMap}; use crate::utils::SortedPair; let mut edges = HashMap::default(); @@ -93,7 +96,7 @@ pub fn check_convex_hull(points: &[Point3], triangles: &[[u32; 3]]) { assert_eq!(points.len() + triangles.len() - edges.len(), 2); } -// fn print_buildable_vec(desc: &str, elts: &[Point3]) { +// fn print_buildable_vec(desc: &str, elts: &[Point3]) { // print!("let {} = vec![", desc); // for elt in elts { // print!("Point3::new({},{},{}),", elt.x, elt.y, elt.z); diff --git a/src/transformation/ear_clipping.rs b/src/transformation/ear_clipping.rs index d4527a56..52c8257a 100644 --- a/src/transformation/ear_clipping.rs +++ b/src/transformation/ear_clipping.rs @@ -5,6 +5,7 @@ use crate::{ math::{Point, Real}, utils::point_in_triangle::{corner_direction, is_point_in_triangle, Orientation}, }; +use alloc::{vec, vec::Vec}; /// The information stored for each vertex in the ear clipping algorithm. #[derive(Clone, Default)] diff --git a/src/transformation/hertel_mehlhorn.rs b/src/transformation/hertel_mehlhorn.rs index 208b9193..a9d1ea27 100644 --- a/src/transformation/hertel_mehlhorn.rs +++ b/src/transformation/hertel_mehlhorn.rs @@ -1,6 +1,8 @@ //! Hertel-Mehlhorn algorithm for convex partitioning. //! Based on , contributed by embotech AG. +use alloc::vec::Vec; + use crate::math::{Point, Real}; use crate::utils::point_in_triangle::{corner_direction, Orientation}; diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index b83f539b..ada74443 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -7,10 +7,13 @@ use crate::utils; use crate::utils::hashmap::Entry; use crate::utils::hashmap::HashMap; use crate::utils::hashset::HashSet; +use alloc::collections::BTreeMap; +use alloc::{vec, vec::Vec}; +#[cfg(not(feature = "std"))] +use na::ComplexField; use na::{Point3, Vector3}; use rstar::RTree; use spade::{ConstrainedDelaunayTriangulation, InsertionError, Triangulation as _}; -use std::collections::BTreeMap; #[cfg(feature = "wavefront")] use std::path::PathBuf; diff --git a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs index 263260ef..15857b33 100644 --- a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs +++ b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs @@ -7,6 +7,7 @@ use crate::transformation::polygon_intersection::{ PolygonIntersectionTolerances, PolylinePointLocation, }; use crate::utils::WBasis; +use alloc::{vec, vec::Vec}; use na::Point2; #[derive(Copy, Clone, Debug, Default)] @@ -221,6 +222,7 @@ fn segment_plane_intersection( /// lines to copy/paste into the Desmos online graphing tool (for visual debugging), as well as /// some rust code to add to the `tris` array in the `intersect_triangle_common_vertex` test for /// regression checking. +#[cfg(feature = "std")] fn debug_check_intersections( tri1: &Triangle, tri2: &Triangle, @@ -229,6 +231,8 @@ fn debug_check_intersections( poly2: &[Point2], // Projection of tri2 on the basis `basis2` with the origin at tri2.a. intersections: &[TriangleTriangleIntersectionPoint], ) { + use std::{print, println}; + let proj = |vect: Vector| Point2::new(vect.dot(&basis[0]), vect.dot(&basis[1])); let mut incorrect = false; for pt in intersections { diff --git a/src/transformation/mod.rs b/src/transformation/mod.rs index c79f5b3d..f7702b2f 100644 --- a/src/transformation/mod.rs +++ b/src/transformation/mod.rs @@ -4,8 +4,10 @@ pub(crate) use self::convex_hull2::convex_hull2_idx; #[cfg(feature = "dim2")] pub use self::convex_hull2::{convex_hull2 as convex_hull, convex_hull2_idx as convex_hull_idx}; +#[cfg(all(feature = "dim3", feature = "std"))] +pub use self::convex_hull3::check_convex_hull; #[cfg(feature = "dim3")] -pub use self::convex_hull3::{check_convex_hull, convex_hull, try_convex_hull, ConvexHullError}; +pub use self::convex_hull3::{convex_hull, try_convex_hull, ConvexHullError}; #[cfg(feature = "dim3")] pub use self::mesh_intersection::{ intersect_meshes, intersect_meshes_with_tolerances, MeshIntersectionError, diff --git a/src/transformation/polygon_intersection.rs b/src/transformation/polygon_intersection.rs index a770ae4b..997f53b9 100644 --- a/src/transformation/polygon_intersection.rs +++ b/src/transformation/polygon_intersection.rs @@ -1,3 +1,4 @@ +use alloc::{vec, vec::Vec}; use log::error; use na::Point2; use ordered_float::OrderedFloat; @@ -415,7 +416,7 @@ pub fn polygons_intersection_points( } else if let Some(loc2) = loc2 { curr_poly.push(loc2.to_point(poly2)) } else if !curr_poly.is_empty() { - result.push(std::mem::take(&mut curr_poly)); + result.push(core::mem::take(&mut curr_poly)); } })?; @@ -663,7 +664,9 @@ mod test { use crate::shape::Triangle; use crate::transformation::convex_polygons_intersection_points_with_tolerances; use crate::transformation::polygon_intersection::PolygonIntersectionTolerances; + use alloc::vec::Vec; use na::Point2; + use std::println; #[test] fn intersect_triangle_common_vertex() { diff --git a/src/transformation/to_outline/ball_to_outline.rs b/src/transformation/to_outline/ball_to_outline.rs index 0d645efc..f5817ef4 100644 --- a/src/transformation/to_outline/ball_to_outline.rs +++ b/src/transformation/to_outline/ball_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::Ball; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point3, RealField}; #[cfg(not(feature = "std"))] diff --git a/src/transformation/to_outline/capsule_to_outline.rs b/src/transformation/to_outline/capsule_to_outline.rs index 9edc8c2a..8881b10e 100644 --- a/src/transformation/to_outline/capsule_to_outline.rs +++ b/src/transformation/to_outline/capsule_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::{Capsule, Cylinder}; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point3}; impl Capsule { diff --git a/src/transformation/to_outline/cone_to_outline.rs b/src/transformation/to_outline/cone_to_outline.rs index 99e65e33..70d65c15 100644 --- a/src/transformation/to_outline/cone_to_outline.rs +++ b/src/transformation/to_outline/cone_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Cone; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point3, Vector3}; impl Cone { diff --git a/src/transformation/to_outline/cuboid_to_outline.rs b/src/transformation/to_outline/cuboid_to_outline.rs index 0552d07a..009b7c57 100644 --- a/src/transformation/to_outline/cuboid_to_outline.rs +++ b/src/transformation/to_outline/cuboid_to_outline.rs @@ -2,6 +2,7 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real, Vector}; use crate::shape::Cuboid; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; impl Aabb { /// Outlines this Aabb’s shape using polylines. diff --git a/src/transformation/to_outline/cylinder_to_outline.rs b/src/transformation/to_outline/cylinder_to_outline.rs index e893ba19..b4ad3bdf 100644 --- a/src/transformation/to_outline/cylinder_to_outline.rs +++ b/src/transformation/to_outline/cylinder_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Cylinder; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point3, Vector3}; impl Cylinder { diff --git a/src/transformation/to_outline/round_cone_to_outline.rs b/src/transformation/to_outline/round_cone_to_outline.rs index cb1e3c86..6af5fe24 100644 --- a/src/transformation/to_outline/round_cone_to_outline.rs +++ b/src/transformation/to_outline/round_cone_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::RoundCone; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point3, Vector3}; impl RoundCone { 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..8b1af24f 100644 --- a/src/transformation/to_outline/round_convex_polyhedron_to_outline.rs +++ b/src/transformation/to_outline/round_convex_polyhedron_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::RoundConvexPolyhedron; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::Point3; impl RoundConvexPolyhedron { diff --git a/src/transformation/to_outline/round_cuboid_to_outline.rs b/src/transformation/to_outline/round_cuboid_to_outline.rs index 13165c1b..cf653770 100644 --- a/src/transformation/to_outline/round_cuboid_to_outline.rs +++ b/src/transformation/to_outline/round_cuboid_to_outline.rs @@ -2,6 +2,7 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real, Vector}; use crate::shape::RoundCuboid; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; impl RoundCuboid { /// Outlines this round cuboid’s surface with polylines. diff --git a/src/transformation/to_outline/round_cylinder_to_outline.rs b/src/transformation/to_outline/round_cylinder_to_outline.rs index 3cc600ab..629a5b0f 100644 --- a/src/transformation/to_outline/round_cylinder_to_outline.rs +++ b/src/transformation/to_outline/round_cylinder_to_outline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::RoundCylinder; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point3}; impl RoundCylinder { diff --git a/src/transformation/to_polyline/ball_to_polyline.rs b/src/transformation/to_polyline/ball_to_polyline.rs index adb0938a..526e0bb9 100644 --- a/src/transformation/to_polyline/ball_to_polyline.rs +++ b/src/transformation/to_polyline/ball_to_polyline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Ball; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point2, RealField}; impl Ball { diff --git a/src/transformation/to_polyline/capsule_to_polyline.rs b/src/transformation/to_polyline/capsule_to_polyline.rs index 33d0ad38..3c52d949 100644 --- a/src/transformation/to_polyline/capsule_to_polyline.rs +++ b/src/transformation/to_polyline/capsule_to_polyline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Capsule; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point2, RealField, Vector2}; impl Capsule { diff --git a/src/transformation/to_polyline/cuboid_to_polyline.rs b/src/transformation/to_polyline/cuboid_to_polyline.rs index c644b201..0f332fdc 100644 --- a/src/transformation/to_polyline/cuboid_to_polyline.rs +++ b/src/transformation/to_polyline/cuboid_to_polyline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Cuboid; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point2}; impl Cuboid { diff --git a/src/transformation/to_polyline/heightfield_to_polyline.rs b/src/transformation/to_polyline/heightfield_to_polyline.rs index 4e8df586..045cee5c 100644 --- a/src/transformation/to_polyline/heightfield_to_polyline.rs +++ b/src/transformation/to_polyline/heightfield_to_polyline.rs @@ -1,5 +1,6 @@ use crate::math::Real; use crate::shape::HeightField; +use alloc::{vec, vec::Vec}; use na::Point2; impl HeightField { 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..03a3da45 100644 --- a/src/transformation/to_polyline/round_convex_polygon_to_polyline.rs +++ b/src/transformation/to_polyline/round_convex_polygon_to_polyline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::RoundConvexPolygon; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point2}; impl RoundConvexPolygon { diff --git a/src/transformation/to_polyline/round_cuboid_to_polyline.rs b/src/transformation/to_polyline/round_cuboid_to_polyline.rs index 3eaf2e03..82a2fd00 100644 --- a/src/transformation/to_polyline/round_cuboid_to_polyline.rs +++ b/src/transformation/to_polyline/round_cuboid_to_polyline.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::RoundCuboid; use crate::transformation::utils; +use alloc::{vec, vec::Vec}; use na::{self, Point2}; impl RoundCuboid { diff --git a/src/transformation/to_trimesh/ball_to_trimesh.rs b/src/transformation/to_trimesh/ball_to_trimesh.rs index 58f94e69..ecd33ac3 100644 --- a/src/transformation/to_trimesh/ball_to_trimesh.rs +++ b/src/transformation/to_trimesh/ball_to_trimesh.rs @@ -1,6 +1,7 @@ use crate::math::{Point, Real, Vector, DIM}; use crate::shape::Ball; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, ComplexField, Point3, RealField}; impl Ball { diff --git a/src/transformation/to_trimesh/capsule_to_trimesh.rs b/src/transformation/to_trimesh/capsule_to_trimesh.rs index eb30af5f..4ec881eb 100644 --- a/src/transformation/to_trimesh/capsule_to_trimesh.rs +++ b/src/transformation/to_trimesh/capsule_to_trimesh.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Capsule; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point3}; impl Capsule { diff --git a/src/transformation/to_trimesh/cone_to_trimesh.rs b/src/transformation/to_trimesh/cone_to_trimesh.rs index f9f6a447..61402634 100644 --- a/src/transformation/to_trimesh/cone_to_trimesh.rs +++ b/src/transformation/to_trimesh/cone_to_trimesh.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Cone; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point3, RealField, Vector3}; impl Cone { diff --git a/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs b/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs index d91468b1..cae110d3 100644 --- a/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs +++ b/src/transformation/to_trimesh/convex_polyhedron_to_trimesh.rs @@ -1,5 +1,6 @@ use crate::math::Real; use crate::shape::ConvexPolyhedron; +use alloc::vec::Vec; use na::Point3; impl ConvexPolyhedron { diff --git a/src/transformation/to_trimesh/cuboid_to_trimesh.rs b/src/transformation/to_trimesh/cuboid_to_trimesh.rs index 5132cf17..11f78eb6 100644 --- a/src/transformation/to_trimesh/cuboid_to_trimesh.rs +++ b/src/transformation/to_trimesh/cuboid_to_trimesh.rs @@ -2,6 +2,7 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real}; use crate::shape::Cuboid; use crate::transformation::utils; +use alloc::vec::Vec; impl Aabb { /// Discretize the boundary of this Aabb as a triangle-mesh. diff --git a/src/transformation/to_trimesh/cylinder_to_trimesh.rs b/src/transformation/to_trimesh/cylinder_to_trimesh.rs index d9c7c730..1ebec952 100644 --- a/src/transformation/to_trimesh/cylinder_to_trimesh.rs +++ b/src/transformation/to_trimesh/cylinder_to_trimesh.rs @@ -1,6 +1,7 @@ use crate::math::Real; use crate::shape::Cylinder; use crate::transformation::utils; +use alloc::vec::Vec; use na::{self, Point3, RealField, Vector3}; impl Cylinder { diff --git a/src/transformation/to_trimesh/heightfield_to_trimesh.rs b/src/transformation/to_trimesh/heightfield_to_trimesh.rs index 28d27cc3..d464c23f 100644 --- a/src/transformation/to_trimesh/heightfield_to_trimesh.rs +++ b/src/transformation/to_trimesh/heightfield_to_trimesh.rs @@ -1,5 +1,6 @@ use crate::math::Real; use crate::shape::HeightField; +use alloc::vec::Vec; use na::Point3; impl HeightField { diff --git a/src/transformation/utils.rs b/src/transformation/utils.rs index 210f8da1..b50fa980 100644 --- a/src/transformation/utils.rs +++ b/src/transformation/utils.rs @@ -2,6 +2,7 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::na::ComplexField; +use alloc::vec::Vec; #[cfg(feature = "dim3")] use {crate::math::DIM, num::Zero}; @@ -163,7 +164,7 @@ pub fn reverse_clockwising(indices: &mut [[u32; DIM]]) { /// Pushes the index buffer of a closed loop. #[cfg(feature = "dim3")] #[inline] -pub fn push_circle_outline_indices(indices: &mut Vec<[u32; 2]>, range: std::ops::Range) { +pub fn push_circle_outline_indices(indices: &mut Vec<[u32; 2]>, range: core::ops::Range) { indices.extend((range.start..range.end - 1).map(|i| [i, i + 1])); indices.push([range.end - 1, range.start]); } @@ -171,7 +172,7 @@ pub fn push_circle_outline_indices(indices: &mut Vec<[u32; 2]>, range: std::ops: /// Pushes the index buffer of an open chain. #[cfg(feature = "dim3")] #[inline] -pub fn push_open_circle_outline_indices(indices: &mut Vec<[u32; 2]>, range: std::ops::Range) { +pub fn push_open_circle_outline_indices(indices: &mut Vec<[u32; 2]>, range: core::ops::Range) { indices.extend((range.start..range.end - 1).map(|i| [i, i + 1])); } @@ -249,7 +250,7 @@ pub fn push_arc( /// Pushes the index buffer for an arc between `start` and `end` and intermediate points in the /// range `arc`. #[cfg(feature = "dim3")] -pub fn push_arc_idx(start: u32, arc: std::ops::Range, end: u32, out: &mut Vec<[u32; 2]>) { +pub fn push_arc_idx(start: u32, arc: core::ops::Range, end: u32, out: &mut Vec<[u32; 2]>) { if arc.is_empty() { out.push([start, end]); } else { @@ -266,7 +267,7 @@ pub fn push_arc_idx(start: u32, arc: std::ops::Range, end: u32, out: &mut V pub fn apply_revolution( collapse_bottom: bool, collapse_top: bool, - circle_ranges: &[std::ops::Range], + circle_ranges: &[core::ops::Range], nsubdivs: u32, out_vtx: &mut Vec>, // Must be set to the half-profile. out_idx: &mut Vec<[u32; 2]>, diff --git a/src/transformation/vhacd/vhacd.rs b/src/transformation/vhacd/vhacd.rs index 8cd72ee9..450edebf 100644 --- a/src/transformation/vhacd/vhacd.rs +++ b/src/transformation/vhacd/vhacd.rs @@ -19,7 +19,8 @@ use crate::math::{Point, Real, Vector, DIM}; use crate::transformation::vhacd::VHACDParameters; use crate::transformation::voxelization::{VoxelSet, VoxelizedVolume}; -use std::sync::Arc; +use alloc::sync::Arc; +use alloc::vec::Vec; #[cfg(feature = "dim2")] type ConvexHull = Vec>; @@ -363,7 +364,7 @@ impl VHACD { let mut input_parts = Vec::new(); let mut parts = Vec::new(); let mut temp = Vec::new(); - input_parts.push(std::mem::take(&mut voxels)); + input_parts.push(core::mem::take(&mut voxels)); let mut first_iteration = true; self.volume_ch0 = 1.0; @@ -406,7 +407,7 @@ impl VHACD { first_iteration = false; } - std::mem::swap(&mut input_parts, &mut temp); + core::mem::swap(&mut input_parts, &mut temp); // Note that temp is already clear because our previous for // loop used `drain`. However we call `clear` here explicitly // to make sure it still works if we remove the `drain` in the diff --git a/src/transformation/voxelization/voxel_set.rs b/src/transformation/voxelization/voxel_set.rs index 3d3cc452..b242d1ce 100644 --- a/src/transformation/voxelization/voxel_set.rs +++ b/src/transformation/voxelization/voxel_set.rs @@ -20,7 +20,8 @@ use super::{FillMode, VoxelizedVolume}; use crate::bounding_volume::Aabb; use crate::math::{Matrix, Point, Real, Vector, DIM}; use crate::transformation::vhacd::CutPlane; -use std::sync::Arc; +use alloc::sync::Arc; +use alloc::{vec, vec::Vec}; #[cfg(feature = "dim2")] type ConvexHull = Vec>; diff --git a/src/transformation/voxelization/voxelized_volume.rs b/src/transformation/voxelization/voxelized_volume.rs index d4703217..eff47bc0 100644 --- a/src/transformation/voxelization/voxelized_volume.rs +++ b/src/transformation/voxelization/voxelized_volume.rs @@ -20,7 +20,8 @@ use crate::bounding_volume::Aabb; use crate::math::{Point, Real, Vector, DIM}; use crate::query; use crate::transformation::voxelization::{Voxel, VoxelSet}; -use std::sync::Arc; +use alloc::sync::Arc; +use alloc::vec::Vec; /// Controls how the voxelization determines which voxel needs /// to be considered empty, and which ones will be considered full. diff --git a/src/utils/as_bytes.rs b/src/utils/as_bytes.rs index 3a201d13..9b172139 100644 --- a/src/utils/as_bytes.rs +++ b/src/utils/as_bytes.rs @@ -1,5 +1,5 @@ -use std::mem; -use std::slice; +use core::mem; +use core::slice; use na::{Point2, Point3, Vector2, Vector3}; use simba::scalar::RealField; diff --git a/src/utils/cleanup.rs b/src/utils/cleanup.rs index 2526220e..18d51002 100644 --- a/src/utils/cleanup.rs +++ b/src/utils/cleanup.rs @@ -1,5 +1,6 @@ use crate::math::{Point, Real}; -use std::iter; +use alloc::vec::Vec; +use core::iter; /// 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]]) { diff --git a/src/utils/deterministic_state.rs b/src/utils/deterministic_state.rs index 1c782006..81a0519d 100644 --- a/src/utils/deterministic_state.rs +++ b/src/utils/deterministic_state.rs @@ -1,5 +1,5 @@ +use core::hash::BuildHasher; use std::collections::hash_map::DefaultHasher; -use std::hash::BuildHasher; /// A hasher builder that creates `DefaultHasher` with default keys. #[derive(Default)] diff --git a/src/utils/fx_hasher.rs b/src/utils/fx_hasher.rs index 914cc988..17c37776 100644 --- a/src/utils/fx_hasher.rs +++ b/src/utils/fx_hasher.rs @@ -18,12 +18,12 @@ impl Default for FxHasher32 { impl FxHasher32 { #[inline] fn add_to_hash(&mut self, i: u32) { - use std::ops::BitXor; + use core::ops::BitXor; self.hash = self.hash.rotate_left(5).bitxor(i).wrapping_mul(K); } } -impl std::hash::Hasher for FxHasher32 { +impl core::hash::Hasher for FxHasher32 { #[inline] fn write(&mut self, mut bytes: &[u8]) { let read_u32 = |bytes: &[u8]| u32::from_ne_bytes(bytes[..4].try_into().unwrap()); diff --git a/src/utils/hashable_partial_eq.rs b/src/utils/hashable_partial_eq.rs index d6994a52..3f209750 100644 --- a/src/utils/hashable_partial_eq.rs +++ b/src/utils/hashable_partial_eq.rs @@ -1,5 +1,5 @@ use crate::utils::AsBytes; -use std::hash::{Hash, Hasher}; +use core::hash::{Hash, Hasher}; /// A structure that implements `Eq` and is hashable even if the wrapped data implements only /// `PartialEq`. diff --git a/src/utils/hashmap.rs b/src/utils/hashmap.rs index 02560f98..fa281638 100644 --- a/src/utils/hashmap.rs +++ b/src/utils/hashmap.rs @@ -8,7 +8,7 @@ use std::collections::HashMap as StdHashMap; /// Serializes only the capacity of a hash-map instead of its actual content. #[cfg(feature = "serde-serialize")] -pub fn serialize_hashmap_capacity( +pub fn serialize_hashmap_capacity( map: &StdHashMap, s: S, ) -> Result { @@ -22,7 +22,7 @@ pub fn deserialize_hashmap_capacity< D: serde::Deserializer<'de>, K, V, - H: std::hash::BuildHasher + Default, + H: core::hash::BuildHasher + Default, >( d: D, ) -> Result, D::Error> { @@ -52,8 +52,12 @@ pub fn deserialize_hashmap_capacity< /// Deterministic hashmap using [`indexmap::IndexMap`] #[cfg(feature = "enhanced-determinism")] pub type FxHashMap32 = - indexmap::IndexMap>; + indexmap::IndexMap>; #[cfg(feature = "enhanced-determinism")] pub use {self::FxHashMap32 as HashMap, indexmap::map::Entry}; + +#[cfg(not(feature = "enhanced-determinism"))] +pub use hashbrown::hash_map::Entry; +/// Hashmap using [`hashbrown::HashMap`] #[cfg(not(feature = "enhanced-determinism"))] -pub use {rustc_hash::FxHashMap as HashMap, std::collections::hash_map::Entry}; +pub type HashMap = hashbrown::hash_map::HashMap; diff --git a/src/utils/hashset.rs b/src/utils/hashset.rs index f33f60b7..732c916d 100644 --- a/src/utils/hashset.rs +++ b/src/utils/hashset.rs @@ -8,7 +8,7 @@ use std::collections::HashSet as StdHashSet; /// Serializes only the capacity of a hash-set instead of its actual content. #[cfg(feature = "serde-serialize")] -pub fn serialize_hashset_capacity( +pub fn serialize_hashset_capacity( set: &StdHashSet, s: S, ) -> Result { @@ -22,7 +22,7 @@ pub fn deserialize_hashset_capacity< D: serde::Deserializer<'de>, K, V, - H: std::hash::BuildHasher + Default, + H: core::hash::BuildHasher + Default, >( d: D, ) -> Result, D::Error> { @@ -30,7 +30,7 @@ pub fn deserialize_hashset_capacity< impl<'de> serde::de::Visitor<'de> for CapacityVisitor { type Value = u64; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { write!(formatter, "an integer between 0 and 2^64") } @@ -49,8 +49,12 @@ pub fn deserialize_hashset_capacity< /// Deterministic hashset using [`indexmap::IndexSet`] #[cfg(feature = "enhanced-determinism")] pub type FxHashSet32 = - indexmap::IndexSet>; + indexmap::IndexSet>; #[cfg(feature = "enhanced-determinism")] pub use self::FxHashSet32 as HashSet; + +#[cfg(not(feature = "enhanced-determinism"))] +pub use hashbrown::hash_set::Entry; +/// Hashset using [`hashbrown::HashSet`] #[cfg(not(feature = "enhanced-determinism"))] -pub use rustc_hash::FxHashSet as HashSet; +pub type HashSet = hashbrown::hash_set::HashSet; diff --git a/src/utils/interval.rs b/src/utils/interval.rs index 9b8d9818..4042eac6 100644 --- a/src/utils/interval.rs +++ b/src/utils/interval.rs @@ -1,8 +1,9 @@ // "Complete Interval Arithmetic and its Implementation on the Computer" // Ulrich W. Kulisch +use alloc::{vec, vec::Vec}; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; use na::{RealField, SimdPartialOrd}; use num::{One, Zero}; -use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; /// A derivable valued function which can be bounded on intervals. pub trait IntervalFunction { diff --git a/src/utils/isometry_ops.rs b/src/utils/isometry_ops.rs index 6b9403f8..9881db27 100644 --- a/src/utils/isometry_ops.rs +++ b/src/utils/isometry_ops.rs @@ -2,7 +2,7 @@ use crate::math::{Isometry, Point, Real, SimdReal, Vector}; use na::SimdComplexField; use na::Unit; // for .abs() -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; /// Extra operations with isometries. diff --git a/src/utils/mod.rs b/src/utils/mod.rs index cf5c8a65..1df70cd1 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(feature = "alloc")] pub use self::cleanup::remove_unused_points; pub(crate) use self::inv::inv; pub use self::isometry_ops::{IsometryOps, IsometryOpt}; @@ -21,7 +21,7 @@ pub use self::as_bytes::AsBytes; pub(crate) use self::consts::*; pub use self::cov::{center_cov, cov}; pub use self::hashable_partial_eq::HashablePartialEq; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub use self::interval::{find_root_intervals, find_root_intervals_to, Interval, IntervalFunction}; pub use self::obb::obb; pub use self::segments_intersection::{segments_intersection2d, SegmentsIntersection}; @@ -29,7 +29,7 @@ pub use self::segments_intersection::{segments_intersection2d, SegmentsIntersect pub(crate) use self::sort::sort2; pub(crate) use self::sort::sort3; pub use self::sorted_pair::SortedPair; -#[cfg(all(feature = "dim3", feature = "std"))] +#[cfg(all(feature = "dim3", feature = "alloc"))] pub(crate) use self::spade::sanitize_spade_point; pub(crate) use self::weighted_value::WeightedValue; pub(crate) use self::wops::{simd_swap, WBasis, WCross, WSign}; @@ -38,7 +38,7 @@ mod as_bytes; mod ccw_face_normal; mod center; #[cfg(feature = "dim3")] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod cleanup; mod consts; mod cov; @@ -47,11 +47,11 @@ mod deterministic_state; #[cfg(feature = "enhanced-determinism")] mod fx_hasher; mod hashable_partial_eq; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub mod hashmap; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub mod hashset; -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod interval; mod inv; mod isometry_ops; @@ -65,7 +65,7 @@ mod sdp_matrix; mod segments_intersection; mod sort; mod sorted_pair; -#[cfg(all(feature = "dim3", feature = "std"))] +#[cfg(all(feature = "dim3", feature = "alloc"))] mod spade; mod weighted_value; mod wops; diff --git a/src/utils/point_in_poly2d.rs b/src/utils/point_in_poly2d.rs index 97e70bb4..e6347565 100644 --- a/src/utils/point_in_poly2d.rs +++ b/src/utils/point_in_poly2d.rs @@ -151,7 +151,7 @@ mod tests { } #[test] - #[cfg(feature = "dim2")] + #[cfg(all(feature = "dim2", feature = "alloc"))] fn point_in_poly2d_concave_exact_vertex_bug() { let poly = crate::shape::Ball::new(1.0).to_polyline(10); assert!(point_in_poly2d(&Point2::origin(), &poly)); diff --git a/src/utils/point_in_triangle.rs b/src/utils/point_in_triangle.rs index dffcc2d8..adb07f08 100644 --- a/src/utils/point_in_triangle.rs +++ b/src/utils/point_in_triangle.rs @@ -37,9 +37,9 @@ pub fn corner_direction(p1: &Point, p2: &Point, p3: &Point) -> .partial_cmp(&0.0) .expect("Found NaN while computing corner direction.") { - std::cmp::Ordering::Less => Orientation::Ccw, - std::cmp::Ordering::Equal => Orientation::None, - std::cmp::Ordering::Greater => Orientation::Cw, + core::cmp::Ordering::Less => Orientation::Ccw, + core::cmp::Ordering::Equal => Orientation::None, + core::cmp::Ordering::Greater => Orientation::Cw, } } diff --git a/src/utils/sdp_matrix.rs b/src/utils/sdp_matrix.rs index 0385a117..9782bee9 100644 --- a/src/utils/sdp_matrix.rs +++ b/src/utils/sdp_matrix.rs @@ -1,6 +1,6 @@ use crate::math::Real; use na::{Matrix2, Matrix3, Matrix3x2, SimdRealField, Vector2, Vector3}; -use std::ops::{Add, Mul}; +use core::ops::{Add, Mul}; #[cfg(feature = "rkyv")] #[cfg(feature = "rkyv")] diff --git a/src/utils/segments_intersection.rs b/src/utils/segments_intersection.rs index d29fb6d6..60159580 100644 --- a/src/utils/segments_intersection.rs +++ b/src/utils/segments_intersection.rs @@ -3,7 +3,7 @@ use na::Point2; use crate::math::Real; use crate::shape::{SegmentPointLocation, Triangle, TriangleOrientation}; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] use na::ComplexField; /// Intersection between two segments. diff --git a/src/utils/sorted_pair.rs b/src/utils/sorted_pair.rs index 8dbfebcc..cd25aa63 100644 --- a/src/utils/sorted_pair.rs +++ b/src/utils/sorted_pair.rs @@ -1,6 +1,6 @@ -use std::cmp::PartialOrd; -use std::mem; -use std::ops::Deref; +use core::cmp::PartialOrd; +use core::mem; +use core::ops::Deref; /// A pair of elements sorted in increasing order. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -33,11 +33,11 @@ impl Deref for SortedPair { // TODO: can we avoid these manual impls of Hash/PartialEq/Eq for the archived types? #[cfg(feature = "rkyv")] -impl std::hash::Hash for ArchivedSortedPair +impl core::hash::Hash for ArchivedSortedPair where - [::Archived; 2]: std::hash::Hash, + [::Archived; 2]: core::hash::Hash, { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { self.0.hash(state) } } diff --git a/src/utils/weighted_value.rs b/src/utils/weighted_value.rs index b4619332..59cd5c23 100644 --- a/src/utils/weighted_value.rs +++ b/src/utils/weighted_value.rs @@ -1,5 +1,5 @@ use crate::math::Real; -use std::cmp::Ordering; +use core::cmp::Ordering; #[derive(Copy, Clone)] pub struct WeightedValue { diff --git a/src/utils/z_order.rs b/src/utils/z_order.rs index dc7a7d77..f9a98d31 100644 --- a/src/utils/z_order.rs +++ b/src/utils/z_order.rs @@ -1,5 +1,5 @@ +use core::cmp::Ordering; use num_traits::float::FloatCore; -use std::cmp::Ordering; #[allow(dead_code)] // We don't use this currently, but might in the future. pub fn z_cmp_ints(lhs: &[usize], rhs: &[usize]) -> Ordering { From aa665de7ec91e6f611804c147c97dba5cba45a0d Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 04:07:28 +0200 Subject: [PATCH 02/12] Revert `std` to be a default feature --- crates/parry2d-f64/Cargo.toml | 2 +- crates/parry2d/Cargo.toml | 2 +- crates/parry3d-f64/Cargo.toml | 2 +- crates/parry3d/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/parry2d-f64/Cargo.toml b/crates/parry2d-f64/Cargo.toml index 4cf13c3b..ce5d9fb0 100644 --- a/crates/parry2d-f64/Cargo.toml +++ b/crates/parry2d-f64/Cargo.toml @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "alloc"] +default = ["required-features", "std"] required-features = ["dim2", "f64"] std = [ "nalgebra/std", diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index 4cd7c9af..3d434314 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "alloc"] +default = ["required-features", "std"] required-features = ["dim2", "f32"] std = [ "alloc", diff --git a/crates/parry3d-f64/Cargo.toml b/crates/parry3d-f64/Cargo.toml index 4f800ba9..64a3e552 100644 --- a/crates/parry3d-f64/Cargo.toml +++ b/crates/parry3d-f64/Cargo.toml @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "alloc"] +default = ["required-features", "std"] required-features = ["dim3", "f64"] std = [ "nalgebra/std", diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index a2e67102..ef3269c8 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "alloc"] +default = ["required-features", "std"] required-features = ["dim3", "f32"] std = [ "nalgebra/std", From 5fefaf867898d000678b3e0b124b27a769006e36 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 04:31:13 +0200 Subject: [PATCH 03/12] Make `spade` properly optional --- crates/parry2d-f64/Cargo.toml | 7 ++++--- crates/parry2d/Cargo.toml | 7 ++++--- crates/parry3d-f64/Cargo.toml | 7 ++++--- crates/parry3d/Cargo.toml | 7 ++++--- src/query/default_query_dispatcher.rs | 1 + src/query/query_dispatcher.rs | 1 + src/query/split/mod.rs | 2 +- .../triangle_triangle_intersection.rs | 13 ++++++++----- src/transformation/mod.rs | 4 ++-- src/utils/mod.rs | 4 ++-- 10 files changed, 31 insertions(+), 22 deletions(-) diff --git a/crates/parry2d-f64/Cargo.toml b/crates/parry2d-f64/Cargo.toml index ce5d9fb0..184eade7 100644 --- a/crates/parry2d-f64/Cargo.toml +++ b/crates/parry2d-f64/Cargo.toml @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "std", "spade"] required-features = ["dim2", "f64"] std = [ "nalgebra/std", @@ -30,7 +30,7 @@ std = [ "spade", "thiserror/std", "ena", - "spade/std", + "spade?/std", ] dim2 = [] f64 = [] @@ -39,7 +39,7 @@ serde-serialize = [ "nalgebra/serde-serialize", "arrayvec/serde", "bitflags/serde", - "spade/serde", + "spade?/serde", ] rkyv-serialize = [ "rkyv/validation", @@ -52,6 +52,7 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"] enhanced-determinism = ["simba/libm_force", "indexmap"] parallel = ["rayon"] alloc = ["nalgebra/alloc", "hashbrown"] +spade = ["dep:spade", "alloc"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index 3d434314..346422ee 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -20,7 +20,7 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "std", "spade"] required-features = ["dim2", "f32"] std = [ "alloc", @@ -28,7 +28,7 @@ std = [ "slab", "simba/std", "arrayvec/std", - "spade/std", + "spade?/std", "thiserror/std", "ena", ] @@ -39,7 +39,7 @@ serde-serialize = [ "nalgebra/serde-serialize", "arrayvec/serde", "bitflags/serde", - "spade/serde", + "spade?/serde", ] rkyv-serialize = [ "rkyv/validation", @@ -52,6 +52,7 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"] enhanced-determinism = ["simba/libm_force", "indexmap"] parallel = ["rayon"] alloc = ["nalgebra/alloc", "hashbrown"] +spade = ["dep:spade", "alloc"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically diff --git a/crates/parry3d-f64/Cargo.toml b/crates/parry3d-f64/Cargo.toml index 64a3e552..4dccca10 100644 --- a/crates/parry3d-f64/Cargo.toml +++ b/crates/parry3d-f64/Cargo.toml @@ -20,14 +20,14 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "std", "spade"] required-features = ["dim3", "f64"] std = [ "nalgebra/std", "slab", "simba/std", "arrayvec/std", - "spade/std", + "spade?/std", "thiserror/std", "ena", ] @@ -37,7 +37,7 @@ serde-serialize = [ "serde", "nalgebra/serde-serialize", "bitflags/serde", - "spade/serde", + "spade?/serde", ] rkyv-serialize = [ "rkyv/validation", @@ -52,6 +52,7 @@ parallel = ["rayon"] # Adds `TriMesh:to_obj_file` function. wavefront = ["obj"] alloc = ["nalgebra/alloc", "hashbrown"] +spade = ["dep:spade", "alloc"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index ef3269c8..09c91388 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -20,14 +20,14 @@ maintenance = { status = "actively-developed" } workspace = true [features] -default = ["required-features", "std"] +default = ["required-features", "std", "spade"] required-features = ["dim3", "f32"] std = [ "nalgebra/std", "slab", "simba/std", "arrayvec/std", - "spade/std", + "spade?/std", "thiserror/std", "ena", ] @@ -37,7 +37,7 @@ serde-serialize = [ "serde", "nalgebra/serde-serialize", "bitflags/serde", - "spade/serde", + "spade?/serde", ] rkyv-serialize = [ "rkyv/validation", @@ -53,6 +53,7 @@ parallel = ["rayon"] # Adds `TriMesh:to_obj_file` function. wavefront = ["obj"] alloc = ["nalgebra/alloc", "hashbrown"] +spade = ["dep:spade", "alloc"] improved_fixed_point_support = [] # Do not enable this feature directly. It is automatically diff --git a/src/query/default_query_dispatcher.rs b/src/query/default_query_dispatcher.rs index 730713ff..cfd2b887 100644 --- a/src/query/default_query_dispatcher.rs +++ b/src/query/default_query_dispatcher.rs @@ -11,6 +11,7 @@ use crate::query::{ ContactManifold, }; use crate::shape::{HalfSpace, Segment, Shape, ShapeType}; +#[cfg(feature = "alloc")] use alloc::vec::Vec; /// A dispatcher that exposes built-in queries diff --git a/src/query/query_dispatcher.rs b/src/query/query_dispatcher.rs index a8b3d123..3c4a2b7f 100644 --- a/src/query/query_dispatcher.rs +++ b/src/query/query_dispatcher.rs @@ -7,6 +7,7 @@ use crate::query::{ }; use crate::query::{ClosestPoints, Contact, NonlinearRigidMotion, ShapeCastHit, Unsupported}; use crate::shape::Shape; +#[cfg(feature = "alloc")] use alloc::vec::Vec; #[cfg(feature = "alloc")] diff --git a/src/query/split/mod.rs b/src/query/split/mod.rs index cd59bff2..4a586df9 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 = "alloc", feature = "dim3"))] +#[cfg(all(feature = "dim3", feature = "spade"))] mod split_trimesh; diff --git a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs index 15857b33..d4108e58 100644 --- a/src/transformation/mesh_intersection/triangle_triangle_intersection.rs +++ b/src/transformation/mesh_intersection/triangle_triangle_intersection.rs @@ -176,11 +176,14 @@ pub(crate) fn triangle_triangle_intersection( }, ); - // NOTE: set this to `true` to automatically check if the computed intersection is - // valid, and print debug infos if it is not. - const DEBUG_INTERSECTIONS: bool = false; - if DEBUG_INTERSECTIONS { - debug_check_intersections(tri1, tri2, &basis, &poly1, &poly2, &intersections); + #[cfg(feature = "std")] + { + // NOTE: set this to `true` to automatically check if the computed intersection is + // valid, and print debug infos if it is not. + const DEBUG_INTERSECTIONS: bool = false; + if DEBUG_INTERSECTIONS { + debug_check_intersections(tri1, tri2, &basis, &poly1, &poly2, &intersections); + } } Some(TriangleTriangleIntersection::Polygon(intersections)) diff --git a/src/transformation/mod.rs b/src/transformation/mod.rs index f7702b2f..47d4185b 100644 --- a/src/transformation/mod.rs +++ b/src/transformation/mod.rs @@ -8,7 +8,7 @@ pub use self::convex_hull2::{convex_hull2 as convex_hull, convex_hull2_idx as co pub use self::convex_hull3::check_convex_hull; #[cfg(feature = "dim3")] pub use self::convex_hull3::{convex_hull, try_convex_hull, ConvexHullError}; -#[cfg(feature = "dim3")] +#[cfg(all(feature = "dim3", feature = "spade"))] pub use self::mesh_intersection::{ intersect_meshes, intersect_meshes_with_tolerances, MeshIntersectionError, MeshIntersectionTolerances, @@ -37,7 +37,7 @@ pub(crate) mod ear_clipping; pub(crate) mod hertel_mehlhorn; #[cfg(feature = "dim2")] pub use hertel_mehlhorn::{hertel_mehlhorn, hertel_mehlhorn_idx}; -#[cfg(feature = "dim3")] +#[cfg(all(feature = "dim3", feature = "spade"))] mod mesh_intersection; #[cfg(feature = "dim3")] mod to_outline; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 1df70cd1..a634eef5 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -29,7 +29,7 @@ pub use self::segments_intersection::{segments_intersection2d, SegmentsIntersect pub(crate) use self::sort::sort2; pub(crate) use self::sort::sort3; pub use self::sorted_pair::SortedPair; -#[cfg(all(feature = "dim3", feature = "alloc"))] +#[cfg(all(feature = "dim3", feature = "spade"))] pub(crate) use self::spade::sanitize_spade_point; pub(crate) use self::weighted_value::WeightedValue; pub(crate) use self::wops::{simd_swap, WBasis, WCross, WSign}; @@ -65,7 +65,7 @@ mod sdp_matrix; mod segments_intersection; mod sort; mod sorted_pair; -#[cfg(all(feature = "dim3", feature = "alloc"))] +#[cfg(all(feature = "dim3", feature = "spade"))] mod spade; mod weighted_value; mod wops; From aaaf77cff404a30f91d0edc231120ea6baf4c744 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 14:20:42 +0200 Subject: [PATCH 04/12] Remove unused `ComplexField` imports and use `std` gates rather than `alloc` --- src/bounding_volume/aabb.rs | 4 ++-- .../contact_manifolds/contact_manifolds_capsule_capsule.rs | 3 --- .../nonlinear_shape_cast_support_map_support_map.rs | 2 -- src/query/ray/ray_support_map.rs | 2 -- src/query/ray/ray_triangle.rs | 3 --- src/query/sat/sat_cuboid_cuboid.rs | 2 -- src/shape/cuboid.rs | 3 --- src/shape/cylinder.rs | 3 --- src/shape/polyline.rs | 2 -- src/shape/tetrahedron.rs | 2 +- src/transformation/convex_hull3/validation.rs | 2 ++ src/transformation/to_outline/ball_to_outline.rs | 3 --- src/utils/isometry_ops.rs | 5 +---- 13 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/bounding_volume/aabb.rs b/src/bounding_volume/aabb.rs index f9720921..eb7ce430 100644 --- a/src/bounding_volume/aabb.rs +++ b/src/bounding_volume/aabb.rs @@ -8,8 +8,8 @@ use arrayvec::ArrayVec; use na; use num::Bounded; -#[cfg(not(feature = "std"))] -use na::ComplexField; // for .abs() +#[cfg(all(feature = "dim3", not(feature = "std")))] +use na::ComplexField; // for .sin_cos() use crate::query::{Ray, RayCast}; #[cfg(feature = "rkyv")] diff --git a/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs b/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs index 78f46c2d..8c945383 100644 --- a/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs +++ b/src/query/contact_manifolds/contact_manifolds_capsule_capsule.rs @@ -6,9 +6,6 @@ use crate::shape::{Capsule, PackedFeatureId, Shape}; use approx::AbsDiffEq; use na::Unit; -#[cfg(not(feature = "alloc"))] -use na::ComplexField; // for .abs() - /// Computes the contact manifold between two capsules given as `Shape` trait-objects. pub fn contact_manifold_capsule_capsule_shapes( pos12: &Isometry, diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs index ec782aca..07afafc8 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs @@ -1,5 +1,3 @@ -#[cfg(not(feature = "alloc"))] -use na::ComplexField; // for .abs() use na::{RealField, Unit}; use crate::math::{Point, Real, Vector}; diff --git a/src/query/ray/ray_support_map.rs b/src/query/ray/ray_support_map.rs index 5438ac5a..577c4e1b 100644 --- a/src/query/ray/ray_support_map.rs +++ b/src/query/ray/ray_support_map.rs @@ -1,6 +1,4 @@ use na; -#[cfg(not(feature = "alloc"))] -use na::ComplexField; // for .abs() use crate::math::Real; #[cfg(feature = "dim2")] diff --git a/src/query/ray/ray_triangle.rs b/src/query/ray/ray_triangle.rs index 4de6d4bb..5c30b049 100644 --- a/src/query/ray/ray_triangle.rs +++ b/src/query/ray/ray_triangle.rs @@ -6,9 +6,6 @@ use crate::shape::{FeatureId, Triangle}; #[cfg(feature = "dim3")] use {crate::math::Point, na::Vector3}; -#[cfg(not(feature = "alloc"))] -use na::ComplexField; // for .abs() - impl RayCast for Triangle { #[inline] #[cfg(feature = "dim2")] diff --git a/src/query/sat/sat_cuboid_cuboid.rs b/src/query/sat/sat_cuboid_cuboid.rs index 152af322..73b3b6fb 100644 --- a/src/query/sat/sat_cuboid_cuboid.rs +++ b/src/query/sat/sat_cuboid_cuboid.rs @@ -1,7 +1,5 @@ use crate::math::{Isometry, Real, Vector, DIM}; use crate::shape::{Cuboid, SupportMap}; -#[cfg(not(feature = "alloc"))] -use na::RealField; // For .copysign() /// Computes the separation of two cuboids along `axis1`. #[cfg(feature = "dim3")] diff --git a/src/shape/cuboid.rs b/src/shape/cuboid.rs index a7aa88bb..5b2b2a57 100644 --- a/src/shape/cuboid.rs +++ b/src/shape/cuboid.rs @@ -7,9 +7,6 @@ use crate::shape::{FeatureId, PackedFeatureId, PolygonalFeature, SupportMap}; use crate::utils::WSign; use na::Unit; -#[cfg(not(feature = "alloc"))] -use na::RealField; // for .copysign() - #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; diff --git a/src/shape/cylinder.rs b/src/shape/cylinder.rs index e5d642f3..cb963ffa 100644 --- a/src/shape/cylinder.rs +++ b/src/shape/cylinder.rs @@ -8,9 +8,6 @@ use num::Zero; #[cfg(feature = "alloc")] use either::Either; -#[cfg(not(feature = "alloc"))] -use na::RealField; // for .copysign() - #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; diff --git a/src/shape/polyline.rs b/src/shape/polyline.rs index e3db04ea..6dbeca00 100644 --- a/src/shape/polyline.rs +++ b/src/shape/polyline.rs @@ -8,8 +8,6 @@ use crate::shape::{FeatureId, Segment, SegmentPointLocation, Shape, TypedSimdCom use alloc::vec::Vec; use crate::query::details::NormalConstraints; -#[cfg(not(feature = "std"))] -use na::ComplexField; // for .abs() #[derive(Clone, Debug)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] diff --git a/src/shape/tetrahedron.rs b/src/shape/tetrahedron.rs index 2282c876..a526c266 100644 --- a/src/shape/tetrahedron.rs +++ b/src/shape/tetrahedron.rs @@ -6,7 +6,7 @@ use crate::utils; use core::mem; use na::Matrix3; -#[cfg(not(feature = "alloc"))] +#[cfg(all(feature = "dim2", not(feature = "std")))] use na::ComplexField; // for .abs() #[cfg(feature = "rkyv")] diff --git a/src/transformation/convex_hull3/validation.rs b/src/transformation/convex_hull3/validation.rs index d3268043..04ee5f2e 100644 --- a/src/transformation/convex_hull3/validation.rs +++ b/src/transformation/convex_hull3/validation.rs @@ -1,5 +1,7 @@ use super::TriangleFacet; +#[cfg(feature = "std")] use crate::math::Real; +#[cfg(feature = "std")] use na::Point3; pub fn check_facet_links(ifacet: usize, facets: &[TriangleFacet]) { diff --git a/src/transformation/to_outline/ball_to_outline.rs b/src/transformation/to_outline/ball_to_outline.rs index f5817ef4..2bdbabb6 100644 --- a/src/transformation/to_outline/ball_to_outline.rs +++ b/src/transformation/to_outline/ball_to_outline.rs @@ -4,9 +4,6 @@ use crate::transformation::utils; use alloc::vec::Vec; use na::{self, Point3, RealField}; -#[cfg(not(feature = "std"))] -use na::ComplexField; - impl Ball { /// Outlines this ball’s shape using polylines. pub fn to_outline(&self, nsubdiv: u32) -> (Vec>, Vec<[u32; 2]>) { diff --git a/src/utils/isometry_ops.rs b/src/utils/isometry_ops.rs index 9881db27..f3a7f885 100644 --- a/src/utils/isometry_ops.rs +++ b/src/utils/isometry_ops.rs @@ -1,9 +1,6 @@ use crate::math::{Isometry, Point, Real, SimdReal, Vector}; use na::SimdComplexField; -use na::Unit; // for .abs() - -#[cfg(not(feature = "alloc"))] -use na::ComplexField; +use na::Unit; /// Extra operations with isometries. pub trait IsometryOps { From c8ad561b16e18c44f38a423f1e0dd00d81dbfb15 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 14:36:08 +0200 Subject: [PATCH 05/12] Revert feature gating tests and benches --- crates/parry3d/benches/bounding_volume/mod.rs | 6 ------ crates/parry3d/benches/common/default_gen.rs | 2 -- crates/parry3d/benches/common/mod.rs | 2 -- crates/parry3d/benches/query/ray.rs | 4 ---- crates/parry3d/benches/support_map/mod.rs | 2 -- crates/parry3d/tests/geometry/mod.rs | 6 ------ 6 files changed, 22 deletions(-) diff --git a/crates/parry3d/benches/bounding_volume/mod.rs b/crates/parry3d/benches/bounding_volume/mod.rs index 89813973..8123af9e 100644 --- a/crates/parry3d/benches/bounding_volume/mod.rs +++ b/crates/parry3d/benches/bounding_volume/mod.rs @@ -1,11 +1,9 @@ -#[cfg(feature = "alloc")] use crate::common::generate_trimesh_around_origin; use crate::common::{generate, unref}; use na::Isometry3; use parry3d::bounding_volume::BoundingVolume; use parry3d::bounding_volume::{Aabb, BoundingSphere}; use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; -#[cfg(feature = "alloc")] use parry3d::shape::{ConvexPolyhedron, TriMesh}; use rand::SeedableRng; use rand_isaac::IsaacRng; @@ -134,14 +132,12 @@ bench_method!( m: Isometry3 ); -#[cfg(feature = "alloc")] bench_method!( bench_convex_aabb, aabb: Aabb, c: ConvexPolyhedron, m: Isometry3 ); -#[cfg(feature = "alloc")] bench_method!( bench_convex_bounding_sphere, bounding_sphere: BoundingSphere, @@ -149,14 +145,12 @@ bench_method!( m: Isometry3 ); -#[cfg(feature = "alloc")] bench_method_gen!( bench_mesh_aabb, aabb: Aabb, mesh: TriMesh = generate_trimesh_around_origin, m: Isometry3 = generate ); -#[cfg(feature = "alloc")] bench_method_gen!( bench_mesh_bounding_sphere, bounding_sphere: BoundingSphere, diff --git a/crates/parry3d/benches/common/default_gen.rs b/crates/parry3d/benches/common/default_gen.rs index cb47bbec..0c1486c3 100644 --- a/crates/parry3d/benches/common/default_gen.rs +++ b/crates/parry3d/benches/common/default_gen.rs @@ -5,7 +5,6 @@ use na::{ use parry3d::bounding_volume::{Aabb, BoundingSphere}; use parry3d::math::{Point, Real, Vector}; use parry3d::query::Ray; -#[cfg(feature = "alloc")] use parry3d::shape::ConvexPolyhedron; use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; use rand::distributions::{Distribution, Standard}; @@ -122,7 +121,6 @@ where } } -#[cfg(feature = "alloc")] impl DefaultGen for ConvexPolyhedron where Standard: Distribution, diff --git a/crates/parry3d/benches/common/mod.rs b/crates/parry3d/benches/common/mod.rs index b7779566..746805fc 100644 --- a/crates/parry3d/benches/common/mod.rs +++ b/crates/parry3d/benches/common/mod.rs @@ -1,9 +1,7 @@ pub use self::default_gen::generate; -#[cfg(feature = "alloc")] pub use self::generators::generate_trimesh_around_origin; pub use self::unref::unref; mod default_gen; -#[cfg(feature = "alloc")] mod generators; mod unref; diff --git a/crates/parry3d/benches/query/ray.rs b/crates/parry3d/benches/query/ray.rs index bec0240f..22db6536 100644 --- a/crates/parry3d/benches/query/ray.rs +++ b/crates/parry3d/benches/query/ray.rs @@ -1,11 +1,9 @@ -#[cfg(feature = "alloc")] use crate::common::generate_trimesh_around_origin; use crate::common::{generate, unref}; use na::Isometry3; use parry3d::bounding_volume::{Aabb, BoundingSphere}; use parry3d::query::{Ray, RayCast}; use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; -#[cfg(feature = "alloc")] use parry3d::shape::{ConvexPolyhedron, TriMesh}; use rand::SeedableRng; use rand_isaac::IsaacRng; @@ -156,7 +154,6 @@ bench_method!( solid: bool ); -#[cfg(feature = "alloc")] bench_method!( bench_ray_against_convex_with_normal, cast_ray_and_get_normal, @@ -167,7 +164,6 @@ bench_method!( solid: bool ); -#[cfg(feature = "alloc")] bench_method_gen!( bench_ray_against_trimesh_with_normal, cast_ray_and_get_normal, diff --git a/crates/parry3d/benches/support_map/mod.rs b/crates/parry3d/benches/support_map/mod.rs index 46021a67..fbba0fab 100644 --- a/crates/parry3d/benches/support_map/mod.rs +++ b/crates/parry3d/benches/support_map/mod.rs @@ -1,6 +1,5 @@ use crate::common::{generate, unref}; use na::{Isometry3, Vector3}; -#[cfg(feature = "alloc")] use parry3d::shape::ConvexPolyhedron; use parry3d::shape::SupportMap; use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle}; @@ -61,7 +60,6 @@ bench_method!( m: Isometry3, dir: Vector3 ); -#[cfg(feature = "alloc")] bench_method!( bench_convex_support_map, support_point, diff --git a/crates/parry3d/tests/geometry/mod.rs b/crates/parry3d/tests/geometry/mod.rs index e28c8a2b..25a4e755 100644 --- a/crates/parry3d/tests/geometry/mod.rs +++ b/crates/parry3d/tests/geometry/mod.rs @@ -1,18 +1,12 @@ mod aabb_scale; mod ball_ball_toi; mod ball_triangle_toi; -#[cfg(feature = "alloc")] mod convex_hull; mod cuboid_ray_cast; -#[cfg(feature = "alloc")] mod cylinder_cuboid_contact; -#[cfg(feature = "alloc")] mod epa3; mod still_objects_toi; mod time_of_impact3; -#[cfg(feature = "alloc")] mod trimesh_connected_components; -#[cfg(feature = "alloc")] mod trimesh_intersection; -#[cfg(feature = "alloc")] mod trimesh_trimesh_toi; From 01f5c4b347c43ca060f72c85c28ea44e1771ddbd Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 14:51:22 +0200 Subject: [PATCH 06/12] Revert manual `robust` dep for now --- crates/parry2d-f64/Cargo.toml | 6 +----- crates/parry2d/Cargo.toml | 4 ---- crates/parry3d-f64/Cargo.toml | 6 +----- crates/parry3d/Cargo.toml | 6 +----- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/crates/parry2d-f64/Cargo.toml b/crates/parry2d-f64/Cargo.toml index 184eade7..cd8e13c6 100644 --- a/crates/parry2d-f64/Cargo.toml +++ b/crates/parry2d-f64/Cargo.toml @@ -82,11 +82,7 @@ hashbrown = { version = "0.15", optional = true, default-features = false, featu "default-hasher", ] } cust_core = { version = "0.1", optional = true } -spade = { version = "2", optional = true, default-features = false } # Make this optional? -robust = { version = "1.1", optional = true, default-features = false, features = [ - # Force `no_std` for `robust`, which is used by `spade`. - "no_std", -] } +spade = { version = "2", optional = true, default-features = false } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } log = "0.4" diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index 346422ee..c60d483e 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -83,10 +83,6 @@ hashbrown = { version = "0.15", optional = true, default-features = false, featu ] } cust_core = { version = "0.1", optional = true } spade = { version = "2", optional = true, default-features = false } -robust = { version = "1.1", optional = true, default-features = false, features = [ - # Force `no_std` for `robust`, which is used by `spade`. - "no_std", -] } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } ordered-float = { version = "5", default-features = false } diff --git a/crates/parry3d-f64/Cargo.toml b/crates/parry3d-f64/Cargo.toml index 4dccca10..742877e0 100644 --- a/crates/parry3d-f64/Cargo.toml +++ b/crates/parry3d-f64/Cargo.toml @@ -83,11 +83,7 @@ hashbrown = { version = "0.15", optional = true, default-features = false, featu ] } foldhash = { version = "0.1", optional = true, default-features = false } cust_core = { version = "0.1", optional = true } -spade = { version = "2.9", optional = true, default-features = false } # Make this optional? -robust = { version = "1.1", optional = true, default-features = false, features = [ - # Force `no_std` for `robust`, which is used by `spade`. - "no_std", -] } +spade = { version = "2.9", optional = true, default-features = false } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } rstar = "0.12.0" diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index 09c91388..73ecbbb2 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -83,11 +83,7 @@ hashbrown = { version = "0.15", optional = true, default-features = false, featu "default-hasher", ] } cust_core = { version = "0.1", optional = true } -spade = { version = "2.9", optional = true, default-features = false } # Make this optional? -robust = { version = "1.1", optional = true, default-features = false, features = [ - # Force `no_std` for `robust`, which is used by `spade`. - "no_std", -] } +spade = { version = "2.9", optional = true, default-features = false } rayon = { version = "1", optional = true } bytemuck = { version = "1", features = ["derive"], optional = true } log = "0.4" From c49036214529211721b56ae202ad751515182ee3 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 15:04:57 +0200 Subject: [PATCH 07/12] Format --- src/query/contact/contact.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/contact/contact.rs b/src/query/contact/contact.rs index 96426efe..15b8abdb 100644 --- a/src/query/contact/contact.rs +++ b/src/query/contact/contact.rs @@ -1,6 +1,6 @@ use crate::math::{Isometry, Point, Real, Vector}; -use na::{self, Unit}; use core::mem; +use na::{self, Unit}; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; From e86bd6093a9e8f7229ba49737e85f572e75d1f46 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 15:05:31 +0200 Subject: [PATCH 08/12] Enable `hashbrown/serde` for `serde-serialize` --- crates/parry2d-f64/Cargo.toml | 1 + crates/parry2d/Cargo.toml | 1 + crates/parry3d-f64/Cargo.toml | 1 + crates/parry3d/Cargo.toml | 1 + 4 files changed, 4 insertions(+) diff --git a/crates/parry2d-f64/Cargo.toml b/crates/parry2d-f64/Cargo.toml index cd8e13c6..0e6f7c56 100644 --- a/crates/parry2d-f64/Cargo.toml +++ b/crates/parry2d-f64/Cargo.toml @@ -39,6 +39,7 @@ serde-serialize = [ "nalgebra/serde-serialize", "arrayvec/serde", "bitflags/serde", + "hashbrown?/serde", "spade?/serde", ] rkyv-serialize = [ diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index c60d483e..acb5284b 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -39,6 +39,7 @@ serde-serialize = [ "nalgebra/serde-serialize", "arrayvec/serde", "bitflags/serde", + "hashbrown?/serde", "spade?/serde", ] rkyv-serialize = [ diff --git a/crates/parry3d-f64/Cargo.toml b/crates/parry3d-f64/Cargo.toml index 742877e0..096caf46 100644 --- a/crates/parry3d-f64/Cargo.toml +++ b/crates/parry3d-f64/Cargo.toml @@ -37,6 +37,7 @@ serde-serialize = [ "serde", "nalgebra/serde-serialize", "bitflags/serde", + "hashbrown?/serde", "spade?/serde", ] rkyv-serialize = [ diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index 73ecbbb2..81850cdc 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -37,6 +37,7 @@ serde-serialize = [ "serde", "nalgebra/serde-serialize", "bitflags/serde", + "hashbrown?/serde", "spade?/serde", ] rkyv-serialize = [ From 8d630ebe384bbfc256406024141d11f15fe69cda Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 15:06:52 +0200 Subject: [PATCH 09/12] Properly format :P --- src/query/gjk/cso_point.rs | 2 +- src/utils/sdp_matrix.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/query/gjk/cso_point.rs b/src/query/gjk/cso_point.rs index 3243012b..0bc51f7c 100644 --- a/src/query/gjk/cso_point.rs +++ b/src/query/gjk/cso_point.rs @@ -1,7 +1,7 @@ use crate::math::{Isometry, Point, Real, Vector}; use crate::shape::SupportMap; -use na::Unit; use core::ops::Sub; +use na::Unit; /// A point of a Configuration-Space Obstacle. /// diff --git a/src/utils/sdp_matrix.rs b/src/utils/sdp_matrix.rs index 9782bee9..2dbe68e6 100644 --- a/src/utils/sdp_matrix.rs +++ b/src/utils/sdp_matrix.rs @@ -1,6 +1,6 @@ use crate::math::Real; -use na::{Matrix2, Matrix3, Matrix3x2, SimdRealField, Vector2, Vector3}; use core::ops::{Add, Mul}; +use na::{Matrix2, Matrix3, Matrix3x2, SimdRealField, Vector2, Vector3}; #[cfg(feature = "rkyv")] #[cfg(feature = "rkyv")] From 4f8aff0e6f171e6f9544dc76f7e8f821edac3c63 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 23 Mar 2025 15:11:58 +0200 Subject: [PATCH 10/12] Fix `wavefront` --- src/transformation/wavefront.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/transformation/wavefront.rs b/src/transformation/wavefront.rs index 257e81fb..0f63731f 100644 --- a/src/transformation/wavefront.rs +++ b/src/transformation/wavefront.rs @@ -1,4 +1,5 @@ use crate::shape::TriMesh; +use alloc::{string::ToString, vec}; use obj::{Group, IndexTuple, ObjData, ObjError, Object, SimplePolygon}; use std::path::PathBuf; From 2ce072abfcac0f5e9fd84efd574a413984eb911b Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Mon, 24 Mar 2025 11:22:55 +0200 Subject: [PATCH 11/12] Remove unnecessary dev-dependency on self --- crates/parry2d-f64/Cargo.toml | 1 - crates/parry2d/Cargo.toml | 1 - crates/parry3d-f64/Cargo.toml | 1 - crates/parry3d/Cargo.toml | 1 - 4 files changed, 4 deletions(-) diff --git a/crates/parry2d-f64/Cargo.toml b/crates/parry2d-f64/Cargo.toml index 0e6f7c56..8eab45cd 100644 --- a/crates/parry2d-f64/Cargo.toml +++ b/crates/parry2d-f64/Cargo.toml @@ -92,7 +92,6 @@ thiserror = { version = "2", default-features = false } ena = { version = "0.14.3", optional = true, default-features = false } [dev-dependencies] -parry2d-f64 = { path = ".", features = ["std"] } simba = { version = "0.9", default-features = false } oorandom = "11" ptree = "0.4.0" diff --git a/crates/parry2d/Cargo.toml b/crates/parry2d/Cargo.toml index acb5284b..6dca90cd 100644 --- a/crates/parry2d/Cargo.toml +++ b/crates/parry2d/Cargo.toml @@ -92,7 +92,6 @@ thiserror = { version = "2", default-features = false } ena = { version = "0.14.3", optional = true, default-features = false } [dev-dependencies] -parry2d = { path = ".", features = ["std"] } simba = { version = "0.9", default-features = false } oorandom = "11" ptree = "0.4.0" diff --git a/crates/parry3d-f64/Cargo.toml b/crates/parry3d-f64/Cargo.toml index 096caf46..52aa97d5 100644 --- a/crates/parry3d-f64/Cargo.toml +++ b/crates/parry3d-f64/Cargo.toml @@ -96,7 +96,6 @@ ordered-float = { version = "5", default-features = false } thiserror = { version = "2", default-features = false } [dev-dependencies] -parry3d-f64 = { path = ".", features = ["std"] } oorandom = "11" ptree = "0.4.0" rand = { version = "0.8" } diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index 81850cdc..586ea1e4 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -95,7 +95,6 @@ obj = { version = "0.10.2", optional = true } ena = { version = "0.14.3", optional = true, default-features = false } [dev-dependencies] -parry3d = { path = ".", features = ["std"] } oorandom = "11" ptree = "0.4.0" rand = { version = "0.8" } From ccd3a36f8dbc4a2970e15dad33e6ceb4fb9c50ac Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Mon, 24 Mar 2025 11:46:56 +0200 Subject: [PATCH 12/12] Update CHANGELOG.md --- CHANGELOG.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447f0fd3..5a36a02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,18 @@ ### Added -- derive `Copy` for `VHACDParameters`. +- Derive `Copy` for `VHACDParameters`. +- Add `spade` default feature for algorithms using Delaunay triangulation from `spade`. + +### Modified + +- Improve `no_std` compatibility. + - Everything is now compatible, except `mesh_intersections`, `split_trimesh`, + convex hull validation, and computation of connected components for `TriMesh`. + - Add the `alloc_instead_of_core`, `std_instead_of_alloc`, and `std_instead_of_core` Clippy lints to the workspace. + - Use `core` and `alloc` directly rather than using an `std` alias. + - Use `hashbrown` instead of `rustc-hash` when `enhanced-determinism` is not enabled. + - Make `spade` optional. ## v0.18.0 @@ -158,7 +169,7 @@ This version modifies many names related to shape-casting: now prefixed with `cast_shapes_` (e.g. `cast_shapes_ball_ball`). - Rename `QueryDispatcher::time_of_impact` to `QueryDispatcher::cast_shapes`. - The (linear) shape-casting functions like `query::cast_shapes` (previously named - `query::time_of_impact) now take a `ShapeCastOptions` instead of the `max_toi` and + `query::time_of_impact`) now take a `ShapeCastOptions` instead of the `max_toi` and `stop_at_penetration` arguments. - Rename `query::nonlinear_time_of_impact` to `query::cast_shapes_nonlinear`. - Rename `QueryDispatcher::nonlinear_time_of_impact` to `QueryDispatcher::cast_shapes_nonlinear`.