Collide
A dimension-generic collision detection ecosystem for Rust. All traits and types work in any dimension (2D, 3D, N-D) and with any numeric type (f32, f64, etc.).
Crates
| Crate | Description |
|---|---|
collide |
Core traits: Collider, BoundingVolume, Bounded, Transformable, SpatialPartition |
collide-sphere |
Sphere collider (center + radius). Simplest and most efficient collider type |
collide-capsule |
Capsule collider (two endpoints + radius). Also represents spheres, lines, points |
collide-convex |
Convex hull collider (N points + radius). GJK/EPA algorithm. Handles arbitrary convex shapes |
collide-ray |
Ray type (origin + direction). Shape crates implement Collider<Ray> via feature flags |
collision-detection |
Collision manager with brute force, spatial partitioning, and BVH algorithms |
Core Traits
Collider
The fundamental trait. Implement collision_info to define how two shapes collide. Override check_collision with a cheap pre-check (bounding sphere, AABB) to skip expensive narrow-phase tests.
use ;
BoundingVolume + Bounded
For BVH-based collision detection. BoundingVolume defines overlap testing and merging. Bounded<B> is generic over the volume type, so a collider can provide multiple bounding representations.
use ;
Wrapper Types
BoundedCollider<B, C> wraps a collider with a bounding volume for automatic pre-checks. Nestable for cascading broad-to-narrow checks.
Transformed<C, T> wraps a collider with a transform. Requires Transformable<T> on the shape and Transform<V> (from vector-space) on the transform type.
SpatialPartition
Maps colliders to spatial cells for hash-based acceleration. Used by collision-detection for O(n×k) algorithms.
Shape Hierarchy
Sphere center + radius Copy, cheapest
Capsule two endpoints + radius Copy, handles elongated shapes
Convex N points + radius Clone, arbitrary convex hulls (GJK/EPA)
Each shape crate can enable ray support via feature flag ray, which implements Collider<Ray>.
Design Goals
- Dimension-generic: No feature may introduce dimension-specific or type-specific assumptions. This is the core principle.
- Interoperability: Share colliders across physics engines via the
Collidertrait. - Extensibility: New collider types without breaking existing implementations.
This project is designed for use with AI coding assistants. The API surface is small and consistent: a single generic Collider trait with two methods, composable wrapper types (BoundedCollider, Transformed), and uniform feature flags across shape crates. All public types implement standard traits (Clone, Debug) and use CollisionInfo<V> as the universal result type.