Added util
This commit is contained in:
parent
84a3e0f5d0
commit
b634575791
20
lib/util/Cargo.toml
Normal file
20
lib/util/Cargo.toml
Normal 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
20
lib/util/src/lib.rs
Normal 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))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user