#[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:
S1Angle::new: Create an angleS1Angle::infinity: Return an angle representing infinityS1Angle::from_degrees: Convert an angle in degrees to an angle in radiansS1Angle::to_degrees: Convert an angle in radians to an angle in degreesS1Angle::to_e5: Convert an angle in radians to an angle in degreesS1Angle::to_e6: Convert an angle in radians to an angle in degreesS1Angle::to_e7: Convert an angle in radians to an angle in degreesS1Angle::from_s2points: Convert two S2Point points to an angleS1Angle::from_lon_lat: Convert two S2LatLng points to an angleS1Angle::to_meters: Convert an angle in radians to an angle in metersS1Angle::from_meters: Convert an angle in meters to an angle in radiansS1Angle::to_km: Convert an angle in radians to an angle in kilometersS1Angle::from_km: Convert an angle in kilometers to an angle in radiansS1Angle::e5: Build an angle in E5 format.S1Angle::e6: Build an angle in E6 format.S1Angle::e7: Build an angle in E7 format.S1Angle::normalize: Normalize this angle to the range (-180, 180] degrees.S1Angle::modulo: Returns the remainder when dividing bymodulus
Fields§
§radians: f64Angle in radians
Implementations§
Source§impl S1Angle
impl S1Angle
Sourcepub fn from_degrees(degrees: f64) -> Self
pub fn from_degrees(degrees: f64) -> Self
Creates an S1Angle from a value in degrees, converting it to radians.
Sourcepub fn to_degrees(&self) -> f64
pub fn to_degrees(&self) -> f64
Returns the angle in degrees.
Sourcepub fn from_s2points(a: &S2Point, b: &S2Point) -> Self
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.
Sourcepub fn from_lon_lat<M1: MValueCompatible, M2: MValueCompatible>(
a: &LonLat<M1>,
b: &LonLat<M2>,
) -> Self
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).
Sourcepub fn to_meters(&self, radius: Option<f64>) -> f64
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.
Sourcepub fn from_meters(angle: f64, radius: Option<f64>) -> Self
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.
Sourcepub fn to_km(&self, radius: Option<f64>) -> f64
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.
Methods from Deref<Target = f64>§
pub const RADIX: u32 = 2u32
pub const MANTISSA_DIGITS: u32 = 53u32
pub const DIGITS: u32 = 15u32
pub const EPSILON: f64 = 2.2204460492503131E-16f64
pub const MIN: f64 = -1.7976931348623157E+308f64
pub const MIN_POSITIVE: f64 = 2.2250738585072014E-308f64
pub const MAX: f64 = 1.7976931348623157E+308f64
pub const MIN_EXP: i32 = -1_021i32
pub const MAX_EXP: i32 = 1_024i32
pub const MIN_10_EXP: i32 = -307i32
pub const MAX_10_EXP: i32 = 308i32
pub const NAN: f64 = NaN_f64
pub const INFINITY: f64 = +Inf_f64
pub const NEG_INFINITY: f64 = -Inf_f64
1.62.0pub fn total_cmp(&self, other: &f64) -> Ordering
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 From<S1Angle> for S1ChordAngle
impl From<S1Angle> for S1ChordAngle
Source§fn from(angle: S1Angle) -> S1ChordAngle
fn from(angle: S1Angle) -> S1ChordAngle
Source§impl From<S1ChordAngle> for S1Angle
impl From<S1ChordAngle> for S1Angle
Source§fn from(c_angle: S1ChordAngle) -> S1Angle
fn from(c_angle: S1ChordAngle) -> S1Angle
Source§impl Ord for S1Angle
impl Ord for S1Angle
Source§impl PartialOrd<f64> for S1Angle
impl PartialOrd<f64> for S1Angle
Source§impl PartialOrd for S1Angle
impl PartialOrd for S1Angle
Source§impl RemAssign<f64> for S1Angle
impl RemAssign<f64> for S1Angle
Source§fn rem_assign(&mut self, modulus: f64)
fn rem_assign(&mut self, modulus: f64)
%= operation. Read moreimpl Copy for S1Angle
impl Eq for S1Angle
Auto Trait Implementations§
impl Freeze for S1Angle
impl RefUnwindSafe for S1Angle
impl Send for S1Angle
impl Sync for S1Angle
impl Unpin for S1Angle
impl UnwindSafe for S1Angle
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().