Struct s2::s1::chordangle::ChordAngle

source ·
pub struct ChordAngle(pub f64);
Expand description

ChordAngle represents the angle subtended by a chord (i.e., the straight line segment connecting two points on the sphere). Its representation makes it very efficient for computing and comparing distances, but unlike Angle it is only capable of representing angles between 0 and π radians. Generally, ChordAngle should only be used in loops where many angles need to be calculated and compared. Otherwise it is simpler to use Angle.

ChordAngle loses some accuracy as the angle approaches π radians. Specifically, the representation of (π - x) radians has an error of about (1e-15 / x), with a maximum error of about 2e-8 radians (about 13cm on the Earth’s surface). For comparison, for angles up to π/2 radians (10000km) the worst-case representation error is about 2e-16 radians (1 nanonmeter), which is about the same as Angle.

ChordAngles are represented by the squared chord length, which can range from 0 to 4. Positive infinity represents an infinite squared length.

Tuple Fields§

§0: f64

Implementations§

inf returns a chord angle larger than any finite chord angle. The only valid operations on an InfChordAngle are comparisons and Angle conversions.

is_infinite reports whether this ChordAngle is infinite.

from_squared_length returns a ChordAngle from the squared chord length. Note that the argument is automatically clamped to a maximum of 4.0 to handle possible roundoff errors. The argument must be non-negative.

expanded returns a new ChordAngle that has been adjusted by the given error bound (which can be positive or negative). Error should be the value returned by either MaxPointError or MaxAngleError. For example: let a = ChordAngle::from_points(x, y) let a1 = a.expanded(a.max_point_error())

is_special reports whether this ChordAngle is one of the special cases.

is_valid reports whether this ChordAngle is valid or not.

max_point_error returns the maximum error size for a ChordAngle constructed from 2 Points x and y, assuming that x and y are normalized to within the bounds guaranteed by s2.Point.Normalize. The error is defined with respect to the true distance after the points are projected to lie exactly on the sphere.

max_angle_error returns the maximum error for a ChordAngle constructed as an Angle distance.

sin returns the sine of this chord angle. This method is more efficient than converting to Angle and performing the computation.

sin2 returns the square of the sine of this chord angle. It is more efficient than Sin.

cos returns the cosine of this chord angle. This method is more efficient than converting to Angle and performing the computation.

tan returns the tangent of this chord angle.

Trait Implementations§

add adds the other ChordAngle to this one and returns the resulting value. This method assumes the ChordAngles are not special.

The resulting type after applying the + operator.
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 this ChordAngle to an Angle.

Converts to this type from the input type.

returns a ChordAngle from the given Angle.

converts this ChordAngle to an Angle.

Converts to this type from the input type.
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

sub subtracts the other ChordAngle from this one and returns the resulting value. This method assumes the ChordAngles are not special.

The resulting type after applying the - operator.

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.