blockworx_geom/angle.rs
1//! A rotation, so a signature cannot take a bare number of radians.
2
3/// A rotation in radians, clockwise on a screen whose y axis points down —
4/// the sense every backend's rotated text takes.
5#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
6#[serde(transparent)]
7pub struct Angle(f32);
8
9impl Angle {
10 pub const ZERO: Self = Self(0.0);
11 /// A quarter turn: text drawn top-to-bottom.
12 pub const QUARTER_TURN: Self = Self(core::f32::consts::FRAC_PI_2);
13
14 pub const fn radians(radians: f32) -> Self {
15 Self(radians)
16 }
17
18 pub fn degrees(self) -> f32 {
19 self.0.to_degrees()
20 }
21}
22
23impl From<Angle> for f32 {
24 fn from(angle: Angle) -> Self {
25 angle.0
26 }
27}