pub struct DefaultQueryDispatcher;Expand description
The default query dispatcher implementation provided by Parry.
This dispatcher handles all the built-in shape types and automatically selects the most
appropriate algorithm for each shape pair combination. It is used internally by all the
free functions in the crate::query module.
§What It Does
DefaultQueryDispatcher implements efficient query dispatch logic that:
- Examines shape types using runtime type checking (
as_ball(),as_cuboid(), etc.) - Selects specialized algorithms for specific shape pairs (e.g., ball-ball, cuboid-cuboid)
- Falls back to general algorithms when specialized versions aren’t available (e.g., GJK/EPA for support map shapes)
- Handles composite shapes by decomposing them and performing multiple sub-queries
§Supported Shape Combinations
The dispatcher provides optimized implementations for many shape pairs, including:
§Basic Shapes
- Ball-Ball: Analytical formulas (fastest)
- Ball-Convex: Specialized algorithms
- Cuboid-Cuboid: SAT-based algorithms
- Segment-Segment: Direct geometric calculations
§Support Map Shapes
For shapes implementing the SupportMap trait (most convex shapes):
- Uses GJK algorithm for distance and intersection queries
- Uses EPA algorithm for penetration depth when shapes overlap
§Composite Shapes
Handles complex shapes by decomposing them:
- TriMesh: Queries individual triangles using BVH acceleration
- Compound: Queries component shapes
- HeightField: Efficiently queries relevant cells
- Voxels: Queries occupied voxels
§Special Cases
- HalfSpace: Infinite planes with specialized handling
- Rounded shapes: Automatically accounts for border radius
§When to Use
You typically don’t need to create DefaultQueryDispatcher explicitly. The free functions
in crate::query use it automatically:
use parry3d::query;
use parry3d::shape::Ball;
use parry3d::na::Isometry3;
let ball1 = Ball::new(1.0);
let ball2 = Ball::new(1.0);
let pos1 = Isometry3::identity();
let pos2 = Isometry3::translation(5.0, 0.0, 0.0);
// This uses DefaultQueryDispatcher internally
let distance = query::distance(&pos1, &ball1, &pos2, &ball2);However, you might use it explicitly when:
- Creating a dispatcher chain with custom dispatchers
- Implementing custom query logic that needs to delegate to default behavior
- Building a custom collision detection pipeline
§Example: Direct Usage
use parry3d::query::{QueryDispatcher, DefaultQueryDispatcher};
use parry3d::shape::{Ball, Cuboid};
use parry3d::na::{Isometry3, Vector3};
let dispatcher = DefaultQueryDispatcher;
let ball = Ball::new(1.0);
let cuboid = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let pos1 = Isometry3::identity();
let pos2 = Isometry3::translation(3.0, 0.0, 0.0);
let pos12 = pos1.inv_mul(&pos2);
// Query intersection
let intersects = dispatcher.intersection_test(&pos12, &ball, &cuboid)
.expect("This shape pair is supported");
// Query distance
let dist = dispatcher.distance(&pos12, &ball, &cuboid)
.expect("This shape pair is supported");
println!("Distance: {}, Intersecting: {}", dist, intersects);§Example: Chaining with Custom Dispatcher
use parry3d::query::{QueryDispatcher, DefaultQueryDispatcher};
struct MyCustomDispatcher;
// ... implement QueryDispatcher for MyCustomDispatcher ...
// Try custom dispatcher first, fall back to default
let dispatcher = MyCustomDispatcher.chain(DefaultQueryDispatcher);
// Now queries will use your custom logic when applicable,
// and Parry's default logic otherwise
let dist = dispatcher.distance(&pos12, shape1, shape2)?;§Algorithm Selection Strategy
The dispatcher follows this priority order when selecting algorithms:
- Exact shape type matching: Ball-Ball, Cuboid-Cuboid, etc.
- Specialized asymmetric pairs: Ball-ConvexShape, HalfSpace-SupportMap, etc.
- Support map fallback: Any SupportMap-SupportMap pair uses GJK/EPA
- Composite shape decomposition: TriMesh, Compound, HeightField, Voxels
- Unsupported: Returns
Err(Unsupported)if no algorithm exists
§Performance Characteristics
- Type checking overhead: Minimal - uses efficient trait object downcasting
- Specialized algorithms: O(1) for ball-ball, O(log n) to O(n) for composite shapes
- GJK/EPA: Iterative algorithms that typically converge in 5-20 iterations
- Composite shapes: Use BVH for O(log n) acceleration of sub-queries
§Thread Safety
DefaultQueryDispatcher is Send + Sync and has no internal state, making it safe to
share across threads. You can use a single instance for all queries in a parallel
collision detection system.
§Limitations
Some shape pairs are not supported and will return Err(Unsupported):
- Custom shapes not implementing required traits (e.g., not convex, no support map)
- Some asymmetric pairs that lack specialized implementations
- Certain combinations involving custom user shapes
When encountering Unsupported, you can implement a custom dispatcher to handle these cases.
§See Also
QueryDispatcher: The trait this struct implementscrate::query: High-level query functions that use this dispatcherPersistentQueryDispatcher: Extended trait for contact manifold queries
Trait Implementations§
Source§impl Clone for DefaultQueryDispatcher
impl Clone for DefaultQueryDispatcher
Source§fn clone(&self) -> DefaultQueryDispatcher
fn clone(&self) -> DefaultQueryDispatcher
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DefaultQueryDispatcher
impl Debug for DefaultQueryDispatcher
Source§impl<ManifoldData, ContactData> PersistentQueryDispatcher<ManifoldData, ContactData> for DefaultQueryDispatcher
impl<ManifoldData, ContactData> PersistentQueryDispatcher<ManifoldData, ContactData> for DefaultQueryDispatcher
Source§fn contact_manifolds(
&self,
pos12: &Isometry<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
prediction: f32,
manifolds: &mut Vec<ContactManifold<ManifoldData, ContactData>>,
workspace: &mut Option<ContactManifoldsWorkspace>,
) -> Result<(), Unsupported>
fn contact_manifolds( &self, pos12: &Isometry<f32>, shape1: &dyn Shape, shape2: &dyn Shape, prediction: f32, manifolds: &mut Vec<ContactManifold<ManifoldData, ContactData>>, workspace: &mut Option<ContactManifoldsWorkspace>, ) -> Result<(), Unsupported>
Source§fn contact_manifold_convex_convex(
&self,
pos12: &Isometry<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
normal_constraints1: Option<&dyn NormalConstraints>,
normal_constraints2: Option<&dyn NormalConstraints>,
prediction: f32,
manifold: &mut ContactManifold<ManifoldData, ContactData>,
) -> Result<(), Unsupported>
fn contact_manifold_convex_convex( &self, pos12: &Isometry<f32>, shape1: &dyn Shape, shape2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, normal_constraints2: Option<&dyn NormalConstraints>, prediction: f32, manifold: &mut ContactManifold<ManifoldData, ContactData>, ) -> Result<(), Unsupported>
Source§impl QueryDispatcher for DefaultQueryDispatcher
impl QueryDispatcher for DefaultQueryDispatcher
Source§fn distance(
&self,
pos12: &Isometry<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
) -> Result<f32, Unsupported>
fn distance( &self, pos12: &Isometry<f32>, shape1: &dyn Shape, shape2: &dyn Shape, ) -> Result<f32, Unsupported>
Computes the minimum distance separating two shapes.
Returns 0.0 if the objects are touching or penetrating.
Source§fn intersection_test(
&self,
pos12: &Isometry<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
) -> Result<bool, Unsupported>
fn intersection_test( &self, pos12: &Isometry<f32>, shape1: &dyn Shape, shape2: &dyn Shape, ) -> Result<bool, Unsupported>
Source§fn contact(
&self,
pos12: &Isometry<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
prediction: f32,
) -> Result<Option<Contact>, Unsupported>
fn contact( &self, pos12: &Isometry<f32>, shape1: &dyn Shape, shape2: &dyn Shape, prediction: f32, ) -> Result<Option<Contact>, Unsupported>
Source§fn closest_points(
&self,
pos12: &Isometry<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
max_dist: f32,
) -> Result<ClosestPoints, Unsupported>
fn closest_points( &self, pos12: &Isometry<f32>, shape1: &dyn Shape, shape2: &dyn Shape, max_dist: f32, ) -> Result<ClosestPoints, Unsupported>
Source§fn cast_shapes(
&self,
pos12: &Isometry<f32>,
local_vel12: &Vector<f32>,
shape1: &dyn Shape,
shape2: &dyn Shape,
options: ShapeCastOptions,
) -> Result<Option<ShapeCastHit>, Unsupported>
fn cast_shapes( &self, pos12: &Isometry<f32>, local_vel12: &Vector<f32>, shape1: &dyn Shape, shape2: &dyn Shape, options: ShapeCastOptions, ) -> Result<Option<ShapeCastHit>, Unsupported>
distance. Read moreSource§fn cast_shapes_nonlinear(
&self,
motion1: &NonlinearRigidMotion,
shape1: &dyn Shape,
motion2: &NonlinearRigidMotion,
shape2: &dyn Shape,
start_time: f32,
end_time: f32,
stop_at_penetration: bool,
) -> Result<Option<ShapeCastHit>, Unsupported>
fn cast_shapes_nonlinear( &self, motion1: &NonlinearRigidMotion, shape1: &dyn Shape, motion2: &NonlinearRigidMotion, shape2: &dyn Shape, start_time: f32, end_time: f32, stop_at_penetration: bool, ) -> Result<Option<ShapeCastHit>, Unsupported>
Source§fn chain<U: QueryDispatcher>(self, other: U) -> QueryDispatcherChain<Self, U>where
Self: Sized,
fn chain<U: QueryDispatcher>(self, other: U) -> QueryDispatcherChain<Self, U>where
Self: Sized,
QueryDispatcher that falls back on other for cases not handled by selfAuto Trait Implementations§
impl Freeze for DefaultQueryDispatcher
impl RefUnwindSafe for DefaultQueryDispatcher
impl Send for DefaultQueryDispatcher
impl Sync for DefaultQueryDispatcher
impl Unpin for DefaultQueryDispatcher
impl UnwindSafe for DefaultQueryDispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.