Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into example_aabb
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Sep 20, 2024
2 parents d9d5865 + c385c9b commit f956053
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 91 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/parry-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: parry CI build

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
CARGO_TERM_COLOR: always
Expand All @@ -18,6 +18,8 @@ jobs:
run: cargo fmt -- --check
clippy:
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- name: Clippy
Expand All @@ -40,7 +42,7 @@ jobs:
- name: Check serialization
run: cargo check --features bytemuck-serialize,serde-serialize,rkyv-serialize;
- name: Run tests
run: cargo test
run: cargo test --features wavefront
build-wasm:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -74,6 +76,16 @@ jobs:
- name: install stable Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
toolchain: stable
- name: cargo doc
run: cargo doc --workspace --features bytemuck-serialize,serde-serialize,rkyv-serialize,parallel --no-deps --document-private-items
check-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: check benchmarks
run: cargo +nightly check --benches
4 changes: 4 additions & 0 deletions crates/parry2d/examples/common_macroquad2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use nalgebra::Point2;
use parry2d::math::Real;
use parry2d::shape::TriMesh;

/// As this file is used as a module from other examples,
/// rustc warns about dead code:
/// - `main()` is needed for this file to be included in examples
/// - For other functions, they may be "dead code" for an example, but not for others.
#[allow(dead_code)]
fn main() {
println!(
Expand Down
5 changes: 5 additions & 0 deletions crates/parry3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
parallel = ["rayon"]
# Adds `TriMesh:to_obj_file` function.
wavefront = ["obj"]
alloc = []
improved_fixed_point_support = []
Expand Down Expand Up @@ -88,3 +89,7 @@ thiserror = { version = "1", optional = true }
oorandom = "11"
ptree = "0.4.0"
rand = { version = "0.8" }

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
features = ["wavefront"]
4 changes: 4 additions & 0 deletions crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
parallel = ["rayon"]
# Adds `TriMesh:to_obj_file` function.
wavefront = ["obj"]
alloc = []
improved_fixed_point_support = []
Expand Down Expand Up @@ -89,10 +90,13 @@ oorandom = "11"
ptree = "0.4.0"
rand = { version = "0.8" }
macroquad = "0.4.12"
nalgebra = { version = "0.33", default-features = false, features = ["rand"] }
rand_isaac = "0.3"

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
features = ["wavefront"]

# The following listing is to allow for examples to be scraped,
# see https://doc.rust-lang.org/rustdoc/scraped-examples.html#scraped-examples for details.
Expand Down
6 changes: 3 additions & 3 deletions crates/parry3d/benches/bounding_volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use na::Isometry3;
use parry3d::bounding_volume::BoundingVolume;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
Expand Down Expand Up @@ -135,13 +135,13 @@ bench_method!(
bench_method!(
bench_convex_aabb,
aabb: Aabb,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>
);
bench_method!(
bench_convex_bounding_sphere,
bounding_sphere: BoundingSphere,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>
);

Expand Down
23 changes: 13 additions & 10 deletions crates/parry3d/benches/common/default_gen.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use na::{
self, Isometry2, Isometry3, Matrix2, Matrix3, Matrix4, Point2, Point3, Point4, RealField,
Vector2, Vector3, Vector4,
self, Isometry2, Isometry3, Matrix2, Matrix3, Matrix4, Point2, Point3, Point4, Vector2,
Vector3, Vector4,
};
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::math::{Point, Real, Vector};
use parry3d::query::Ray;
use parry3d::shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle};
use parry3d::shape::{Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, Triangle};
use rand::distributions::{Distribution, Standard};
use rand::Rng;

Expand Down Expand Up @@ -76,7 +76,11 @@ where
Standard: Distribution<Real>,
{
fn generate<R: Rng>(rng: &mut R) -> Capsule {
Capsule::new(rng.gen::<Real>().abs(), rng.gen::<Real>().abs())
Capsule::new(
rng.gen::<Point<Real>>(),
rng.gen::<Point<Real>>(),
rng.gen::<Real>().abs(),
)
}
}

Expand Down Expand Up @@ -116,16 +120,15 @@ where
}
}

