Struct Angle

Source
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§

Source§

impl Angle

Source

pub fn rad(&self) -> f64

rad returns the angle in radians.

Source

pub fn deg(&self) -> f64

deg returns the angle in degrees.

Source

pub fn inf() -> Self

inf returns an angle larger than any finite angle.

Source

pub fn is_infinite(&self) -> bool

is_infinite reports whether this Angle is infinite.

Source

pub fn abs(&self) -> Self

abs returns the absolute value of the angle.

Source

pub fn normalized(&self) -> Self

normalized returns an equivalent angle in [0, 2π).

Source

pub fn max(self, other: Angle) -> Self

Source

pub fn min(self, other: Angle) -> Self

Trait Implementations§

Source§

impl Add<Angle> for f64

Source§

type Output = Angle

The resulting type after applying the + operator.
Source§

fn add(self, other: Angle) -> Angle

Performs the + operation. Read more
Source§

impl Add<f64> for Angle

Source§

type Output = Angle

The resulting type after applying the + operator.
Source§

fn add(self, other: f64) -> Self

Performs the + operation. Read more
Source§

impl Add for Angle

Source§

type Output = Angle

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<Angle> for f64

Source§

fn add_assign(self: &mut f64, other: Angle)

Performs the += operation. Read more
Source§

impl AddAssign<f64> for Angle

Source§

fn add_assign(&mut self, other: f64)

Performs the += operation. Read more
Source§

impl AddAssign for Angle

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Angle

Source§

fn clone(&self) -> Angle

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Angle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Angle

Source§

fn default() -> Angle

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Angle

Source§

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 Div<Angle> for f64

Source§

type Output = Angle

The resulting type after applying the / operator.
Source§

fn div(self, other: Angle) -> Angle

Performs the / operation. Read more
Source§

impl Div<f64> for Angle

Source§

type Output = Angle

The resulting type after applying the / operator.
Source§

fn div(self, other: f64) -> Self

Performs the / operation. Read more
Source§

impl Div for Angle

Source§

type Output = Angle

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
Source§

impl DivAssign<Angle> for f64

Source§

fn div_assign(self: &mut f64, other: Angle)

Performs the /= operation. Read more
Source§

impl DivAssign<f64> for Angle

Source§

fn div_assign(&mut self, other: f64)

Performs the /= operation. Read more
Source§

impl DivAssign for Angle

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl<'a> From<&'a Angle> for ChordAngle

Source§

fn from(a: &'a Angle) -> Self

returns a ChordAngle from the given Angle.

Source§

impl<'a> From<&'a Angle> for Deg

Source§

fn from(a: &Angle) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Angle> for E5

Source§

fn from(a: &Angle) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Angle> for E6

Source§

fn from(a: &Angle) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Angle> for E7

Source§

fn from(a: &Angle) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Angle> for Rad

Source§

fn from(a: &Angle) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a ChordAngle> for Angle

Source§

fn from(ca: &'a ChordAngle) -> Self

converts this ChordAngle to an Angle.

Source§

impl<'a> From<&'a Deg> for Angle

Source§

fn from(a: &Deg) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a E5> for Angle

Source§

fn from(a: &E5) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a E6> for Angle

Source§

fn from(a: &E6) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a E7> for Angle

Source§

fn from(a: &E7) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Rad> for Angle

Source§

fn from(a: &Rad) -> Self

Converts to this type from the input type.
Source§

impl From<Angle> for ChordAngle

Source§

fn from(a: Angle) -> Self

returns a ChordAngle from the given Angle.

Source§

impl From<Angle> for Deg

Source§

fn from(a: Angle) -> Self

Converts to this type from the input type.
Source§

impl From<Angle> for E5

Source§

fn from(a: Angle) -> Self

Converts to this type from the input type.
Source§

impl From<Angle> for E6

Source§

fn from(a: Angle) -> Self

Converts to this type from the input type.
Source§

impl From<Angle> for E7

Source§

fn from(a: Angle) -> Self

Converts to this type from the input type.
Source§

impl From<Angle> for Rad

Source§

fn from(a: Angle) -> Self

Converts to this type from the input type.
Source§

impl From<ChordAngle> for Angle

Source§

fn from(ca: ChordAngle) -> Self

converts this ChordAngle to an Angle.

Source§

impl From<Deg> for Angle

Source§

fn from(a: Deg) -> Self

Converts to this type from the input type.
Source§

impl From<E5> for Angle

Source§

fn from(a: E5) -> Self

Converts to this type from the input type.
Source§

impl From<E6> for Angle

Source§

fn from(a: E6) -> Self

Converts to this type from the input type.
Source§

impl From<E7> for Angle

Source§

fn from(a: E7) -> Self

Converts to this type from the input type.
Source§

impl From<Rad> for Angle

Source§

fn from(a: Rad) -> Self

Converts to this type from the input type.
Source§

impl Mul<Angle> for f64

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

fn mul(self, other: Angle) -> Angle

Performs the * operation. Read more
Source§

impl Mul<f64> for Angle

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

fn mul(self, other: f64) -> Self

Performs the * operation. Read more
Source§

impl Mul for Angle

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<Angle> for f64

Source§

fn mul_assign(self: &mut f64, other: Angle)

Performs the *= operation. Read more
Source§

impl MulAssign<f64> for Angle

Source§

fn mul_assign(&mut self, other: f64)

Performs the *= operation. Read more
Source§

impl MulAssign for Angle

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl Neg for Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Angle

Source§

fn eq(&self, other: &Angle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Angle

Source§

fn partial_cmp(&self, other: &Angle) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Angle

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<Angle> for f64

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn sub(self, other: Angle) -> Angle

Performs the - operation. Read more
Source§

impl Sub<f64> for Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn sub(self, other: f64) -> Self

Performs the - operation. Read more
Source§

impl Sub for Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign<Angle> for f64

Source§

fn sub_assign(self: &mut f64, other: Angle)

Performs the -= operation. Read more
Source§

impl SubAssign<f64> for Angle

Source§

fn sub_assign(&mut self, other: f64)

Performs the -= operation. Read more
Source§

impl SubAssign for Angle

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl Copy for Angle

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,