S1Angle

Struct S1Angle 

Source
#[repr(C)]
pub struct S1Angle { pub radians: f64, }
Expand description

This class represents a one-dimensional angle (as opposed to a two-dimensional solid angle). It has methods for converting angles to or from radians, degrees, and the E5/E6/E7 representations (i.e. degrees multiplied by 1e5/1e6/1e7 and rounded to the nearest integer).

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, Degrees(3.1) is different from E6(3100000) or E7(310000000). However, the following properties are guaranteed for any integer “n”, provided that “n” is in the input range of both functions:

$$ Degrees(n) == E6(1000000 * n) $$ $$ Degrees(n) == E7(10000000 * n) $$ $$ E6(n) == E7(10 * n) $$

The corresponding properties are not true for E5, so if you use E5 then don’t test for exact equality when comparing to other formats such as Degrees or E7.

The following conversions between degrees and radians are exact:

$$ Degrees(180) == Radians(M_PI); $$ $$ Degrees(45 * k) == Radians(k * M_PI / 4) for k == 0..8 $$

These identities also hold when the arguments are scaled up or down by any power of 2. Some similar identities are also true, for example, Degrees(60) == Radians(M_PI / 3), but be aware that this type of identity does not hold in general. For example, Degrees(3) != Radians(M_PI / 60).

Similarly, the conversion to radians means that Angle::Degrees(x).degrees() does not always equal “x”. For example,

$$ S1Angle::Degrees(45 * k).degrees() == 45 * k for k == 0..8 $$ but $$ S1Angle::Degrees(60).degrees() != 60. $$

This means that when testing for equality, you should allow for numerical errors (EXPECT_DOUBLE_EQ) or convert to discrete E5/E6/E7 values first.

CAVEAT: All of the above properties depend on “double” being the usual 64-bit IEEE 754 type (which is true on almost all modern platforms).

This class is intended to be copied by value as desired. It uses the default copy constructor and assignment operator.

§Usage

Methods that are available:

Fields§

§radians: f64

Angle in radians

Implementations§

Source§

impl S1Angle

Source

pub fn new(radians: f64) -> Self

Creates an S1Angle from a value in radians.

Source

pub fn infinity() -> Self

Creates an S1Angle with an infinite value.

Source

pub fn from_degrees(degrees: f64) -> Self

Creates an S1Angle from a value in degrees, converting it to radians.

Source

pub fn to_degrees(&self) -> f64

Returns the angle in degrees.

Source

pub fn to_e5(e5_: f64) -> Self

build an angle in E5 format.

Source

pub fn to_e6(e6_: f64) -> Self

build an angle in E6 format.

Source

pub fn to_e7(e7_: f64) -> Self

build an angle in E7 format.

Source

pub fn from_s2points(a: &S2Point, b: &S2Point) -> Self

Return the angle between two points, which is also equal to the distance between these points on the unit sphere. The points do not need to be normalized. This function has a maximum error of 3.25 * DBL_EPSILON (or 2.5 * DBL_EPSILON for angles up to 1 radian). If either point is zero-length (e.g. an uninitialized S2Point), or almost zero-length, the resulting angle will be zero.

Source

pub fn from_lon_lat<M1: MValueCompatible, M2: MValueCompatible>( a: &LonLat<M1>, b: &LonLat<M2>, ) -> Self

Like the constructor above, but return the angle (i.e., distance) between two S2LatLng points. This function has about 15 digits of accuracy for small distances but only about 8 digits of accuracy as the distance approaches 180 degrees (i.e., nearly-antipodal points).

Source

pub fn to_meters(&self, radius: Option<f64>) -> f64

Convert an angle in radians to an angle in meters If no radius is specified, the Earth’s radius is used.

Source

pub fn from_meters(angle: f64, radius: Option<f64>) -> Self

Convert an angle in meters to an angle in radians If no radius is specified, the Earth’s radius is used.

Source

pub fn to_km(&self, radius: Option<f64>) -> f64

