#[deprecated(
since = "0.0.29",
note = "renamed to `noyalib::lossless_float::LosslessFloat` (feature \
`lossless-float`); the `robotics` module and feature are removed \
in the next release"
)]
pub type StrictFloat = crate::lossless_float::LosslessFloat;
#[deprecated(
since = "0.0.29",
note = "renamed to `noyalib::lossless_float::LosslessFloatError` (feature \
`lossless-float`); the `robotics` module and feature are removed \
in the next release"
)]
pub type StrictFloatError = crate::lossless_float::LosslessFloatError;
#[deprecated(
since = "0.0.29",
note = "domain unit newtypes are leaving noyalib with the `robotics` \
module next release — copy the type into your own code (it has \
no dependence on noyalib)"
)]
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize)]
#[serde(transparent)]
pub struct Radians(pub f64);
#[allow(deprecated)]
impl<'de> serde_core::Deserialize<'de> for Radians {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde_core::Deserializer<'de>,
{
let degrees = f64::deserialize(deserializer)?;
Ok(Self(degrees.to_radians()))
}
}
#[deprecated(
since = "0.0.29",
note = "domain unit newtypes are leaving noyalib with the `robotics` \
module next release — copy the type into your own code (it has \
no dependence on noyalib)"
)]
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(transparent)]
pub struct Degrees(pub f64);
#[allow(deprecated)]
impl Degrees {
#[must_use]
pub fn to_radians(self) -> Radians {
Radians(self.0.to_radians())
}
}
#[allow(deprecated)]
impl Radians {
#[must_use]
pub fn to_degrees(self) -> Degrees {
Degrees(self.0.to_degrees())
}
}
#[cfg(test)]
#[allow(deprecated)]
mod tests {
use super::*;
#[test]
fn strict_float_alias_still_deserializes() {
let sf: StrictFloat = crate::from_str("1.23456789").unwrap();
assert!((sf.get() - 1.234_567_89).abs() < 1e-15);
}
#[test]
fn radians_from_degrees() {
let r: Radians = crate::from_str("180.0").unwrap();
assert!((r.0 - core::f64::consts::PI).abs() < 1e-10);
}
#[test]
fn radians_90() {
let r: Radians = crate::from_str("90.0").unwrap();
assert!((r.0 - core::f64::consts::FRAC_PI_2).abs() < 1e-10);
}
#[test]
fn radians_zero() {
let r: Radians = crate::from_str("0.0").unwrap();
assert!((r.0).abs() < 1e-15);
}
#[test]
fn degrees_roundtrip() {
let d: Degrees = crate::from_str("45.0").unwrap();
let r = d.to_radians();
let back = r.to_degrees();
assert!((back.0 - 45.0).abs() < 1e-10);
}
#[test]
fn degrees_deserialize() {
let d: Degrees = crate::from_str("90.0").unwrap();
assert!((d.0 - 90.0).abs() < 1e-15);
}
#[test]
fn radians_serialize() {
let r = Radians(core::f64::consts::PI);
let yaml = crate::to_string(&r).unwrap();
assert!(yaml.contains("3.14159"));
}
}