Galactica/crates/content/src/util.rs

25 lines
435 B
Rust
Raw Normal View History

2024-01-12 22:47:40 -08:00
use nalgebra::{Point2, Vector2};
2023-12-21 11:26:44 -08:00
#[derive(Debug, Clone, Copy)]
pub struct Polar {
2024-01-12 22:47:40 -08:00
/// The center of this polar coordinate
2023-12-25 16:22:44 -08:00
pub center: Point2<f32>,
2024-01-12 22:47:40 -08:00
/// The radius of this polar coordinate
2023-12-25 16:22:44 -08:00
pub radius: f32,
2024-01-12 22:47:40 -08:00
/// In radians
pub angle: f32,
2023-12-21 11:26:44 -08:00
}
2023-12-22 17:24:53 -08:00
impl Polar {
2023-12-25 16:22:44 -08:00
pub fn to_cartesian(self) -> Point2<f32> {
2024-01-12 22:47:40 -08:00
let v = Vector2::new(
self.radius * self.angle.sin(),
self.radius * self.angle.cos(),
);
2023-12-25 10:29:52 -08:00
return self.center + v;
2023-12-21 11:26:44 -08:00
}
}