Struct S1Angle

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).

struct S1Angle ;

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.

Constructors

NameDescription
this (x, y) 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 * double.epsilon for angles up to 1 radian).
this (x, y) 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).

Methods

NameDescription
abs () Returns the absolute value of an angle.
fromRadians (radians) These methods construct S1Angle objects from their measure in radians or degrees.
normalize () Normalizes this angle to the range \(-180, 180] degrees.
normalized () Returns the angle normalized to the range \(-180, 180] degrees.
opEquals (y) Comparison operators.
opOpAssign (v) Simple arithmetic operators for manipulating S1Angles.
opUnary () Implement negation.
zero () A explicit shorthand for the default constructor.

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.