// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2023, 2025 lacklustr@protonmail.com https://github.com/eadf
// This file is part of the hronn crate.

use crate::{prelude, probe};
use vector_traits::prelude::GenericVector3;

#[inline(always)]
pub fn debug_cone_to_edge_collision<T: GenericVector3>(
    edge: probe::EdgeAndCenterType<T>,
    cr: T::Scalar,
    ch: T::Scalar,
) -> Option<T::Scalar> {
    use crate::probe::tapered_end_to_edge::tapered_end_to_edge_collision;
    let cone = probe::tapered_end::ConeProperties::<T>::new(cr, ch);
    let mut mt = prelude::MaximumTracker::<prelude::SearchResult<T>>::default();
    //println!("Testing center:{:?} cr:{:?}, ch:{:?}, po:{:?} p1:{:?}", center, cr, ch, p0, p1);
    tapered_end_to_edge_collision(edge, cone, 0, &mut mt);
    Some(mt.get_max()?.z_value)
}

#[inline(always)]
pub fn debug_ball_end_to_edge_collision<T: GenericVector3>(
    edge: probe::EdgeAndCenterType<T>,
    probe_radius: T::Scalar,
) -> Option<T::Scalar> {
    use crate::probe::ball_end::BallEndProperties;
    use crate::probe::ball_end_to_edge::ball_end_to_edge_collision;
    let mut mt = prelude::MaximumTracker::<prelude::SearchResult<T>>::default();

    ball_end_to_edge_collision(edge, BallEndProperties::new(probe_radius), 0, &mut mt);
    Some(mt.get_max()?.z_value)
}

#[inline(always)]
pub fn debug_square_end_to_edge_collision<T: GenericVector3>(
    edge: probe::EdgeAndCenterType<T>,
    probe_radius: T::Scalar,
) -> Option<T::Scalar> {
    use crate::probe::square_end_to_edge::square_end_to_edge_collision;
    let mut mt = prelude::MaximumTracker::<prelude::SearchResult<T>>::default();

    square_end_to_edge_collision(edge, probe_radius, 0, &mut mt);
    Some(mt.get_max()?.z_value)
}

#[inline(always)]
pub fn xy_distance_to_line_squared<T: GenericVector3>(
    p: T::Vector2,
    p0: T,
    p1: T,
) -> probe::EdgeAndCenterType<T> {
    probe::xy_distance_to_line_squared(p, p0, p1)
}
