cas_compute/funcs/
angle.rs

1//! Utilities for converting between degrees and radians.
2
3use cas_attrs::builtin;
4use crate::consts::{PI, TAU};
5use rug::Float;
6
7/// Converts the given value from degrees to radians.
8#[derive(Debug)]
9pub struct Dtr;
10
11#[cfg_attr(feature = "numerical", builtin)]
12impl Dtr {
13    pub fn eval_static(n: Float) -> Float {
14        n * &*PI / 180.0
15    }
16}
17
18/// Converts the given value from radians to degrees.
19#[derive(Debug)]
20pub struct Rtd;
21
22#[cfg_attr(feature = "numerical", builtin)]
23impl Rtd {
24    pub fn eval_static(n: Float) -> Float {
25        n * 180.0 / &*PI
26    }
27}
28
29/// Computes the amount of angle needed to traverse a specified fraction of a circle.
30///
31/// For example, `circle(0.25)` returns `PI / 2`, since a rotation of `PI / 2` radians is needed to
32/// traverse a quarter of a circle.
33#[derive(Debug)]
34pub struct Circle;
35
36#[cfg_attr(feature = "numerical", builtin)]
37impl Circle {
38    pub fn eval_static(n: Float) -> Float {
39        n * &*TAU
40    }
41}