Galactica/crates/content/src/util.rs

20 lines
352 B
Rust
Raw Normal View History

2024-01-08 21:02:02 -08:00
use cgmath::{Angle, Point2, Rad, Vector2};
2023-12-21 11:26:44 -08:00
#[derive(Debug, Clone, Copy)]
pub struct Polar {
2023-12-25 16:22:44 -08:00
pub center: Point2<f32>,
pub radius: f32,
2024-01-08 21:02:02 -08:00
pub angle: Rad<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> {
2023-12-25 10:29:52 -08:00
let v = Vector2 {
2023-12-22 17:24:53 -08:00
x: self.radius * self.angle.sin(),
y: 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
}
}