Package s1 implements types and functions for working with geometry in S¹ (circular geometry).
See ../s2 for a more detailed overview.
const ( // NegativeChordAngle represents a chord angle smaller than the zero angle. // The only valid operations on a NegativeChordAngle are comparisons and // Angle conversions. NegativeChordAngle = ChordAngle(-1) // RightChordAngle represents a chord angle of 90 degrees (a "right angle"). RightChordAngle = ChordAngle(2) // StraightChordAngle represents a chord angle of 180 degrees (a "straight angle"). // This is the maximum finite chord angle. StraightChordAngle = ChordAngle(4) )
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, Degrees(3.1) is different from E6(3100000) or E7(310000000).
The following conversions between degrees and radians are exact:
Degree*180 == Radian*math.Pi Degree*(180/n) == Radian*(math.Pi/n) for n == 0..8
These identities hold when the arguments are scaled up or down by any power of 2. Some similar identities are also true, for example,
Degree*60 == Radian*(math.Pi/3)
But be aware that this type of identity does not hold in general. For example,
Degree*3 != Radian*(math.Pi/60)
Similarly, the conversion to radians means that (Angle(x)*Degree).Degrees() does not always equal x. For example,
(Angle(45*n)*Degree).Degrees() == 45*n for n == 0..8
(60*Degree).Degrees() != 60
When testing for equality, you should allow for numerical errors (floatApproxEq) or convert to discrete E5/E6/E7 values first.
InfAngle returns an angle larger than any finite angle.
Abs returns the absolute value of the angle.
Degrees returns the angle in degrees.
E5 returns the angle in hundred thousandths of degrees.
E6 returns the angle in millionths of degrees.
E7 returns the angle in ten millionths of degrees.
Normalized returns an equivalent angle in [0, 2π).
Radians returns the angle in radians.
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.
ChordAngleFromAngle returns a ChordAngle from the given Angle.
ChordAngleFromSquaredLength 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.
InfChordAngle returns a chord angle larger than any finite chord angle. The only valid operations on an InfChordAngle are comparisons and Angle conversions.
Add adds the other ChordAngle to this one and returns the resulting value. This method assumes the ChordAngles are not special.
Angle converts this ChordAngle to an Angle.
Cos returns the cosine of this chord angle. This method is more efficient than converting to Angle and performing the computation.
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:
a := ChordAngleFromPoints(x, y) a1 := a.Expanded(a.MaxPointError())
MaxAngleError returns the maximum error for a ChordAngle constructed as an Angle distance.
MaxPointError 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.
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.
Sub subtracts the other ChordAngle from this one and returns the resulting value. This method assumes the ChordAngles are not special.
Tan returns the tangent of this chord angle.
Interval represents a closed interval on a unit circle. Zero-length intervals (where Lo == Hi) represent single points. If Lo > Hi then the interval is "inverted". The point at (-1, 0) on the unit circle has two valid representations, [π,π] and [-π,-π]. We normalize the latter to the former in IntervalFromEndpoints. There are two special intervals that take advantage of that:
- the full interval, [-π,π], and - the empty interval, [π,-π].
Treat the exported fields as read-only.
EmptyInterval returns an empty interval.
FullInterval returns a full interval.
IntervalFromEndpoints constructs a new interval from endpoints. Both arguments must be in the range [-π,π]. This function allows inverted intervals to be created.
IntervalFromPointPair returns the minimal interval containing the two given points. Both arguments must be in [-π,π].
AddPoint returns the interval expanded by the minimum amount necessary such that it contains the given point "p" (an angle in the range [-Pi, Pi]).
Center returns the midpoint of the interval. It is undefined for full and empty intervals.
Contains returns true iff the interval contains p. Assumes p ∈ [-π,π].
ContainsInterval returns true iff the interval contains oi.
Expanded returns an interval that has been expanded on each side by margin. If margin is negative, then the function shrinks the interval on each side by margin instead. The resulting interval may be empty or full. Any expansion (positive or negative) of a full interval remains full, and any expansion of an empty interval remains empty.
InteriorContains returns true iff the interior of the interval contains p. Assumes p ∈ [-π,π].
InteriorContainsInterval returns true iff the interior of the interval contains oi.
InteriorIntersects returns true iff the interior of the interval contains any points in common with oi, including the latter's boundary.
Intersection returns the smallest interval that contains the intersection of the interval and oi.
Intersects returns true iff the interval contains any points in common with oi.
Invert returns the interval with endpoints swapped.
IsEmpty reports whether the interval is empty.
IsFull reports whether the interval is full.
IsInverted reports whether the interval is inverted; that is, whether Lo > Hi.
IsValid reports whether the interval is valid.
Length returns the length of the interval. The length of an empty interval is negative.
Union returns the smallest interval that contains both the interval and oi.
☞ The major differences from the C++ version are: - no unsigned E5/E6/E7 methods - no S2Point or S2LatLng constructors - no comparison or arithmetic operators
☞ The major differences from the C++ version are: - no validity checking on construction, etc. (not a bug?) - a few operations