#[repr(transparent)]pub struct Gradian(pub f32);Expand description
Representation of an angle in Gradians.
In trigonometry, the gradian is a unit of measurement of an angle, defined as one-hundredth of the right angle; in other words, 100 gradians is equal to 90 degrees.
This type is provided so that developers can provide nicer/round numbers in angular arithmetic, where desired.
Tuple Fields§
§0: f32Implementations§
source§impl Gradian
impl Gradian
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 const fn to_gradians(self) -> Gradian
pub const fn to_gradians(self) -> Gradian
Identity conversion.
This exists for symmetry with the other angle definitions.
§Example
Basic use:
assert_eq!(Gradian::ONE_REVOLUTION.to_degrees(), Gradian::ONE_REVOLUTION);sourcepub fn from_radians(other: Radian) -> Self
pub fn from_radians(other: Radian) -> Self
sourcepub fn from_degrees(other: Degree) -> Self
pub fn from_degrees(other: Degree) -> Self
Constructs a new Gradian object from an existing angle.
§Parameters
angle- the angle to construct from
§Example
Basic use:
let lhs = Gradian::from_degrees(Degree::ONE_REVOLUTION);
let rhs = Gradian::ONE_REVOLUTION;
// Degree => Gradian conversions are less exact (to ~5 decimal places with
// 32-bit IEEE floats)
assert!((lhs - rhs).abs() <= 0.0001);sourcepub const fn from_gradians(other: Gradian) -> Self
pub const fn from_gradians(other: Gradian) -> Self
source§impl Gradian
impl Gradian
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<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<Gradian> for Radian
impl AddAssign<Gradian> for Radian
source§fn add_assign(&mut self, rhs: Gradian)
fn add_assign(&mut self, rhs: Gradian)
+= 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 Gradian
impl AddAssign<Radian> for Gradian
source§fn add_assign(&mut self, rhs: Radian)
fn add_assign(&mut self, rhs: Radian)
+= 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 for Gradian
impl AddAssign for Gradian
source§fn add_assign(&mut self, rhs: Gradian)
fn add_assign(&mut self, rhs: Gradian)
+= operation. Read moresource§impl DivAssign for Gradian
impl DivAssign for Gradian
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moresource§impl MulAssign for Gradian
impl MulAssign for Gradian
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<Gradian> for Degree
impl PartialOrd<Gradian> for Degree
source§impl PartialOrd<Gradian> for Radian
impl PartialOrd<Gradian> for Radian
source§impl PartialOrd<Gradian> for Unit
impl PartialOrd<Gradian> for Unit
source§impl PartialOrd<Gradian> for f32
impl PartialOrd<Gradian> for f32
source§impl PartialOrd<Radian> for Gradian
impl PartialOrd<Radian> for Gradian
source§impl PartialOrd<Unit> for Gradian
impl PartialOrd<Unit> for Gradian
source§impl PartialOrd<f32> for Gradian
impl PartialOrd<f32> for Gradian
source§impl PartialOrd for Gradian
impl PartialOrd for Gradian
source§impl RemAssign for Gradian
impl RemAssign for Gradian
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<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<Gradian> for Radian
impl SubAssign<Gradian> for Radian
source§fn sub_assign(&mut self, rhs: Gradian)
fn sub_assign(&mut self, rhs: Gradian)
-= 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 Gradian
impl SubAssign<Radian> for Gradian
source§fn sub_assign(&mut self, rhs: Radian)
fn sub_assign(&mut self, rhs: Radian)
-= 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 for Gradian
impl SubAssign for Gradian
source§fn sub_assign(&mut self, rhs: Gradian)
fn sub_assign(&mut self, rhs: Gradian)
-= operation. Read moresource§impl Transparent for Gradian
impl Transparent for Gradian
impl Copy for Gradian
Auto Trait Implementations§
impl Freeze for Gradian
impl RefUnwindSafe for Gradian
impl Send for Gradian
impl Sync for Gradian
impl Unpin for Gradian
impl UnwindSafe for Gradian
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)