Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some parts of lib in no_std with alloc. Tests pass #170

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/parry2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ maintenance = { status = "actively-developed" }
[features]
default = [ "required-features", "std" ]
required-features = [ "dim2", "f32" ]
std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade" ]
alloc = [ "hashbrown", "num-traits/libm", "nalgebra/alloc", "spade/alloc" ]
std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade/std" ]
dim2 = [ ]
f32 = [ ]
serde-serialize = [ "serde", "nalgebra/serde-serialize", "arrayvec/serde" ]
Expand Down Expand Up @@ -57,9 +58,10 @@ num-derive = "0.4"
indexmap = { version = "1", features = [ "serde-1" ], optional = true }
rustc-hash = { version = "1", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true }
spade = { git = "https://github.com/hatmajster/spade.git", branch = "no_std", default-features = false, optional = true }
rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = [ "derive" ], optional = true }
hashbrown = { version = "0.14.2", optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }
Expand Down
6 changes: 4 additions & 2 deletions crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ maintenance = { status = "actively-developed" }
[features]
default = [ "required-features", "std" ]
required-features = [ "dim3", "f32" ]
std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade" ]
alloc = [ "hashbrown", "num-traits/libm", "nalgebra/alloc", "spade/alloc"]
std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade/std" ]
dim3 = [ ]
f32 = [ ]
serde-serialize = [ "serde", "nalgebra/serde-serialize" ]
Expand Down Expand Up @@ -58,9 +59,10 @@ num-derive = "0.4"
indexmap = { version = "1", features = [ "serde-1" ], optional = true }
rustc-hash = { version = "1", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
spade = { git = "https://github.com/hatmajster/spade.git", branch = "no_std", default-features = false, optional = true }
rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = [ "derive" ], optional = true }
hashbrown = { version = "0.14.2", optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }
Expand Down
12 changes: 6 additions & 6 deletions src/bounding_volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub mod bounding_volume;
pub mod aabb;
mod aabb_ball;
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod aabb_convex_polygon;
#[cfg(feature = "dim3")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod aabb_convex_polyhedron;
mod aabb_cuboid;
mod aabb_halfspace;
Expand All @@ -36,21 +36,21 @@ mod bounding_sphere_capsule;
#[cfg(feature = "dim3")]
mod bounding_sphere_cone;
#[cfg(feature = "dim3")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod bounding_sphere_convex;
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod bounding_sphere_convex_polygon;
mod bounding_sphere_cuboid;
#[cfg(feature = "dim3")]
mod bounding_sphere_cylinder;
mod bounding_sphere_halfspace;
mod bounding_sphere_heightfield;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod bounding_sphere_polyline;
mod bounding_sphere_segment;
mod bounding_sphere_triangle;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod bounding_sphere_trimesh;
mod bounding_sphere_utils;
mod simd_aabb;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub mod mass_properties;
pub mod partitioning;
pub mod query;
pub mod shape;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
pub mod transformation;
pub mod utils;

Expand Down
7 changes: 5 additions & 2 deletions src/mass_properties/mass_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use {na::Matrix3, std::ops::MulAssign};
#[cfg(feature = "rkyv")]
use rkyv::{bytecheck, CheckBytes};

#[cfg(feature = "alloc")]
use alloc::vec::Vec;

const EPSILON: Real = f32::EPSILON as Real;

#[derive(Copy, Clone, Debug, Default, PartialEq)]
Expand Down Expand Up @@ -378,8 +381,8 @@ impl AddAssign<MassProperties> for MassProperties {
}
}