Convert an angle in radians to an angle in kilometers If no radius is specified, the Earth’s radius is used.

Source

pub fn from_km(angle: f64, radius: Option<f64>) -> Self

Convert an angle in kilometers to an angle in radians If no radius is specified, the Earth’s radius is used.

Source

pub fn e5(&self) -> f64

Build an angle in E5 format.

Source

pub fn e6(&self) -> f64

Build an angle in E6 format.

Source

pub fn e7(&self) -> f64

Build an angle in E7 format.

Source

pub fn normalize(&self) -> Self

Normalize this angle to the range (-180, 180] degrees.

Source

pub fn modulo(&self, modulus: f64) -> Self

Returns the remainder when dividing by modulus

Methods from Deref<Target = f64>§

1.43.0

pub const RADIX: u32 = 2u32

1.43.0

pub const MANTISSA_DIGITS: u32 = 53u32

1.43.0

pub const DIGITS: u32 = 15u32

1.43.0

pub const EPSILON: f64 = 2.2204460492503131E-16f64

1.43.0

pub const MIN: f64 = -1.7976931348623157E+308f64

1.43.0

pub const MIN_POSITIVE: f64 = 2.2250738585072014E-308f64

1.43.0

pub const MAX: f64 = 1.7976931348623157E+308f64

1.43.0

pub const MIN_EXP: i32 = -1_021i32

1.43.0

pub const MAX_EXP: i32 = 1_024i32

1.43.0

pub const MIN_10_EXP: i32 = -307i32

1.43.0

pub const MAX_10_EXP: i32 = 308i32

1.43.0

pub const NAN: f64 = NaN_f64

1.43.0

pub const INFINITY: f64 = +Inf_f64

1.43.0

pub const NEG_INFINITY: f64 = -Inf_f64

1.62.0

pub fn total_cmp(&self, other: &f64) -> 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 f64. 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: f64,
}

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: f64::INFINITY },
    GoodBoy { name: "Abs. Unit".to_owned(), weight: f64::NAN },
    GoodBoy { name: "Floaty".to_owned(), weight: -5.0 },
];

bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));

// `f64::NAN` could be positive or negative, which will affect the sort order.
if f64::NAN.is_sign_negative() {
    assert!(bois.into_iter().map(|b| b.weight)
        .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::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, f64::INFINITY, f64::NAN].iter())
        .all(|(a, b)| a.to_bits() == b.to_bits()))
}

Trait Implementations§

Source§

impl Add<f64> for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for S1Angle

Source§

fn clone(&self) -> S1Angle

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for S1Angle

Source§

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

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

impl Default for S1Angle

Source§

fn default() -> S1Angle

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

impl Deref for S1Angle

Source§

type Target = f64

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Div<f64> for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl From<S1Angle> for S1ChordAngle

Source§

fn from(angle: S1Angle) -> S1ChordAngle

Converts to this type from the input type.
Source§

impl From<S1ChordAngle> for S1Angle

Source§

fn from(c_angle: S1ChordAngle) -> S1Angle

Converts to this type from the input type.
Source§

impl From<f64> for S1Angle

Source§

fn from(radians: f64) -> S1Angle

Converts to this type from the input type.
Source§

impl Mul<f64> for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for S1Angle

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<f64> for S1Angle

Source§

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

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

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 PartialEq for S1Angle

Source§

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

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

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<f64> for S1Angle

Source§

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

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

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

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

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§

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

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

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 PartialOrd for S1Angle

Source§

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

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

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

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

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§

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

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

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 Rem<f64> for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the % operator.
Source§

fn rem(self, modulus: f64) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign<f64> for S1Angle

Source§

fn rem_assign(&mut self, modulus: f64)

Performs the %= operation. Read more
Source§

impl Sub<f64> for S1Angle

Source§

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

Subtracts a value from the radians of the chord angle.

Source§

type Output = S1Angle

The resulting type after applying the - operator.
Source§

impl Sub for S1Angle

Source§

type Output = S1Angle

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for S1Angle

Source§

impl Eq for S1Angle

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,