Struct s2::s1::angle::Angle

source ·
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§

rad returns the angle in radians.

deg returns the angle in degrees.

inf returns an angle larger than any finite angle.

is_infinite reports whether this Angle is infinite.

abs returns the absolute value of the angle.

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

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more

returns a ChordAngle from the given Angle.

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

converts this ChordAngle to an Angle.

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

returns a ChordAngle from the given Angle.

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

converts this ChordAngle to an Angle.

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The resulting type after applying the * operator.
Performs the * operation. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.