#[cfg(feature = "std")]
impl std::iter::Sum<MassProperties> for MassProperties {
#[cfg(any(feature = "std", feature = "alloc"))]
impl core::iter::Sum<MassProperties> for MassProperties {
#[cfg(feature = "dim2")]
fn sum<I>(iter: I) -> Self
where
Expand Down
4 changes: 4 additions & 0 deletions src/mass_properties/mass_properties_trimesh3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ impl MassProperties {
itot += ipart * vol;
}

#[cfg(feature = "std")]
let sign = volume.signum();
#[cfg(not(feature = "std"))]
let sign = if volume >= 0.0f32 { 1.0f32 } else { -1.0f32 };
Self::with_inertia_matrix(com, volume * density * sign, itot * density * sign)
}
}
Expand Down Expand Up @@ -208,6 +211,7 @@ mod test {

use crate::shape::Shape;
let orig_mprops = cuboid.mass_properties(1.0);
#[cfg(feature = "std")]
dbg!(orig_mprops.principal_inertia());

let mut trimesh = cuboid.to_trimesh();
Expand Down
16 changes: 8 additions & 8 deletions src/mass_properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ pub use self::mass_properties::MassProperties;
mod mass_properties;
mod mass_properties_ball;
mod mass_properties_capsule;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod mass_properties_compound;
#[cfg(feature = "dim3")]
mod mass_properties_cone;
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod mass_properties_convex_polygon;
#[cfg(feature = "dim3")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod mass_properties_convex_polyhedron;
mod mass_properties_cuboid;
mod mass_properties_cylinder;
#[cfg(feature = "dim2")]
mod mass_properties_triangle;
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod mass_properties_trimesh2d;
#[cfg(feature = "dim3")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod mass_properties_trimesh3d;

/// Free functions for some special-cases of mass-properties computation.
pub mod details {
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
pub use super::mass_properties_convex_polygon::convex_polygon_area_and_center_of_mass;
#[cfg(feature = "dim2")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
pub use super::mass_properties_trimesh2d::trimesh_area_and_center_of_mass;
#[cfg(feature = "dim3")]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
pub use super::mass_properties_trimesh3d::{
tetrahedron_unit_inertia_tensor_wrt_point, trimesh_signed_volume_and_center_of_mass,
};
Expand Down
6 changes: 6 additions & 0 deletions src/partitioning/qbvh/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use crate::query::SplitResult;
use crate::simd::SimdReal;
use simba::simd::SimdValue;

#[cfg(feature = "alloc")]
use alloc::{vec, vec::Vec};

#[cfg(not(feature = "std"))]
use na::ComplexField; // for .abs()

use super::utils::split_indices_wrt_dim;
use super::{IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhNodeFlags, QbvhProxy};

Expand Down
6 changes: 3 additions & 3 deletions src/partitioning/qbvh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ mod qbvh;
mod storage;
pub(self) mod utils;

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod build;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod traversal;
#[cfg(not(feature = "std"))]
#[cfg(not(any(feature = "std", feature = "alloc")))]
mod traversal_no_std;
#[cfg(feature = "std")]
mod update;
6 changes: 5 additions & 1 deletion src/partitioning/qbvh/qbvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use bitflags::bitflags;

use na::SimdValue;

#[cfg(feature = "alloc")]
use alloc::vec::Vec;


#[cfg(feature = "rkyv")]
use rkyv::{bytecheck, CheckBytes};
#[cfg(all(feature = "std", feature = "cuda"))]
Expand Down Expand Up @@ -307,7 +311,7 @@ impl<LeafData: DeviceCopy> CudaQbvh<LeafData> {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
impl<LeafData: IndexedData> Qbvh<LeafData> {
/// Initialize an empty Qbvh.
pub fn new() -> Self {
Expand Down
4 changes: 3 additions & 1 deletion src/partitioning/qbvh/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::utils::{Array1, DefaultStorage};
use crate::utils::CudaArray1;
#[cfg(feature = "cuda")]
use crate::utils::{CudaArrayPointer1, CudaStorage, CudaStoragePtr};
#[cfg(feature = "alloc")]
use alloc::vec::Vec;

/// Trait describing all the types needed for storing a Qbvh’s data.
pub trait QbvhStorage<LeafData> {
Expand All @@ -16,7 +18,7 @@ pub trait QbvhStorage<LeafData> {
type ArrayProxies: Array1<QbvhProxy<LeafData>>;
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
impl<LeafData> QbvhStorage<LeafData> for DefaultStorage {
type Nodes = Vec<QbvhNode>;
type ArrayU32 = Vec<u32>;
Expand Down
7 changes: 6 additions & 1 deletion src/partitioning/qbvh/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::utils::Array1;
use crate::utils::WeightedValue;
use num::Bounded;
use simba::simd::SimdBool;
use std::collections::BinaryHeap;
#[cfg(feature = "parallel")]
use {
crate::partitioning::{ParallelSimdSimultaneousVisitor, ParallelSimdVisitor},
Expand All @@ -19,6 +18,12 @@ use {
std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering},
};

#[cfg(feature = "std")]
use std::collections::BinaryHeap;

#[cfg(feature = "alloc")]
use alloc::{vec, vec::Vec, collections::BinaryHeap};

use super::{IndexedData, NodeIndex, Qbvh};

impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData, Storage> {
Expand Down
3 changes: 3 additions & 0 deletions src/query/clip/clip_aabb_polygon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::bounding_volume::Aabb;
use crate::math::{Point, Real, Vector};

#[cfg(feature = "alloc")]
use alloc::vec::Vec;

impl Aabb {
/// Computes the intersections between this Aabb and the given polygon.
///
Expand Down
3 changes: 3 additions & 0 deletions src/query/clip/clip_halfspace_polygon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::math::{Point, Real, Vector};
use crate::query::{self, Ray};

#[cfg(feature = "alloc")]
use alloc::vec::Vec;

/// Cuts a polygon with the given half-space.
///
/// Given the half-space `center` and outward `normal`,
Expand Down
6 changes: 3 additions & 3 deletions src/query/clip/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pub use self::clip_aabb_line::clip_aabb_line;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
pub use self::clip_halfspace_polygon::clip_halfspace_polygon;
pub use self::clip_segment_segment::clip_segment_segment;
#[cfg(feature = "dim2")]
pub use self::clip_segment_segment::clip_segment_segment_with_normal;

mod clip_aabb_line;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod clip_aabb_polygon;
#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "alloc"))]
mod clip_halfspace_polygon;
mod clip_segment_segment;
4 changes: 2 additions & 2 deletions src/query/contact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::contact_halfspace_support_map::{
contact_halfspace_support_map, contact_support_map_halfspace,
};
pub use self::contact_shape_shape::contact;
#[cfg(feature = "std")] // TODO: doesn’t work without std because of EPA
#[cfg(any(feature = "std", feature = "alloc"))]
pub use self::contact_support_map_support_map::{
contact_support_map_support_map, contact_support_map_support_map_with_params,
};
Expand All @@ -27,5 +27,5 @@ mod contact_composite_shape_shape;
mod contact_cuboid_cuboid;
mod contact_halfspace_support_map;
mod contact_shape_shape;
#[cfg(feature = "std")] // TODO: doesn’t work without std because of EPA
#[cfg(any(feature = "std", feature = "alloc"))]
mod contact_support_map_support_map;
3 changes: 3 additions & 0 deletions src/query/contact_manifolds/contact_manifold.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::math::{Isometry, Point, Real, Vector};
use crate::shape::PackedFeatureId;

#[cfg(feature = "alloc")]
use alloc::{vec::Vec};

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use crate::shape::SimdCompositeShape;
use crate::utils::hashmap::{Entry, HashMap};
use crate::utils::IsometryOpt;

#[cfg(feature = "alloc")]
use alloc::{boxed::Box, vec::Vec};

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
Expand Down Expand Up @@ -128,7 +131,7 @@ pub fn contact_manifolds_composite_shape_composite_shape<'a, ManifoldData, Conta
timestamp: new_timestamp,
};

let mut manifold = ContactManifold::new();
let mut manifold: ContactManifold<ManifoldData, ContactData> = ContactManifold::<ManifoldData, ContactData>::new();

if flipped {
manifold.subshape1 = *leaf2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use crate::shape::{Shape, SimdCompositeShape};
use crate::utils::hashmap::{Entry, HashMap};
use crate::utils::IsometryOpt;

#[cfg(feature = "alloc")]
use alloc::{boxed::Box, vec::Vec};

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
Expand Down Expand Up @@ -103,7 +106,7 @@ pub fn contact_manifolds_composite_shape_shape<ManifoldData, ContactData>(
timestamp: new_timestamp,
};

let mut manifold = ContactManifold::new();
let mut manifold: ContactManifold<ManifoldData, ContactData> = ContactManifold::new();

if flipped {
manifold.subshape1 = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn contact_manifold_cuboid_cuboid<'a, ManifoldData, ContactData: Default + C
let feature1 = cuboid1.support_feature(best_sep.1);
let feature2 = cuboid2.support_feature(local_n2);

PolygonalFeature::contacts(
PolygonalFeature::contacts::<ManifoldData, ContactData>(
pos12,
pos21,
&best_sep.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn contact_manifold_cuboid_triangle<'a, ManifoldData, ContactData>(
let old_manifold_points = manifold.points.clone();
manifold.clear();

PolygonalFeature::contacts(
PolygonalFeature::contacts::<ManifoldData, ContactData>(
pos12,
pos21,
&best_sep.1,
Expand Down
Loading