use std::default::Default;
use std::f64::consts;
use crate::{EvalResult, Value};
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Rounding {
Round(u8),
NoRounding,
}
impl Default for Rounding {
fn default() -> Self {
Rounding::Round(8)
}
}
impl Rounding {}
#[derive(Clone, Copy, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AngleUnit {
#[default]
Radian,
Degree,
Turn,
}
impl AngleUnit {
pub fn convert_value(self, to: Self, value: Value) -> EvalResult<Value> {
let as_radians = match self {
Self::Radian => value,
Self::Degree => {
let division_result = value / Value::from(180);
let division_value = match division_result {
Ok(val) => val,
Err(e) => return Err(e), };
let final_result = division_value * Value::from(consts::PI);
let result_value = match final_result {
Ok(val) => val,
Err(e) => return Err(e), };
result_value
}
Self::Turn => {
let division_result = value / Value::from(0.5);
let division_value = match division_result {
Ok(val) => val,
Err(e) => return Err(e), };
let final_result = division_value / Value::from(consts::PI);
let result_value = match final_result {
Ok(val) => val,
Err(e) => return Err(e), };
result_value
}
};
Ok(match to {
Self::Radian => as_radians,
Self::Degree => {
let division_result = as_radians / Value::from(consts::PI);
let division_value = match division_result {
Ok(val) => val,
Err(e) => return Err(e), };
let final_result = division_value * Value::from(180);
match final_result {
Ok(val) => val,
Err(e) => return Err(e), }
}
Self::Turn => {
let division_result = as_radians / Value::from(consts::PI);
let division_value = match division_result {
Ok(val) => val,
Err(e) => return Err(e), };
let final_result = division_value * Value::from(0.5);
match final_result {
Ok(val) => val,
Err(e) => return Err(e), }
}
})
}
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DepthLimit {
Limit(u32),
NoLimit,
}
impl Default for DepthLimit {
fn default() -> Self {
DepthLimit::Limit(49)
}
}