pub struct Angle(/* private fields */);
Expand description
Angle represents a 1D angle. The internal representation is a double precision value in radians, so conversion to and from radians is exact. Conversions between E5, E6, E7, and Degrees are not always exact. For example, Deg(3.1) is different from E6(3100000) or E7(310000000).
use s2::s1::angle::*;
use std::f64::consts::PI;
// The following conversions between degrees and radians are exact:
assert_eq!(Deg(180.), Deg::from(Rad(PI)));
for n in 0..9 {
// for n == 0..8
assert_eq!(Rad(PI/(n as f64)), Deg(180./(n as f64)).into());
}
// These identities hold when the arguments are scaled up or down by any power
// of 2. Some similar identities are also true, for example,
assert_eq!(Rad(PI/3.), Deg(60.).into());
// But be aware that this type of identity does not hold in general. For example,
assert_ne!(Rad(PI/60.), Deg(3.).into());
// Similarly, the conversion to radians means that Deg::from(Angle::from(Deg(x)))
// does not always equal x. For example,
// for n == 0..8
for n in 0..9 {
let x = 45. * (n as f64);
assert_eq!(Deg(x), Deg::from(Angle::from(Deg(x))));
}
// but
assert_ne!(Deg(60.), Deg::from(Angle::from(Deg(60.))));
When testing for equality, you should allow for numerical errors (float64Eq) or convert to discrete E5/E6/E7 values first.
Implementations§
Trait Implementations§
Source§impl AddAssign<f64> for Angle
impl AddAssign<f64> for Angle
Source§fn add_assign(&mut self, other: f64)
fn add_assign(&mut self, other: f64)
Performs the
+=
operation. Read moreSource§impl AddAssign for Angle
impl AddAssign for Angle
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+=
operation. Read moreSource§impl<'de> Deserialize<'de> for Angle
impl<'de> Deserialize<'de> for Angle
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl DivAssign<f64> for Angle
impl DivAssign<f64> for Angle
Source§fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
Performs the
/=
operation. Read moreSource§impl DivAssign for Angle
impl DivAssign for Angle
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the
/=
operation. Read moreSource§impl<'a> From<&'a Angle> for ChordAngle
impl<'a> From<&'a Angle> for ChordAngle
Source§impl<'a> From<&'a ChordAngle> for Angle
impl<'a> From<&'a ChordAngle> for Angle
Source§fn from(ca: &'a ChordAngle) -> Self
fn from(ca: &'a ChordAngle) -> Self
converts this ChordAngle to an Angle.
Source§impl From<Angle> for ChordAngle
impl From<Angle> for ChordAngle
Source§impl From<ChordAngle> for Angle
impl From<ChordAngle> for Angle
Source§fn from(ca: ChordAngle) -> Self
fn from(ca: ChordAngle) -> Self
converts this ChordAngle to an Angle.
Source§impl MulAssign<f64> for Angle
impl MulAssign<f64> for Angle
Source§fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
Performs the
*=
operation. Read moreSource§impl MulAssign for Angle
impl MulAssign for Angle
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the
*=
operation. Read moreSource§impl PartialOrd for Angle
impl PartialOrd for Angle
Source§impl SubAssign<f64> for Angle
impl SubAssign<f64> for Angle
Source§fn sub_assign(&mut self, other: f64)
fn sub_assign(&mut self, other: f64)
Performs the
-=
operation. Read moreSource§impl SubAssign for Angle
impl SubAssign for Angle
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-=
operation. Read moreimpl Copy for Angle
impl StructuralPartialEq for Angle
Auto Trait Implementations§
impl Freeze for Angle
impl RefUnwindSafe for Angle
impl Send for Angle
impl Sync for Angle
impl Unpin for Angle
impl UnwindSafe for Angle
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
Mutably borrows from an owned value. Read more