Galactica/crates/content/src/util.rs

20 lines
352 B
Rust
Raw Normal View History

2023-12-25 10:29:52 -08:00
use cgmath::{Angle, Deg, Point2, 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,
pub angle: Deg<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
}
}