pub struct Angle(_);
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<'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<'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 PartialEq<Angle> for Angle
impl PartialEq<Angle> for Angle
source§impl PartialOrd<Angle> for Angle
impl PartialOrd<Angle> for Angle
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more