123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- use crate::{Float, Numeric, Primitive};
- pub trait Angular<T: Numeric + Float + Primitive>: From<Degree<T>> + From<Radiant<T>> {
- fn degree(&self) -> T;
- fn radiant(&self) -> T;
- }
- #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
- #[repr(transparent)]
- pub struct Degree<T: Numeric + Float + Primitive> {
- value: T,
- }
- impl<T: Numeric + Float + Primitive> Degree<T> {
- pub fn new(value: T) -> Self {
- Self { value }
- }
- }
- impl<T: Numeric + Float + Primitive> From<Radiant<T>> for Degree<T> {
- fn from(source: Radiant<T>) -> Self {
- Degree::new(source.value * T::pi() / unsafe { T::whole(180) })
- }
- }
- impl<T: Numeric + Float + Primitive> Angular<T> for Degree<T> {
- fn degree(&self) -> T {
- self.value
- }
- fn radiant(&self) -> T {
- Radiant::from(*self).value
- }
- }
- #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
- #[repr(transparent)]
- pub struct Radiant<T: Numeric + Float + Primitive> {
- value: T,
- }
- impl<T: Numeric + Float + Primitive> Radiant<T> {
- pub fn new(value: T) -> Self {
- Self { value }
- }
- }
- impl<T: Numeric + Float + Primitive> From<Degree<T>> for Radiant<T> {
- fn from(source: Degree<T>) -> Self {
- Radiant::new(source.value * unsafe { T::whole(180) } / T::pi())
- }
- }
- impl<T: Numeric + Float + Primitive> Angular<T> for Radiant<T> {
- fn degree(&self) -> T {
- Degree::from(*self).value
- }
- fn radiant(&self) -> T {
- self.value
- }
- }
|