Skip to main content

symtropy_math/
shape.rs

1// Copyright (C) 2024-2026 Tristan Stoltz / Luminous Dynamics
2// SPDX-License-Identifier: AGPL-3.0-or-later
3// Commercial licensing: see COMMERCIAL_LICENSE.md at repository root
4use crate::point::Point;
5use nalgebra::SVector;
6
7/// Trait for D-dimensional convex shapes compatible with GJK collision detection.
8///
9/// The support function is the only requirement for GJK — given a direction,
10/// return the point on the shape's boundary furthest in that direction.
11/// This generalizes naturally to any dimension.
12pub trait Shape<const D: usize>: Send + Sync {
13    /// Support function: furthest point on the boundary in the given direction.
14    fn support(&self, direction: &SVector<f64, D>) -> SVector<f64, D>;
15
16    /// Bounding sphere: (center, radius).
17    fn bounding_sphere(&self) -> (Point<D>, f64);
18
19    /// Downcast to concrete type for specialized collision dispatch.
20    ///
21    /// Used by the narrowphase to dispatch to analytical contacts when
22    /// one shape is a HalfSpace (bypassing GJK+EPA for a dot product).
23    fn as_any(&self) -> &dyn std::any::Any;
24}