#vector #game #geometry #collision #physics

collide

Simple extensible collision management

10 releases (5 breaking)

Uses new Rust 2024

0.7.0 Mar 21, 2026
0.5.1 Mar 15, 2026
0.2.1 Mar 29, 2025
0.2.0 Jan 9, 2022
0.1.0 May 25, 2021

#829 in Algorithms


Used in 5 crates

MIT/Apache

13KB
100 lines

Collide

crates.io docs.rs

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 collide::{Collider, CollisionInfo};

impl Collider for MyShape {
    type Vector = Vec3;

    fn check_collision(&self, other: &Self) -> bool {
        // Optional: cheap broad-phase check
        self.bounding_sphere_overlaps(other)
    }

    fn collision_info(&self, other: &Self) -> Option<CollisionInfo<Vec3>> {
        // Precise narrow-phase collision detection
    }
}

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 collide::{BoundingVolume, Bounded};

impl BoundingVolume for MySphere {
    fn overlaps(&self, other: &Self) -> bool { /* distance check */ }
    fn merged(&self, other: &Self) -> Self { /* enclosing sphere */ }
}

impl Bounded<MySphere> for MyConvex {
    fn bounding_volume(&self) -> MySphere { /* compute enclosing sphere */ }
}

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

  1. Dimension-generic: No feature may introduce dimension-specific or type-specific assumptions. This is the core principle.
  2. Interoperability: Share colliders across physics engines via the Collider trait.
  3. 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.

Dependencies

~595KB
~13K SLoC