impl DefaultGen for ConvexHull
impl DefaultGen for ConvexPolyhedron
where
Standard: Distribution<Point<Real>>,
Standard: Distribution<Real>,
{
fn generate<R: Rng>(rng: &mut R) -> ConvexHull {
fn generate<R: Rng>(rng: &mut R) -> ConvexPolyhedron {
// It is recommended to have at most 100 points.
// Otherwise, a smarter structure like the DK hierarchy would be needed.
// let pts: Vec<_> = (0..100).map(|_| rng.gen()).collect();
// ConvexHull::try_from_points(&pts).unwrap()
unimplemented!()
let pts: Vec<_> = (0..100).map(|_| rng.gen()).collect();
ConvexPolyhedron::from_convex_hull(&pts).unwrap()
}
}

Expand Down
9 changes: 3 additions & 6 deletions crates/parry3d/benches/common/generators.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use na::{Point2, Point3};
use na::Point3;
use parry3d::shape::TriMesh;
use rand::Rng;

pub fn generate_trimesh_around_origin<R: Rng>(rng: &mut R) -> TriMesh {
let pts = (0..3000).map(|_| rng.gen::<Point3<f32>>() * 3.0).collect();
let uvs = (0..3000).map(|_| rng.gen::<Point2<f32>>() * 3.0).collect();
let indices = (0..1000)
.map(|i| Point3::new(i * 3, i * 3 + 1, i * 3 + 2))
.collect();
let indices = (0..1000).map(|i| [i * 3, i * 3 + 1, i * 3 + 2]).collect();

TriMesh::new(pts, indices, Some(uvs)).unwrap()
TriMesh::new(pts, indices).unwrap()
}
2 changes: 1 addition & 1 deletion crates/parry3d/benches/common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! bench_method_gen (

unsafe {
let val: $tres = test::black_box($arg.get_unchecked(i).$method($(unref($args.get_unchecked(i)),)*));
drop(val);
let _ = val;
}
})
}
Expand Down
15 changes: 10 additions & 5 deletions crates/parry3d/benches/query/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,49 @@ mod macros;
bench_free_fn!(
bench_ball_against_ball,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Ball,
pos2: Isometry3<f32>,
b2: Ball,
prediction: f32
);

bench_free_fn!(
bench_cuboid_against_cuboid,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cuboid,
pos2: Isometry3<f32>,
b2: Cuboid,
prediction: f32
);

bench_free_fn!(
bench_capsule_against_capsule,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Capsule,
pos2: Isometry3<f32>,
b2: Capsule,
prediction: f32
);

bench_free_fn!(
bench_cone_against_cone,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cone,
pos2: Isometry3<f32>,
b2: Cone,
prediction: f32
);

bench_free_fn!(
bench_cylinder_against_cylinder,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cylinder,
pos2: Isometry3<f32>,
b2: Cylinder,
prediction: f32
);
40 changes: 20 additions & 20 deletions crates/parry3d/benches/query/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use na::Isometry3;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::query::{Ray, RayCast};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
Expand Down Expand Up @@ -85,8 +85,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_ball_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_ball_with_normal,
cast_ray_and_get_normal,
b: Ball,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -95,8 +95,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cuboid_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cuboid_with_normal,
cast_ray_and_get_normal,
c: Cuboid,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -105,8 +105,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_capsule_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_capsule_with_normal,
cast_ray_and_get_normal,
c: Capsule,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -115,8 +115,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cone_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cone_with_normal,
cast_ray_and_get_normal,
c: Cone,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -125,8 +125,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cylinder_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cylinder_with_normal,
cast_ray_and_get_normal,
c: Cylinder,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -135,8 +135,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_segment_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_segment_with_normal,
cast_ray_and_get_normal,
c: Segment,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -145,8 +145,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_triangle_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_triangle_with_normal,
cast_ray_and_get_normal,
c: Triangle,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -155,18 +155,18 @@ bench_method!(
);

bench_method!(
bench_ray_against_convex_with_normal_uv,
cast_ray_and_get_normal_and_uv,
c: ConvexHull,
bench_ray_against_convex_with_normal,
cast_ray_and_get_normal,
c: ConvexPolyhedron,
pos: Isometry3<f32>,
ray: Ray,
max_time_of_impact: f32,
solid: bool
);

bench_method_gen!(
bench_ray_against_trimesh_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_trimesh_with_normal,
cast_ray_and_get_normal,
m: TriMesh = generate_trimesh_around_origin,
pos: Isometry3<f32> = generate,
ray: Ray = generate,
Expand Down
7 changes: 4 additions & 3 deletions crates/parry3d/benches/support_map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::{generate, unref};
use na::{Isometry3, Vector3};
use parry3d::shape::SupportMap;
use parry3d::shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle};
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;
Expand Down Expand Up @@ -59,10 +59,11 @@ bench_method!(
m: Isometry3<f32>,
dir: Vector3<f32>
);

bench_method!(
bench_convex_support_map,
support_point,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>,
dir: Vector3<f32>
);
1 change: 1 addition & 0 deletions src/mass_properties/mass_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use {na::Matrix3, std::ops::MulAssign};
#[cfg(feature = "rkyv")]
use rkyv::{bytecheck, CheckBytes};

#[cfg_attr(feature = "f32", expect(clippy::unnecessary_cast))]
const EPSILON: Real = f32::EPSILON as Real;

#[derive(Copy, Clone, Debug, Default, PartialEq)]
Expand Down
Loading

0 comments on commit f956053

Please sign in to comment.