phys-collision 2.0.1-beta.0

Provides collision detection ability
// Copyright (C) 2020-2025 phys-collision authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::any::Any;

use glam::Point3;
pub use phys_geom::volume::ComputeVolume;
use phys_geom::{Aabb3, ComputeAabb3};

use super::ComplexShapeId;
use crate::ray::{Raycast, RaycastHitResult};
use crate::{ContainsPoint, ContainsResult, Expansion, Ray, SignedDistanceToPoint};
pub trait ComplexShapeTrait:
    ComputeAabb3
    + Raycast
    + Expansion
    + ContainsPoint
    + SignedDistanceToPoint
    + ComputeVolume
    + ShapePlugin
    + Clone
{
}

pub trait ShapeSetTrait: Send + Sync + dyn_clone::DynClone {
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;
    fn compute_aabb(&self, id: ComplexShapeId) -> Aabb3;
    fn max_radius_and_max_angular_expansion(&self, id: ComplexShapeId) -> (f32, f32);
    fn raycast(
        &self,
        id: ComplexShapeId,
        local_ray: Ray,
        max_distance: f32,
        discard_inside_hit: bool,
    ) -> Option<RaycastHitResult>;
    fn contains_point_with_threshold(
        &self,
        id: ComplexShapeId,
        local_point: Point3,
        threshold: f32,
    ) -> ContainsResult;
    fn signed_distance_to_point(&self, id: ComplexShapeId, local_point: Point3) -> f32;
    fn compute_volume(&self, id: ComplexShapeId) -> f32;
}

dyn_clone::clone_trait_object!(ShapeSetTrait);

pub trait ShapePlugin {
    const PLUGIN_ID: u64;
}