symtropy_math/shape.rs
1// Copyright (C) 2024-2026 Tristan Stoltz / Luminous Dynamics
2// SPDX-License-Identifier: Apache-2.0 OR MIT
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 fn as_any(&self) -> &dyn std::any::Any;
21
22 /// Clone this shape into a new box.
23 fn clone_box(&self) -> Box<dyn Shape<D>>;
24}