use nalgebra::Vector2;
use crate::misc::FloatingPoint;
#[derive(Debug, Clone, Copy)]
pub struct SurfaceMetric<T: FloatingPoint> {
pub e: T,
pub g: T,
}
impl<T: FloatingPoint> SurfaceMetric<T> {
pub fn new(e: T, g: T) -> Self {
Self { e, g }
}
pub fn max_uv_step(&self, target_length: T) -> Vector2<T> {
let du = if self.e > T::default_epsilon() {
target_length / self.e.sqrt()
} else {
target_length
};
let dv = if self.g > T::default_epsilon() {
target_length / self.g.sqrt()
} else {
target_length
};
Vector2::new(du, dv)
}
}
pub fn curvature_to_edge_length<T: FloatingPoint>(curvature: T, deflection: T) -> T {
let eps = T::from_f64(1e-12).unwrap();
if curvature.abs() < eps {
return T::from_f64(1e6).unwrap(); }
let two = T::from_f64(2.0).unwrap();
(two * deflection / curvature.abs()).sqrt() * two
}