Added util function

master
Mark 2024-01-14 11:09:51 -08:00
parent 0289031c88
commit 129b134114
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,8 @@
//! Various utilities //! Various utilities
use nalgebra::Vector2;
pub mod constants; pub mod constants;
pub mod timing; pub mod timing;
@ -9,3 +11,9 @@ pub mod timing;
pub fn to_radians(degrees: f32) -> f32 { pub fn to_radians(degrees: f32) -> f32 {
return (degrees / 360.0) * std::f32::consts::TAU; return (degrees / 360.0) * std::f32::consts::TAU;
} }
/// Compute the clockwise angle between two vectors
/// Returns a value in [0, 2pi]
pub fn clockwise_angle(a: &Vector2<f32>, b: &Vector2<f32>) -> f32 {
(a.x * b.y - b.x * a.y).atan2(a.dot(&b))
}