Package com.google.common.geometry
Class S2ShapeMeasures
java.lang.Object
com.google.common.geometry.S2ShapeMeasures
Defines various angle and area measures for
S2Shape
objects. Unlike the built-in S2Polygon
and S2Polyline
methods, these methods allow the underlying data to be
represented arbitrarily.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interface
A consumer which accepts two arguments.private static interface
A function which accepts an int.(package private) static class
Represents a cyclic ordering of the loop vertices, starting at the index "first" and proceeding in direction "dir" (either +1 or -1).private static class
private static class
Wraps a mutable primitive double. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
For shapes of dimension 2, returns the area of the shape on the unit sphere.(package private) static S2ShapeMeasures.LoopOrder
canonicalLoopOrder
(List<S2Point> loop) Returns an index "first" and a direction "dir" such that the vertex sequence (first, first + dir, ..., first + (n - 1) * dir) does not change when the loop vertex order is rotated or reversed.static S2Point
Returns the centroid of shape multiplied by the measure of shape.private static void
forEachChainEdge
(S2Shape shape, int chainId, S2ShapeMeasures.BiConsumer<S2Point, S2Point> edgeConsumer) Passes each edge (a, b) in the chain of shape at index chainId to edgeConsumer.static S1Angle
Returns the sum of all polyline lengths on the unit sphere for shapes of dimension 1, orS1Angle.ZERO
otherwise.(package private) static double
Returns the area of the loop interior, i.e.(package private) static double
Same asloopArea(S2Shape, int)
, but takes a loop as a list of vertices.(package private) static S2Point
loopCentroid
(S2Shape shape, int chainId) Returns the true centroid of the loop multiplied by the area of the loop.(package private) static S1Angle
loopPerimeter
(S2Shape shape, int chainId) Returns the perimeter of the loop, orS1Angle.ZERO
if the loop has 0 or 1 vertices.static S1Angle
Returns the sum of all loop perimeters on the unit sphere for shapes of dimension 2, orS1Angle.ZERO
otherwise.(package private) static S2Point
polylineCentroid
(S2Shape shape, int chainId) Returns the true centroid of the polyline multiplied by the length of the polyline.(package private) static S1Angle
polylineLength
(S2Shape shape, int chainId) Returns the length of the polyline, orS1Angle.ZERO
if the polyline has fewer than two vertices.pruneDegeneracies
(List<S2Point> input) Returns a new loop obtained by removing all degeneracies from "input".private static double
signedLoopArea
(S2Shape shape, int chainId) Returns the area of the loop interior, i.e.private static double
signedLoopArea
(List<S2Point> loop) Same assignedLoopArea(S2Shape, int)
, but takes a loop as a list of vertices.(package private) static double
turningAngle
(S2Shape shape, int chainId) (package private) static double
turningAngle
(List<S2Point> loop) Returns the geodesic curvature of the loop, defined as the sum of the turn angles at each vertex (seeS2.turnAngle(S2Point, S2Point, S2Point)
).
-
Constructor Details
-
S2ShapeMeasures
private S2ShapeMeasures()
-
-
Method Details
-
length
Returns the sum of all polyline lengths on the unit sphere for shapes of dimension 1, orS1Angle.ZERO
otherwise. Seeperimeter(S2Shape)
for shapes of dimension 2.See
S2ShapeIndexMeasures.length(S2ShapeIndex)
for more info. -
polylineLength
Returns the length of the polyline, orS1Angle.ZERO
if the polyline has fewer than two vertices. -
perimeter
Returns the sum of all loop perimeters on the unit sphere for shapes of dimension 2, orS1Angle.ZERO
otherwise. Seelength(S2Shape)
for shapes of dimension 1. -
loopPerimeter
Returns the perimeter of the loop, orS1Angle.ZERO
if the loop has 0 or 1 vertices. -
area
For shapes of dimension 2, returns the area of the shape on the unit sphere. The result is between 0 and 4*Pi steradians. Otherwise returns zero. This method has good relative accuracy for both very large and very small regions. -
loopArea
Returns the area of the loop interior, i.e. the region on the left side of the loop. The result is between 0 and 4*Pi steradians. The implementation ensures that nearly-degenerate clockwise loops have areas close to zero, while nearly-degenerate counter-clockwise loops have areas close to 4*Pi. -
loopArea
Same asloopArea(S2Shape, int)
, but takes a loop as a list of vertices. -
signedLoopArea
Returns the area of the loop interior, i.e. the region on the left side of the loop. The result is between 0 and 4*Pi steradians. The implementation ensures that nearly-degenerate clockwise loops have areas close to zero, while nearly-degenerate counter-clockwise loops have areas close to 4*Pi. -
signedLoopArea
Same assignedLoopArea(S2Shape, int)
, but takes a loop as a list of vertices. -
turningAngle
-
turningAngle
Returns the geodesic curvature of the loop, defined as the sum of the turn angles at each vertex (seeS2.turnAngle(S2Point, S2Point, S2Point)
). The result is positive if the loop is counter-clockwise, negative if the loop is clockwise, and zero if the loop is a great circle. The geodesic curvature is equal to 2*Pi minus the area of the loop.The following cases are handled specially:
- Degenerate loops (consisting of an isolated vertex or composed entirely of sibling edge pairs) have a curvature of 2*Pi exactly.
- The full loop (containing all points, and represented as a loop with no vertices) has a curvature of -2*Pi exactly.
- All other loops have a non-zero curvature in the range (-2*Pi, 2*Pi). For any such loop, reversing the order of the vertices is guaranteed to negate the curvature. This property can be used to define a unique normalized orientation for every loop.
-
canonicalLoopOrder
Returns an index "first" and a direction "dir" such that the vertex sequence (first, first + dir, ..., first + (n - 1) * dir) does not change when the loop vertex order is rotated or reversed. This allows the loop vertices to be traversed in a canonical order. -
pruneDegeneracies
Returns a new loop obtained by removing all degeneracies from "input". In particular, the result will not contain any adjacent duplicate vertices or sibling edge pairs, i.e. vertex sequences of the form (A, A) or (A, B, A). -
centroid
Returns the centroid of shape multiplied by the measure of shape.See
S2ShapeIndexMeasures.centroid(S2ShapeIndex)
for more info. -
polylineCentroid
Returns the true centroid of the polyline multiplied by the length of the polyline.Scaling by the polyline length makes it easy to compute the centroid of several polylines (by simply adding up their centroids).
CAVEAT: Returns
S2Point.ORIGIN
for degenerate polylines (e.g., AA). [Note that this answer is correct; the result of this function is a line integral over the polyline, whose value is always zero if the polyline is degenerate]. -
loopCentroid
Returns the true centroid of the loop multiplied by the area of the loop.See
S2ShapeIndexMeasures.centroid(S2ShapeIndex)
for more info. -
vertices
-
forEachChainEdge
private static void forEachChainEdge(S2Shape shape, int chainId, S2ShapeMeasures.BiConsumer<S2Point, S2Point> edgeConsumer) Passes each edge (a, b) in the chain of shape at index chainId to edgeConsumer.
-