### List All Examples in a Crate Source: https://github.com/dimforge/parry/blob/master/Claude.md Lists all available example files within a specified crate's examples directory. ```bash ls crates/parry3d/examples/ ``` -------------------------------- ### Run 3D Example Source: https://github.com/dimforge/parry/blob/master/Claude.md Executes a specific example located in the parry3d crate, such as 'getting_started'. ```bash cargo run -p parry3d --example getting_started ``` -------------------------------- ### Run 2D Example Source: https://github.com/dimforge/parry/blob/master/Claude.md Executes a specific example located in the parry2d crate, such as 'getting_started'. ```bash cargo run -p parry2d --example getting_started ``` -------------------------------- ### Ray casting usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Example demonstrating how to cast a ray against a ball shape. ```rust use parry3d::query::{Ray, RayCast}; use parry3d::shape::Ball; use parry3d::math::{Pose, Vector}; let ball = Ball::new(1.0); let pose = Pose::identity(); let ray = Ray { origin: Vector::new(0.0, 0.0, -5.0), dir: Vector::Z, // Pointing forward }; if let Some(intersection) = ball.cast_ray(&pose, &ray, f32::MAX, false) { println!("Hit at distance: {}", intersection.toi); println!("Normal: {:?}", intersection.normal); } ``` -------------------------------- ### Point Cloud Support Point Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/utilities.md Example demonstrating how to find the support point of a vector set in a specific direction using point_cloud_support_point. ```rust use parry3d::utils::point_cloud_support_point; use parry3d::math::Vector; let points = vec![ Vector::new(1.0, 0.0, 0.0), Vector::new(0.0, 1.0, 0.0), Vector::new(0.0, 0.0, 1.0), ]; let direction = Vector::new(1.0, 1.0, 1.0).normalize(); let support = point_cloud_support_point(&direction, &points); println!("Support point: {:?}", support); ``` -------------------------------- ### Create a Cone instance Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Example of creating a Cone with a specified half-height and radius. ```rust use parry3d::shape::Cone; // Create a cone with height 2.0 (±1.0 from center) and radius 0.5 let cone = Cone::new(1.0, 0.5); ``` -------------------------------- ### SymmetricEigen2 Import Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/utilities.md Example of importing the SymmetricEigen2 utility from the parry2d crate. ```rust use parry2d::utils::SymmetricEigen2; ``` -------------------------------- ### Capsule Initialization Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Shows how to create a Capsule using axis-aligned constructors or by providing an explicit Segment. ```rust use parry3d::shape::Capsule; use parry3d::math::Vector; use parry3d::shape::Segment; // Create a capsule aligned with X-axis // Height 2.0 (±1.0 from center), radius 0.5 let capsule = Capsule::new_x(1.0, 0.5); // Or from explicit segment let segment = Segment::new( Vector::new(-1.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), ); let capsule2 = Capsule::new(segment, 0.5); ``` -------------------------------- ### Segment Initialization Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Demonstrates how to create a new Segment instance using two Vector endpoints. ```rust use parry3d::shape::Segment; use parry3d::math::Vector; let segment = Segment::new( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 1.0, 0.0), ); ``` -------------------------------- ### VHACD Decomposition Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Demonstrates how to initialize VHACD parameters and decompose a simple mesh into convex pieces. ```rust use parry3d::transformation::vhacd::{VHACD, VHACDParameters}; use parry3d::math::Vector; let vertices = vec![ Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(0.0, 1.0, 0.0), Vector::new(0.5, 0.5, 1.0), ]; let indices = vec![0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4]; let mut params = VHACDParameters::default(); params.concavity = 0.01; params.resolution = 50; let convex_pieces = VHACD::decompose(&vertices, &indices, ¶ms); println!("Decomposed into {} convex pieces", convex_pieces.len()); ``` -------------------------------- ### Ball usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Demonstrates creating a Ball instance and using it for collision detection. ```rust use parry3d::shape::Ball; // Create a ball with radius 2.0 let ball = Ball::new(2.0); assert_eq!(ball.radius, 2.0); // Use in collision detection let other_ball = Ball::new(1.5); ``` -------------------------------- ### Creating Cuboid Instances Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Examples of how to instantiate a Cuboid using specific half-extents or as a unit cube. ```rust use parry3d::shape::Cuboid; use parry3d::math::Vector; // Create a cuboid with half-extents (1.0, 2.0, 0.5) // Full dimensions: 2.0 x 4.0 x 1.0 let cuboid = Cuboid::new(Vector::new(1.0, 2.0, 0.5)); // Create a unit cube (half-extents 0.5 in all dimensions) let cube = Cuboid::new(Vector::new(0.5, 0.5, 0.5)); ``` -------------------------------- ### 2D Convex Hull Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Example demonstrating the computation of a 2D convex hull and its indices using the parry2d crate. ```rust #[cfg(feature = "dim2")] use parry2d::transformation::convex_hull; #[cfg(feature = "dim2")] use parry2d::math::Vector; #[cfg(feature = "dim2")] { let points = vec![ Vector::new(0.0, 0.0), Vector::new(1.0, 0.0), Vector::new(0.5, 0.5), // Inside hull Vector::new(1.0, 1.0), Vector::new(0.0, 1.0), ]; let hull = convex_hull(&points); println!("Convex hull points: {:?}", hull); let indices = convex_hull_idx(&points); println!("Hull indices: {:?}", indices); } ``` -------------------------------- ### Pose usage in collision queries Source: https://github.com/dimforge/parry/blob/master/_autodocs/types.md Example demonstrating how to create poses and use them within a closest_points query. ```rust use parry3d::math::Pose; use parry3d::shape::Ball; use parry3d::query::closest_points; // Create poses let pose1 = Pose::translation(0.0, 0.0, 0.0); let pose2 = Pose::translation(5.0, 0.0, 0.0); // Use in queries let ball1 = Ball::new(1.0); let ball2 = Ball::new(1.0); let result = closest_points(&pose1, &ball1, &pose2, &ball2, f32::MAX).unwrap(); ``` -------------------------------- ### HalfSpace Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Creating HalfSpace instances for a floor and a wall using normal vectors. ```rust use parry3d::shape::HalfSpace; use parry3d::math::Vector; // Create a half-space with normal pointing up (Y-axis) let floor = HalfSpace::new(Vector::Y); // Create a wall with normal pointing right (X-axis) let wall = HalfSpace::new(Vector::X); ``` -------------------------------- ### Create a Cylinder instance Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Example of creating a Cylinder with a specified half-height and radius. ```rust use parry3d::shape::Cylinder; // Create a cylinder with height 2.0 (±1.0 from center) and radius 0.5 let cylinder = Cylinder::new(1.0, 0.5); ``` -------------------------------- ### Enable Serde serialization Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Example configuration to enable Serde support for serializing and deserializing shapes. ```toml [dependencies] parry3d = { version = "0.30", features = ["serde-serialize"] } ``` -------------------------------- ### BoundingSphere usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/bounding-volumes.md Demonstrates creating a BoundingSphere, testing point containment, checking intersection with another sphere, and enlarging the sphere. ```rust use parry3d::bounding_volume::BoundingSphere; use parry3d::math::Vector; // Create a bounding sphere let sphere = BoundingSphere::new(Vector::ZERO, 2.0); // Test point containment let point = Vector::new(1.0, 0.0, 0.0); assert!(sphere.contains_local_point(point)); // Test sphere intersection let other = BoundingSphere::new(Vector::new(2.5, 0.0, 0.0), 1.0); assert!(sphere.intersects(&other)); // Enlarge sphere let enlarged = sphere.loosen(0.5); assert_eq!(enlarged.radius, 2.5); ``` -------------------------------- ### MassProperties Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/mass-properties.md Demonstrates creating mass properties for a sphere and transforming them into world space. ```rust use parry3d::mass_properties::MassProperties; use parry3d::shape::Ball; use parry3d::math::Pose; // Create mass properties for a sphere let mass_props = MassProperties::with_mass(5.0); println!("Mass: {}", mass_props.mass()); println!("Center of mass: {:?}", mass_props.local_com); println!("Inertia: {:?}", mass_props.principal_inertia()); // Transform to world space let pose = Pose::translation(1.0, 2.0, 3.0); let transformed = mass_props.transform_by(&pose); println!("World COM: {:?}", transformed.local_com); ``` -------------------------------- ### 3D Convex Hull Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Example demonstrating 3D convex hull generation with error handling for coplanar point sets. ```rust use parry3d::transformation::convex_hull; use parry3d::math::Vector; let points = vec![ Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), Vector::new(0.5, 0.5, 0.0), // Coplanar, would cause error Vector::new(0.5, 0.5, 1.0), // Non-coplanar ]; match convex_hull(&points) { Ok(hull) => println!("Hull vertices: {:?}", hull), Err(e) => println!("Error: {:?}", e), } ``` -------------------------------- ### Contact detection example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Example usage of the contact function to detect overlapping balls and retrieve contact details. ```rust use parry3d::query::contact; use parry3d::shape::Ball; use parry3d::math::Pose; let ball1 = Ball::new(1.0); let ball2 = Ball::new(1.0); let pos1 = Pose::translation(0.0, 0.0, 0.0); let pos2 = Pose::translation(1.5, 0.0, 0.0); // Overlapping let contact_result = contact(&pos1, &ball1, &pos2, &ball2, 0.0).unwrap(); if let Some(contact) = contact_result { println!("Contact normal: {:?}", contact.normal1); println!("Penetration depth: {}", -contact.dist); // Negative when penetrating } ``` -------------------------------- ### Voxelize Triangle Mesh Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Demonstrates how to use voxelize_triangle_mesh to convert a set of vertices and indices into a VoxelSet. ```rust use parry3d::transformation::voxelization; use parry3d::math::Vector; let vertices = vec![ Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), Vector::new(0.5, 1.0, 0.0), Vector::new(0.5, 0.5, 1.0), ]; let indices = vec![0, 1, 2, 0, 1, 3]; let voxel_size = 0.1; let voxel_set = voxelization::voxelize_triangle_mesh( &vertices, &indices, voxel_size, ); println!("Voxel set created with voxel size {}", voxel_size); ``` -------------------------------- ### ConvexPolygon Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Creating a ConvexPolygon from a set of points using the from_convex_hull method. ```rust #[cfg(all(feature = "dim2", feature = "alloc"))] use parry2d::shape::ConvexPolygon; #[cfg(all(feature = "dim2", feature = "alloc"))] use parry2d::math::Vector; #[cfg(all(feature = "dim2", feature = "alloc"))] { // Create a triangle as a convex polygon let points = vec![ Vector::new(0.0, 0.0), Vector::new(1.0, 0.0), Vector::new(0.5, 1.0), ]; let polygon = ConvexPolygon::from_convex_hull(&points).unwrap(); } ``` -------------------------------- ### closest_points usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md An example demonstrating how to use the closest_points function with two Ball shapes and handle the resulting ClosestPoints enum. ```rust use parry3d::query::{closest_points, ClosestPoints}; use parry3d::shape::Ball; use parry3d::math::Pose; let ball1 = Ball::new(1.0); let ball2 = Ball::new(1.0); let pos1 = Pose::translation(0.0, 0.0, 0.0); let pos2 = Pose::translation(5.0, 0.0, 0.0); let result = closest_points(&pos1, &ball1, &pos2, &ball2, f32::MAX).unwrap(); match result { ClosestPoints::WithinMargin(pt1, pt2) => { let distance = (pt2 - pt1).length(); println!("Distance: {}", distance); } ClosestPoints::Intersecting => println!("Shapes overlap"), ClosestPoints::Disjoint => println!("Too far apart"), } ``` -------------------------------- ### Configure Parry for no_std and no heap allocation Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Example configuration for a no_std environment without heap allocation, limiting available shapes to primitives. ```toml [dependencies] parry3d = { version = "0.30", default-features = false, features = ["dim3", "f32"] } ``` -------------------------------- ### 2D Point-in-Polygon Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/utilities.md Example demonstrating the use of point_in_poly2d to check if a point is contained within a defined polygon. ```rust use parry2d::utils::point_in_poly2d; use parry2d::math::Vector; let polygon = vec![ Vector::new(0.0, 0.0), Vector::new(1.0, 0.0), Vector::new(1.0, 1.0), Vector::new(0.0, 1.0), ]; let point = Vector::new(0.5, 0.5); if point_in_poly2d(&point, &polygon) { println!("Point is inside polygon"); } ``` -------------------------------- ### Aabb usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/bounding-volumes.md Demonstrates creating an AABB, testing point containment, checking intersections, retrieving properties, and creating an AABB from a set of points. ```rust use parry3d::bounding_volume::Aabb; use parry3d::math::Vector; // Create an AABB let aabb = Aabb::new( Vector::new(-1.0, -1.0, -1.0), Vector::new(1.0, 1.0, 1.0), ); // Test containment let point = Vector::ZERO; assert!(aabb.contains_local_point(point)); // Test intersection let other = Aabb::new( Vector::new(0.5, 0.5, 0.5), Vector::new(2.0, 2.0, 2.0), ); assert!(aabb.intersects(&other)); // Get properties println!("Center: {:?}", aabb.center()); println!("Extents: {:?}", aabb.extents()); // Create from points let points = vec![ Vector::new(1.0, 2.0, 3.0), Vector::new(-1.0, 0.0, 1.0), ]; let aabb_from_pts = Aabb::from_points(points); ``` -------------------------------- ### FeatureId usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/types.md Demonstrates how to instantiate FeatureId variants and use helper methods to check the feature type and retrieve its index. ```rust use parry3d::shape::FeatureId; let vertex_feature = FeatureId::Vertex(0); let edge_feature = FeatureId::Edge(1); let face_feature = FeatureId::Face(2); if edge_feature.is_edge() { println!("Edge index: {}", edge_feature.index()); } ``` -------------------------------- ### Migrate nalgebra to glam types Source: https://github.com/dimforge/parry/blob/master/CHANGELOG.md Example showing the transition from nalgebra types to glam types in Parry 0.26.0, including changes to points, vectors, and isometry. ```rust // Before (nalgebra) use parry3d::na::{Point3, Vector3, Isometry3, Unit}; let point = Point3::new(1.0, 2.0, 3.0); let vector = Vector3::new(1.0, 0.0, 0.0); let normal = Unit::new_normalize(vector); let pos = Isometry3::translation(1.0, 2.0, 3.0); // After (glam) use parry3d::math::{Vector, Pose}; let point = Vector::new(1.0, 2.0, 3.0); // Points are now Vector let vector = Vector::X; let normal = vector.normalize(); // No Unit wrapper let pos = Pose::translation(1.0, 2.0, 3.0); ``` -------------------------------- ### Doc-Test Feature Gate Example Source: https://github.com/dimforge/parry/blob/master/Claude.md Demonstrates the correct way to use feature gates within doc-tests for Parry crates. It requires checking for both dimension and precision features to ensure compatibility across all variants. ```rust /// ```rust /// # #[cfg(all(feature = "dim3", feature = "f32"))] { /// use parry3d::shape::Ball; /// // ... example code ... /// # } /// ``` ``` -------------------------------- ### Mesh Intersection Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Demonstrates how to perform a mesh intersection with defined tolerances and handle the resulting mesh or potential errors. ```rust use parry3d::transformation::{intersect_meshes, MeshIntersectionTolerances}; use parry3d::shape::TriMesh; use parry3d::math::Pose; let mesh1 = TriMesh::new(vertices1, indices1); let mesh2 = TriMesh::new(vertices2, indices2); let tolerances = MeshIntersectionTolerances { voxel_size: 0.1, intersection_tolerance: 1e-5, }; match intersect_meshes(&mesh1, &Pose::identity(), &mesh2, &Pose::identity(), &tolerances) { Ok(result_mesh) => println!("Intersection mesh has {} vertices", result_mesh.vertices().len()), Err(e) => println!("Intersection failed: {:?}", e), } ``` -------------------------------- ### Vector Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/types.md Demonstrates basic usage of the Vector type, including instantiation, normalization, and calculating dot products, cross products, and distances. ```rust use parry3d::math::Vector; let v1 = Vector::new(1.0, 2.0, 3.0); let v2 = Vector::new(4.0, 5.0, 6.0); let length = v1.length(); let normalized = v1.normalize(); let dot_product = v1.dot(&v2); let cross_product = v1.cross(&v2); let distance = (v2 - v1).length(); ``` -------------------------------- ### Compute Bounding Volumes for a Ball Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/bounding-volumes.md Example demonstrating how to compute the AABB and bounding sphere for a Ball shape at a specific pose. ```rust use parry3d::shape::Ball; use parry3d::bounding_volume::{aabb_of_any_shape, bounding_sphere_of_any_shape}; use parry3d::math::Pose; let ball = Ball::new(2.0); let pose = Pose::translation(5.0, 0.0, 0.0); // Compute AABB let aabb = aabb_of_any_shape(&pose, &ball); println!("AABB: mins={:?}, maxs={:?}", aabb.mins, aabb.maxs); // Compute bounding sphere let bsphere = bounding_sphere_of_any_shape(&pose, &ball); println!("Bounding sphere: center={:?}, radius={}", bsphere.center, bsphere.radius); ``` -------------------------------- ### Configure Density Constants Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Defines the default density and provides examples of common material densities in kg/m³ for mass property calculations. ```rust // Default density (must be positive) const DEFAULT_DENSITY: Real = 1.0; // Compute mass for sphere with custom density let props = mass_properties_ball(radius, density); // Common densities (kg/m³) let water_density = 1000.0; let wood_density = 700.0; let aluminum_density = 2700.0; let steel_density = 7850.0; ``` -------------------------------- ### Integrate MassProperties into a RigidBody Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/mass-properties.md Example of using MassProperties within a custom RigidBody struct to handle force and torque calculations. ```rust use parry3d::mass_properties::MassProperties; use parry3d::shape::Ball; use parry3d::math::Pose; struct RigidBody { pose: Pose, velocity: Vector, angular_velocity: Vector, mass_properties: MassProperties, } impl RigidBody { fn new(shape: &dyn Shape, pose: Pose, density: Real) -> Self { let mass_props = MassProperties::with_mass(1.0); // Simplified RigidBody { pose, velocity: Vector::ZERO, angular_velocity: Vector::ZERO, mass_properties: mass_props, } } fn apply_force(&mut self, force: Vector, point: Vector) { // F = ma let accel = force * self.mass_properties.mass(); self.velocity += accel; // τ = Iω let inertia = self.mass_properties.principal_inertia(); // ... apply torque } } ``` -------------------------------- ### Create a Compound shape Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Example of initializing a Compound shape containing a cuboid and two balls, requiring the 'alloc' feature. ```rust #[cfg(feature = "alloc")] use parry3d::shape::{Compound, Ball, Cuboid}; #[cfg(feature = "alloc")] use parry3d::math::{Pose, Vector}; #[cfg(feature = "alloc")] { // Create a compound shape with a cuboid and two balls let shapes = vec![ (Pose::identity(), ShapeRef::Cuboid(Cuboid::new(Vector::new(1.0, 0.5, 0.5)))), (Pose::translation(0.0, 1.0, 0.0), ShapeRef::Ball(Ball::new(0.5))), (Pose::translation(0.0, -1.0, 0.0), ShapeRef::Ball(Ball::new(0.5))), ]; let compound = Compound::new(shapes); } ``` -------------------------------- ### BoundingVolume Trait Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/bounding-volumes.md Demonstrates using the BoundingVolume trait methods to find the center of an Aabb and merge two Aabb instances. ```rust use parry3d::bounding_volume::{BoundingVolume, Aabb, BoundingSphere}; use parry3d::math::Vector; let aabb = Aabb::new(Vector::new(-1.0, -1.0, -1.0), Vector::new(1.0, 1.0, 1.0)); let sphere = BoundingSphere::new(Vector::ZERO, 1.5); // Use through trait let center = aabb.center(); println!("AABB center: {:?}", center); // Merge AABBs let other_aabb = Aabb::new(Vector::new(0.5, 0.5, 0.5), Vector::new(2.0, 2.0, 2.0)); let merged = aabb.merged(&other_aabb); println!("Merged AABB: {:?}", merged); ``` -------------------------------- ### intersection_test usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Example demonstrating how to use intersection_test to check if two balls overlap. ```rust use parry3d::query::intersection_test; use parry3d::shape::Ball; use parry3d::math::Pose; let ball1 = Ball::new(1.0); let ball2 = Ball::new(1.0); let pos1 = Pose::translation(0.0, 0.0, 0.0); let pos2 = Pose::translation(5.0, 0.0, 0.0); let is_intersecting = intersection_test(&pos1, &ball1, &pos2, &ball2).unwrap(); println!("Intersecting: {}", is_intersecting); ``` -------------------------------- ### Distance calculation example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Example usage of the distance function to compute the distance between a ball and a cuboid. ```rust use parry3d::query::distance; use parry3d::shape::{Ball, Cuboid}; use parry3d::math::{Pose, Vector}; let ball = Ball::new(1.0); let cuboid = Cuboid::new(Vector::new(1.0, 1.0, 1.0)); let pos1 = Pose::translation(0.0, 0.0, 0.0); let pos2 = Pose::translation(5.0, 0.0, 0.0); let dist = distance(&pos1, &ball, &pos2, &cuboid).unwrap(); println!("Distance: {}", dist); ``` -------------------------------- ### Build with SIMD Optimizations Source: https://github.com/dimforge/parry/blob/master/Claude.md Builds a crate with SIMD optimizations enabled. Ensure you are in the crate's directory. ```bash cd crates/parry3d && cargo build --features simd-stable ``` -------------------------------- ### Hertel-Mehlhorn Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Example demonstrating the simplification of a 2D polygon using the hertel_mehlhorn function. ```rust #[cfg(feature = "dim2")] use parry2d::transformation::hertel_mehlhorn; #[cfg(feature = "dim2")] use parry2d::math::Vector; #[cfg(feature = "dim2")] { let polygon = vec![ Vector::new(0.0, 0.0), Vector::new(1.0, 0.0), Vector::new(1.5, 0.5), // Could be removed Vector::new(2.0, 0.0), Vector::new(2.0, 2.0), Vector::new(0.0, 2.0), ]; let simplified = hertel_mehlhorn(&polygon); println!("Simplified from {} to {} vertices", polygon.len(), simplified.len()); } ``` -------------------------------- ### Build Documentation Source: https://github.com/dimforge/parry/blob/master/Claude.md Generates documentation for the entire workspace, excluding dependencies. RUSTDOCFLAGS="-D warnings" treats warnings as errors. ```bash RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps ``` -------------------------------- ### Build Documentation with Private Items Source: https://github.com/dimforge/parry/blob/master/Claude.md Generates documentation for all workspace crates, including private items and dependencies. ```bash cargo doc --workspace --no-deps --document-private-items ``` -------------------------------- ### Build Workspace Documentation Source: https://github.com/dimforge/parry/blob/master/Claude.md Generates documentation for all crates in the workspace, excluding dependencies. ```bash cargo doc --workspace --no-deps ``` -------------------------------- ### Create a RoundCuboid Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Example of creating a rounded cuboid by wrapping a standard Cuboid with a specified radius. ```rust use parry3d::shape::{RoundCuboid, Cuboid}; use parry3d::math::Vector; // Create a cuboid and add a 0.1 unit radius of rounding let cuboid = Cuboid::new(Vector::new(1.0, 2.0, 0.5)); let rounded = RoundCuboid::new(cuboid, 0.1); ``` -------------------------------- ### Example usage of cast_shapes_nonlinear Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Demonstrates how to set up two balls with NonlinearRigidMotion and perform a collision check. ```rust use parry3d::query::{cast_shapes_nonlinear, NonlinearRigidMotion}; use parry3d::shape::Ball; use parry3d::math::{Pose, Vector}; let ball1 = Ball::new(1.0); let ball2 = Ball::new(1.0); let motion1 = NonlinearRigidMotion { position: Pose::translation(0.0, 0.0, 0.0), linvel: Vector::new(5.0, 0.0, 0.0), angvel: Vector::new(0.0, 2.0, 0.0), // Rotating around Y-axis }; let motion2 = NonlinearRigidMotion { position: Pose::translation(10.0, 0.0, 0.0), linvel: Vector::ZERO, angvel: Vector::ZERO, }; if let Ok(Some(hit)) = cast_shapes_nonlinear(&ball1, &motion1, &ball2, &motion2, 1.0) { println!("Collision at t={}", hit.time_of_impact); } ``` -------------------------------- ### Build with Serialization Features Source: https://github.com/dimforge/parry/blob/master/Claude.md Builds all workspace crates with support for bytemuck, serde, and rkyv serialization. ```bash cargo build --features bytemuck-serialize,serde-serialize,rkyv ``` -------------------------------- ### WebAssembly Compact Configuration Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Configuration for compact WebAssembly builds, including Cargo.toml optimizations for binary size. ```toml [dependencies] parry2d = { version = "0.30", features = ["serde-serialize"] } ``` ```toml [profile.release] opt-level = "z" # Optimize for size lto = true # Link-time optimization codegen-units = 1 # Better optimization ``` -------------------------------- ### cast_shapes usage example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Demonstrates how to perform continuous collision detection between two balls moving relative to each other. ```rust use parry3d::query::{cast_shapes, ShapeCastOptions}; use parry3d::shape::Ball; use parry3d::math::{Pose, Vector}; let ball1 = Ball::new(1.0); let ball2 = Ball::new(1.0); let pos1 = Pose::translation(0.0, 0.0, 0.0); let vel1 = Vector::X * 5.0; // Moving right at 5 units/frame let pos2 = Pose::translation(10.0, 0.0, 0.0); let vel2 = Vector::ZERO; // Stationary let options = ShapeCastOptions { max_toi: 1.0 }; if let Ok(Some(hit)) = cast_shapes(&pos1, &vel1, &ball1, &pos2, &vel2, &ball2, &options) { println!("Collision at t={}", hit.time_of_impact); println!("Contact point: {:?}", hit.witness1); } ``` -------------------------------- ### Create a new Triangle instance Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Demonstrates how to instantiate a new Triangle using three Vector coordinates. ```rust use parry3d::shape::Triangle; use parry3d::math::Vector; let triangle = Triangle::new( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), Vector::new(0.0, 1.0, 0.0), ); ``` -------------------------------- ### TypedShape Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/types.md Demonstrates storing different shape types in a vector and accessing them via the Shape trait. ```rust use parry3d::shape::{TypedShape, Ball, Cuboid}; use parry3d::math::Vector; let shapes: Vec = vec![ TypedShape::Ball(Ball::new(1.0)), TypedShape::Cuboid(Cuboid::new(Vector::new(1.0, 2.0, 0.5))), ]; for shape in shapes { let as_trait = shape.as_shape(); // Use as_trait for queries... } ``` -------------------------------- ### 2D Line Segment Intersection Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/utilities.md Demonstrates how to use the segments_intersection2d function and handle the resulting SegmentsIntersection enum variants. ```rust use parry2d::utils::segments_intersection2d; use parry2d::math::Vector; let p1 = Vector::new(0.0, 0.0); let p2 = Vector::new(1.0, 1.0); let p3 = Vector::new(0.0, 1.0); let p4 = Vector::new(1.0, 0.0); match segments_intersection2d(&p1, &p2, &p3, &p4) { SegmentsIntersection::Intersecting(pt) => { println!("Intersection at: {:?}", pt); } SegmentsIntersection::Parallel => println!("Parallel"), SegmentsIntersection::Collinear => println!("Collinear"), } ``` -------------------------------- ### Build All Workspace Crates Source: https://github.com/dimforge/parry/blob/master/Claude.md Use this command to build all crates within the Parry workspace. ```bash cargo build ``` -------------------------------- ### Handling Polygon Intersection Errors Source: https://github.com/dimforge/parry/blob/master/_autodocs/errors.md Example demonstrating how to handle potential errors when performing convex polygon intersection. ```rust use parry2d::transformation::{ convex_polygons_intersection_with_tolerances, PolygonIntersectionTolerances }; use parry2d::math::Vector; let poly1 = vec![ Vector::new(0.0, 0.0), Vector::new(1.0, 0.0), Vector::new(0.5, 1.0), ]; let poly2 = vec![ Vector::new(0.0, 0.0), // Degenerate: same point twice Vector::new(0.0, 0.0), ]; let tolerances = PolygonIntersectionTolerances { max_distance: 1e-5, coplanar_threshold: 1e-5, }; match convex_polygons_intersection_with_tolerances(&poly1, &poly2, &tolerances) { Ok(Some(intersection)) => println!("Intersection: {:?}", intersection), Ok(None) => println!("No intersection"), Err(e) => println!("Error: {:?}", e), } ``` -------------------------------- ### Run Doc-Tests for All Variants Source: https://github.com/dimforge/parry/blob/master/Claude.md Runs documentation tests across all four crate variants (2D/3D, f32/f64). This is crucial for verifying cross-variant compatibility. ```bash cargo test --doc ``` -------------------------------- ### Format Code Source: https://github.com/dimforge/parry/blob/master/Claude.md Applies the project's standard code formatting to all files. ```bash cargo fmt ``` -------------------------------- ### WebAssembly size-optimized profile Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Profile configuration specifically tuned for minimizing WebAssembly binary size. ```toml [profile.release] opt-level = "z" # Optimize for size lto = true codegen-units = 1 ``` -------------------------------- ### Handling Mesh Intersection Errors Source: https://github.com/dimforge/parry/blob/master/_autodocs/errors.md Example demonstrating how to handle potential errors when performing mesh intersection using intersect_meshes. ```rust use parry3d::transformation::{intersect_meshes, MeshIntersectionTolerances}; use parry3d::shape::TriMesh; use parry3d::math::Pose; let mesh1 = TriMesh::new(vertices1, indices1); let mesh2 = TriMesh::new(vertices2, indices2); let tolerances = MeshIntersectionTolerances { voxel_size: 0.1, intersection_tolerance: 1e-5, }; match intersect_meshes(&mesh1, &Pose::identity(), &mesh2, &Pose::identity(), &tolerances) { Ok(result) => println!("Intersection computed"), Err(MeshIntersectionError::InvalidInput(msg)) => println!("Invalid mesh: {}", msg), Err(MeshIntersectionError::ComputationFailed) => println!("Algorithm failed"), } ``` -------------------------------- ### NonlinearRigidMotion struct definition Source: https://github.com/dimforge/parry/blob/master/_autodocs/types.md Defines rigid body motion using a starting pose, linear velocity, and angular velocity. ```rust pub struct NonlinearRigidMotion { pub position: Pose, // Starting pose pub linvel: Vector, // Linear velocity pub angvel: Vector, // Angular velocity (axis * angle_per_time) } impl NonlinearRigidMotion { pub fn position_at(&self, time: Real) -> Pose } ``` -------------------------------- ### Build with SIMD8 AVX2 support Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Use this RUSTFLAGS configuration to enable AVX2 and FMA instructions for SIMD8 performance. ```bash RUSTFLAGS="-C target-feature=+avx2,+fma" cargo build --release ``` -------------------------------- ### Build All Parry Crates Source: https://github.com/dimforge/parry/blob/master/Claude.md Compiles all crates within the Parry project to ensure basic build integrity. ```bash cargo build -p parry2d cargo build -p parry3d ``` -------------------------------- ### Convex Polygon Intersection Usage Example Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/transformations.md Demonstrates calculating the intersection of two convex polygons defined by vertices in counter-clockwise order. ```rust use parry2d::transformation::convex_polygons_intersection; use parry2d::math::Vector; let poly1 = vec![ Vector::new(0.0, 0.0), Vector::new(2.0, 0.0), Vector::new(2.0, 2.0), Vector::new(0.0, 2.0), ]; let poly2 = vec![ Vector::new(1.0, 1.0), Vector::new(3.0, 1.0), Vector::new(3.0, 3.0), Vector::new(1.0, 3.0), ]; if let Some(intersection) = convex_polygons_intersection(&poly1, &poly2) { println!("Intersection polygon: {:?}", intersection); } ``` -------------------------------- ### Configure Query Options Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Functions and structures for closest point queries, contact prediction, and ray casting configuration. ```rust // Closest points with distance limit pub fn closest_points( pos1: &Pose, g1: &dyn Shape, pos2: &Pose, g2: &dyn Shape, max_dist: Real, // 0.0 = exact, f32::MAX = unlimited ) -> Result // Contact prediction for CCD pub fn contact( pos1: &Pose, g1: &dyn Shape, pos2: &Pose, g2: &dyn Shape, prediction: Real, // 0.0 = exact, >0 = early detection ) -> Result, Unsupported> // Ray casting direction and distance pub struct Ray { pub origin: Vector, // Ray start pub dir: Vector, // Direction (typically normalized) } pub fn cast_ray( ray: &Ray, max_toi: Real, // Maximum distance along ray solid: bool, // true = ray stops inside, false = continuous ) -> Option ``` -------------------------------- ### Release profile configuration Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Optimized profile settings for production builds, including LTO and symbol stripping. ```toml [profile.release] opt-level = 3 # Maximum optimization debug = false # Remove debug symbols lto = true # Link-time optimization codegen-units = 1 # Single codegen unit for better optimization strip = true # Strip symbols ``` -------------------------------- ### Enable nalgebra and glamx conversion features Source: https://github.com/dimforge/parry/blob/master/CHANGELOG.md Configuration to enable type conversion between nalgebra and glam during the migration process. ```toml nalgebra = { version = "0.34", features = [ "convert-glam030" ] } glamx = { version = "0.1", features = ["nalgebra"] } ``` -------------------------------- ### Instantiate FeatureId variants Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/shapes.md Demonstrates creating instances of FeatureId for vertices, edges, and faces. ```rust use parry3d::shape::FeatureId; let vertex_feature = FeatureId::Vertex(0); let edge_feature = FeatureId::Edge(1); let face_feature = FeatureId::Face(2); ``` -------------------------------- ### Development profile configuration Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Standard profile settings for development builds with minimal optimization and debug symbols enabled. ```toml [profile.dev] opt-level = 0 # Minimal optimization debug = true # Include debug symbols ``` -------------------------------- ### Build for WASM Target Source: https://github.com/dimforge/parry/blob/master/Claude.md Builds a specific crate for the WebAssembly target. Ensure you are in the crate's directory. ```bash cd crates/parry3d && cargo build --target wasm32-unknown-unknown ``` -------------------------------- ### sweep_time_of_impact function and Sweep struct Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Provides low-level time-of-impact computation with detailed control over collision phases. The Sweep struct tracks the start, first contact, and separation times. ```rust pub fn sweep_time_of_impact( pos12: &Pose, vel12: &Vector, g1: &dyn Shape, g2: &dyn Shape, max_toi: Real, target_distance: Real, ) -> Result, Unsupported> pub struct Sweep { pub t0: Real, // Time when shapes start touching (0.0 if touching at start) pub t1: Real, // Time when shapes first touch (first contact) pub t2: Real, // Time when shapes fully separate after contact } ``` -------------------------------- ### Build Specific Parry Crate Source: https://github.com/dimforge/parry/blob/master/Claude.md Builds a particular crate, such as parry3d or parry2d. ```bash cargo build -p parry3d ``` ```bash cargo build -p parry2d ``` -------------------------------- ### Build with Enhanced Determinism Source: https://github.com/dimforge/parry/blob/master/Claude.md Builds crates with enhanced determinism features. Note: This is incompatible with SIMD features. ```bash cargo build --features enhanced-determinism ``` -------------------------------- ### Perform Standalone Shape Queries Source: https://github.com/dimforge/parry/blob/master/_autodocs/README.md Demonstrates using Parry directly for geometry operations without a full physics engine. ```rust // Use Parry directly for geometry without physics use parry3d::shape::{Ball, Cuboid}; use parry3d::query::closest_points; let shapes: Vec> = vec![ Box::new(Ball::new(1.0)), Box::new(Cuboid::new(Vector::new(1.0, 2.0, 0.5))), ]; ``` -------------------------------- ### Calculate mass properties for a Ball Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/mass-properties.md Demonstrates calculating mass properties for a ball shape using specific densities for water and steel. ```rust use parry3d::mass_properties; use parry3d::shape::Ball; let ball = Ball::new(1.0); // Water ball let water_density = 1000.0; let props_water = mass_properties::details::mass_properties_ball(ball.radius, water_density); // Steel ball let steel_density = 7850.0; let props_steel = mass_properties::details::mass_properties_ball(ball.radius, steel_density); println!("Water mass: {}", props_water.mass()); println!("Steel mass: {}", props_steel.mass()); ``` -------------------------------- ### 2D Array Structure and Methods Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/utilities.md Provides a 2D matrix storage structure with methods for initialization, retrieval, and setting values. Requires alloc. ```rust pub struct Array2 { // 2D matrix storage } impl Array2 { pub fn new(nrows: usize, ncols: usize) -> Self pub fn get(&self, i: usize, j: usize) -> Real pub fn set(&mut self, i: usize, j: usize, value: Real) } ``` -------------------------------- ### Integrate Parry with Rapier Physics Engines Source: https://github.com/dimforge/parry/blob/master/_autodocs/README.md Shows how Rapier2D and Rapier3D utilize Parry for internal shape representations and collision queries. ```rust // Rapier2D/Rapier3D use Parry for collision detection use rapier3d::prelude::*; let rigid_body_set = RigidBodySet::new(); let collider_set = ColliderSet::new(); // Rapier internally uses Parry for shape representations // and collision queries ``` -------------------------------- ### Run All Tests Source: https://github.com/dimforge/parry/blob/master/Claude.md Executes all tests across the entire workspace. ```bash cargo test ``` -------------------------------- ### Game Development Configuration Source: https://github.com/dimforge/parry/blob/master/_autodocs/configuration.md Configuration for performance-focused game development using single-precision floats, standard library support, and serialization. ```toml [dependencies] parry3d = { version = "0.30", features = ["std", "serde-serialize"] } ``` -------------------------------- ### Projecting a Point onto a Ball Source: https://github.com/dimforge/parry/blob/master/_autodocs/api-reference/queries.md Demonstrates using the project_point method on a Ball shape to find the closest point, distance, and containment status. ```rust use parry3d::query::PointQuery; use parry3d::shape::Ball; use parry3d::math::{Pose, Vector}; let ball = Ball::new(1.0); let pose = Pose::identity(); let point = Vector::new(2.0, 0.0, 0.0); let projection = ball.project_point(&pose, &point, false); println!("Closest point: {:?}", projection.point); println!("Distance: {}", (projection.point - point).length()); println!("Inside: {}", projection.is_inside); ```