MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / classify_angle

Function classify_angle

src/math.rs:83–97  ·  view source on GitHub ↗

Classifies a rotation in radians into an [`AngleType`]. Normalises to `[0, 2π)` first, then checks within `EPS` of each cardinal.

(radians: f32)

Source from the content-addressed store, hash-verified

81/// Classifies a rotation in radians into an [`AngleType`].
82/// Normalises to `[0, 2π)` first, then checks within `EPS` of each cardinal.
83pub fn classify_angle(radians: f32) -> AngleType {
84 let normalized = radians.rem_euclid(std::f32::consts::TAU);
85 const EPS: f32 = 0.001;
86 if normalized < EPS || (std::f32::consts::TAU - normalized) < EPS {
87 AngleType::Zero
88 } else if (normalized - std::f32::consts::FRAC_PI_2).abs() < EPS {
89 AngleType::Right90
90 } else if (normalized - std::f32::consts::PI).abs() < EPS {
91 AngleType::Straight180
92 } else if (normalized - 3.0 * std::f32::consts::FRAC_PI_2).abs() < EPS {
93 AngleType::Right270
94 } else {
95 AngleType::Arbitrary(normalized)
96 }
97}
98
99use crate::layout::CornerRadius;
100

Callers 3

test_classify_angleFunction · 0.85
renderFunction · 0.85
compute_rotated_aabbFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_classify_angleFunction · 0.68