use crate::geometry::Vec2;
use crate::primitives::tolerance::{COLLINEAR_TOL_DEG, DEGENERATE_EPS};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) enum Class {
Corner,
Collinear,
NonCorner,
Endpoint,
}
pub(crate) fn angle_between_deg(a: Vec2, b: Vec2) -> f64 {
let a_len = a.hypot();
let b_len = b.hypot();
if a_len <= DEGENERATE_EPS || b_len <= DEGENERATE_EPS {
return 180.0;
}
let cos = (a.x * b.x + a.y * b.y) / (a_len * b_len);
cos.clamp(-1.0, 1.0).acos().to_degrees()
}
pub(crate) fn classify_angle(angle_deg: f64, max_angle_deg: f64) -> Class {
if angle_deg >= 180.0 - COLLINEAR_TOL_DEG || angle_deg <= COLLINEAR_TOL_DEG {
Class::Collinear
} else if angle_deg <= max_angle_deg {
Class::Corner
} else {
Class::NonCorner
}
}