#[repr(transparent)]pub struct Unit(pub f32);Expand description
Representation of a unit-based Angle.
A unit is an angle where each revolution is exactly 1. This makes conversion
to and from other angular units simple; e.g. 1 Unit is 360 Degree
units which means conversion to Degree is just a simple multiplication.
Likewise, the inverse conversion is a simple division operation.
Tuple Fields§
§0: f32Implementations§
source§impl Unit
impl Unit
sourcepub fn to_radians(self) -> Radian
pub fn to_radians(self) -> Radian
sourcepub fn to_degrees(self) -> Degree
pub fn to_degrees(self) -> Degree
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 Unit
impl Unit
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 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 Unit
impl AddAssign<Gradian> for Unit
source§fn add_assign(&mut self, rhs: Gradian)
fn add_assign(&mut self, rhs: Gradian)
+= operation. Read moresource§impl AddAssign<Radian> for Unit
impl AddAssign<Radian> for Unit
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<Unit> for Gradian
impl AddAssign<Unit> for Gradian
source§fn add_assign(&mut self, rhs: Unit)
fn add_assign(&mut self, rhs: Unit)
+= operation. Read moresource§impl AddAssign<Unit> for Radian
impl AddAssign<Unit> for Radian
source§fn add_assign(&mut self, rhs: Unit)
fn add_assign(&mut self, rhs: Unit)
+= operation. Read moresource§impl AddAssign for Unit
impl AddAssign for Unit
source§fn add_assign(&mut self, rhs: Unit)
fn add_assign(&mut self, rhs: Unit)
+= operation. Read moresource§impl DivAssign for Unit
impl DivAssign for Unit
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moresource§impl MulAssign for Unit
impl MulAssign for Unit
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moresource§impl PartialOrd<Degree> for Unit
impl PartialOrd<Degree> for Unit
source§impl PartialOrd<Gradian> for Unit
impl PartialOrd<Gradian> for Unit
source§impl PartialOrd<Radian> for Unit
impl PartialOrd<Radian> for Unit
source§impl PartialOrd<Unit> for Degree
impl PartialOrd<Unit> for Degree
source§impl PartialOrd<Unit> for Gradian
impl PartialOrd<Unit> for Gradian
source§impl PartialOrd<Unit> for Radian
impl PartialOrd<Unit> for Radian
source§impl PartialOrd<Unit> for f32
impl PartialOrd<Unit> for f32
source§impl PartialOrd<f32> for Unit
impl PartialOrd<f32> for Unit
source§impl PartialOrd for Unit
impl PartialOrd for Unit
source§impl RemAssign for Unit
impl RemAssign for Unit
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= 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 Unit
impl SubAssign<Gradian> for Unit
source§fn sub_assign(&mut self, rhs: Gradian)
fn sub_assign(&mut self, rhs: Gradian)
-= operation. Read moresource§impl SubAssign<Radian> for Unit
impl SubAssign<Radian> for Unit
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<Unit> for Gradian
impl SubAssign<Unit> for Gradian
source§fn sub_assign(&mut self, rhs: Unit)
fn sub_assign(&mut self, rhs: Unit)
-= operation. Read moresource§impl SubAssign<Unit> for Radian
impl SubAssign<Unit> for Radian
source§fn sub_assign(&mut self, rhs: Unit)
fn sub_assign(&mut self, rhs: Unit)
-= operation. Read moresource§impl SubAssign for Unit
impl SubAssign for Unit
source§fn sub_assign(&mut self, rhs: Unit)
fn sub_assign(&mut self, rhs: Unit)
-= operation. Read moresource§impl Transparent for Unit
impl Transparent for Unit
impl Copy for Unit
Auto Trait Implementations§
impl Freeze for Unit
impl RefUnwindSafe for Unit
impl Send for Unit
impl Sync for Unit
impl Unpin for Unit
impl UnwindSafe for Unit
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)