thimni 0.2.3

efficient SDF collision without discretizatio, neural nets, or interval arithmetic
Documentation
use std::marker::PhantomData;

use crate::{sdf::SDF, utils::AABB, vector::Vector};

#[derive(Copy, Clone)]
pub struct Combinator<const N: usize, V: Vector<N>, A: SDF<N, V>, B: SDF<N, V>> {
    pub obj_a: A,
    pub ovj_b: B,
    pub function: fn(a: f32, b: f32) -> f32,
    // this feels incredibly hacky.
    _phantom: PhantomData<V>,
}

impl<const N: usize, V: Vector<N>, A: SDF<N, V>, B: SDF<N, V>> SDF<N, V>
    for Combinator<N, V, A, B>
{
    fn dist(&self, p: V) -> f32 {
        (self.function)(self.obj_a.dist(p), self.ovj_b.dist(p))
    }

    fn aabb(&self) -> crate::utils::AABB<N, V> {
        let (abb, bbb) = (self.obj_a.aabb(), self.ovj_b.aabb());

        AABB {
            min: abb.min.cmin(bbb.min),
            max: abb.max.cmax(bbb.max),
        }
    }
}