Added util

This commit is contained in:
Mark 2025-01-04 17:57:56 -08:00
parent 84a3e0f5d0
commit b634575791
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 40 additions and 0 deletions

20
lib/util/Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "galactica-util"
description = "Shared utilities"
categories = { workspace = true }
keywords = { workspace = true }
version = { workspace = true }
rust-version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
[lints]
workspace = true
[dependencies]
nalgebra = { workspace = true }

20
lib/util/src/lib.rs Normal file
View File

@ -0,0 +1,20 @@
#![warn(missing_docs)]
//! Shared utilities
use nalgebra::Vector2;
/// Convert an angle in degrees to radians
pub const fn to_radians(degrees: f32) -> f32 {
return (degrees / 360.0) * std::f32::consts::TAU;
}
/// Convert an angle in radians to degrees
pub const fn to_degrees(radians: f32) -> f32 {
return (radians / std::f32::consts::TAU) * 360.0;
}
/// Compute the clockwise angle between two vectors
/// Returns a value in [-pi, pi]
pub fn clockwise_angle(a: &Vector2<f32>, b: &Vector2<f32>) -> f32 {
(a.x * b.y - b.x * a.y).atan2(a.dot(&b))
}