#[repr(transparent)]pub struct Degree(pub f32);Expand description
Representation of a Degree unit of angles.
It is not an SI unit—the SI unit of angular measure is the radian—but it is mentioned in the SI brochure as an accepted unit. Because a full rotation equals 2π radians, one degree is equivalent to π/180 radians.
Tuple Fields§
§0: f32Implementations§
source§impl Degree
impl Degree
sourcepub fn to_radians(self) -> Radian
pub fn to_radians(self) -> Radian
sourcepub const fn to_degrees(self) -> Degree
pub const fn to_degrees(self) -> Degree
Identity conversion.
This exists for symmetry with the other angle definitions.
§Example
Basic use:
assert_eq!(Degree::ONE_REVOLUTION.to_degrees(), Degree::ONE_REVOLUTION);sourcepub fn to_gradians(self) -> Gradian
pub fn to_gradians(self) -> Gradian
sourcepub fn from_radians(angle: Radian) -> Self
pub fn from_radians(angle: Radian) -> Self
sourcepub fn from_degrees(angle: Degree) -> Self
pub fn from_degrees(angle: Degree) -> Self
source§impl Degree
impl Degree
sourcepub const ONE_REVOLUTION: Self = _
pub const ONE_REVOLUTION: Self = _
Constant for the number of units of Self required to perform one
full revolution around a unit circle.
sourcepub fn constrained(self) -> Self
pub fn constrained(self) -> Self
Constructs a new instance of this angle by constraining the result to be within one revolution.
Note: This will
sourcepub fn revolutions(self) -> f32
pub fn revolutions(self) -> f32
Counts the number of times this angle has revolved round the unit circle.
Methods from Deref<Target = f32>§
pub const RADIX: u32 = 2u32
pub const MANTISSA_DIGITS: u32 = 24u32
pub const DIGITS: u32 = 6u32
pub const EPSILON: f32 = 1.1920929E-7f32
pub const MIN: f32 = -3.40282347E+38f32
pub const MIN_POSITIVE: f32 = 1.17549435E-38f32
pub const MAX: f32 = 3.40282347E+38f32
pub const MIN_EXP: i32 = -125i32
pub const MAX_EXP: i32 = 128i32
pub const MIN_10_EXP: i32 = -37i32
pub const MAX_10_EXP: i32 = 38i32
pub const NAN: f32 = NaN_f32
pub const INFINITY: f32 = +Inf_f32
pub const NEG_INFINITY: f32 = -Inf_f32
1.62.0 · sourcepub fn total_cmp(&self, other: &f32) -> Ordering
pub fn total_cmp(&self, other: &f32) -> Ordering
Returns the ordering between self and other.
Unlike the standard partial comparison between floating point numbers,
this comparison always produces an ordering in accordance to
the totalOrder predicate as defined in the IEEE 754 (2008 revision)
floating point standard. The values are ordered in the following sequence:
- negative quiet NaN
- negative signaling NaN
- negative infinity
- negative numbers
- negative subnormal numbers
- negative zero
- positive zero
- positive subnormal numbers
- positive numbers
- positive infinity
- positive signaling NaN
- positive quiet NaN.
The ordering established by this function does not always agree with the
PartialOrd and PartialEq implementations of f32. For example,
they consider negative and positive zero equal, while total_cmp
doesn’t.
The interpretation of the signaling NaN bit follows the definition in the IEEE 754 standard, which may not match the interpretation by some of the older, non-conformant (e.g. MIPS) hardware implementations.
§Example
struct GoodBoy {
name: String,
weight: f32,
}
let mut bois = vec![
GoodBoy { name: "Pucci".to_owned(), weight: 0.1 },
GoodBoy { name: "Woofer".to_owned(), weight: 99.0 },
GoodBoy { name: "Yapper".to_owned(), weight: 10.0 },
GoodBoy { name: "Chonk".to_owned(), weight: f32::INFINITY },
GoodBoy { name: "Abs. Unit".to_owned(), weight: f32::NAN },
GoodBoy { name: "Floaty".to_owned(), weight: -5.0 },
];
bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
// `f32::NAN` could be positive or negative, which will affect the sort order.
if f32::NAN.is_sign_negative() {
assert!(bois.into_iter().map(|b| b.weight)
.zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
.all(|(a, b)| a.to_bits() == b.to_bits()))
} else {
assert!(bois.into_iter().map(|b| b.weight)
.zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
.all(|(a, b)| a.to_bits() == b.to_bits()))
}Trait Implementations§
source§impl AddAssign<Degree> for Gradian
impl AddAssign<Degree> for Gradian
source§fn add_assign(&mut self, rhs: Degree)
fn add_assign(&mut self, rhs: Degree)
+= operation. Read moresource§impl AddAssign<Degree> for Radian
impl AddAssign<Degree> for Radian
source§fn add_assign(&mut self, rhs: Degree)
fn add_assign(&mut self, rhs: Degree)
+= operation. Read moresource§impl AddAssign<Degree> for Unit
impl AddAssign<Degree> for Unit
source§fn add_assign(&mut self, rhs: Degree)
fn add_assign(&mut self, rhs: Degree)
+= operation. Read moresource§impl AddAssign<Gradian> for Degree
impl AddAssign<Gradian> for Degree
source§fn add_assign(&mut self, rhs: Gradian)
fn add_assign(&mut self, rhs: Gradian)
+= operation. Read moresource§impl AddAssign<Radian> for Degree
impl AddAssign<Radian> for Degree
source§fn add_assign(&mut self, rhs: Radian)
fn add_assign(&mut self, rhs: Radian)
+= operation. Read moresource§impl AddAssign<Unit> for Degree
impl AddAssign<Unit> for Degree
source§fn add_assign(&mut self, rhs: Unit)
fn add_assign(&mut self, rhs: Unit)
+= operation. Read moresource§impl AddAssign for Degree
impl AddAssign for Degree
source§fn add_assign(&mut self, rhs: Degree)
fn add_assign(&mut self, rhs: Degree)
+= operation. Read moresource§impl DivAssign for Degree
impl DivAssign for Degree
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moresource§impl MulAssign for Degree
impl MulAssign for Degree
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moresource§impl PartialOrd<Degree> for Gradian
impl PartialOrd<Degree> for Gradian
source§impl PartialOrd<Degree> for Radian
impl PartialOrd<Degree> for Radian
source§impl PartialOrd<Degree> for Unit
impl PartialOrd<Degree> for Unit
source§impl PartialOrd<Degree> for f32
impl PartialOrd<Degree> for f32
source§impl PartialOrd<Gradian> for Degree
impl PartialOrd<Gradian> for Degree
source§impl PartialOrd<Radian> for Degree
impl PartialOrd<Radian> for Degree
source§impl PartialOrd<Unit> for Degree
impl PartialOrd<Unit> for Degree
source§impl PartialOrd<f32> for Degree
impl PartialOrd<f32> for Degree
source§impl PartialOrd for Degree
impl PartialOrd for Degree
source§impl RemAssign for Degree
impl RemAssign for Degree
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moresource§impl SubAssign<Degree> for Gradian
impl SubAssign<Degree> for Gradian
source§fn sub_assign(&mut self, rhs: Degree)
fn sub_assign(&mut self, rhs: Degree)
-= operation. Read moresource§impl SubAssign<Degree> for Radian
impl SubAssign<Degree> for Radian
source§fn sub_assign(&mut self, rhs: Degree)
fn sub_assign(&mut self, rhs: Degree)
-= operation. Read moresource§impl SubAssign<Degree> for Unit
impl SubAssign<Degree> for Unit
source§fn sub_assign(&mut self, rhs: Degree)
fn sub_assign(&mut self, rhs: Degree)
-= operation. Read moresource§impl SubAssign<Gradian> for Degree
impl SubAssign<Gradian> for Degree
source§fn sub_assign(&mut self, rhs: Gradian)
fn sub_assign(&mut self, rhs: Gradian)
-= operation. Read moresource§impl SubAssign<Radian> for Degree
impl SubAssign<Radian> for Degree
source§fn sub_assign(&mut self, rhs: Radian)
fn sub_assign(&mut self, rhs: Radian)
-= operation. Read moresource§impl SubAssign<Unit> for Degree
impl SubAssign<Unit> for Degree
source§fn sub_assign(&mut self, rhs: Unit)
fn sub_assign(&mut self, rhs: Unit)
-= operation. Read moresource§impl SubAssign for Degree
impl SubAssign for Degree
source§fn sub_assign(&mut self, rhs: Degree)
fn sub_assign(&mut self, rhs: Degree)
-= operation. Read moresource§impl Transparent for Degree
impl Transparent for Degree
impl Copy for Degree
Auto Trait Implementations§
impl Freeze for Degree
impl RefUnwindSafe for Degree
impl Send for Degree
impl Sync for Degree
impl Unpin for Degree
impl UnwindSafe for Degree
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)