1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub use glam::*;
mod circle;
mod rect;
pub use circle::Circle;
pub use rect::{Rect, RectOffset};
pub fn polar_to_cartesian(rho: f32, theta: f32) -> Vec2 {
vec2(rho * theta.cos(), rho * theta.sin())
}
pub fn cartesian_to_polar(cartesian: Vec2) -> Vec2 {
vec2(
(cartesian.x.powi(2) + cartesian.y.powi(2)).sqrt(),
cartesian.y.atan2(cartesian.x),
)
}
pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> T {
if value < min {
min
} else if value > max {
max
} else {
value
}
}