Package com.google.common.geometry
Class S2ShapeIndexMeasures
- java.lang.Object
-
- com.google.common.geometry.S2ShapeIndexMeasures
-
@GwtCompatible public final class S2ShapeIndexMeasures extends java.lang.Object
Defines various angle and area measures forS2ShapeIndex
objects. In general, these methods return the sum of the corresponding measure for allS2Shape
in the index.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
S2ShapeIndexMeasures()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
area(S2ShapeIndex shapeIndex)
Returns the total area of all polygons in shapeIndex.static S2Point
centroid(S2ShapeIndex shapeIndex)
Returns the centroid of all shapes whose dimension is maximal within shapeIndex, multiplied by the measure of those shapes.static int
dimension(S2ShapeIndex shapeIndex)
Returns the maximum dimension of any shape in shapeIndex, or -1 if shapeIndex has no shapes.static S1Angle
length(S2ShapeIndex shapeIndex)
Returns the total length of all polylines in shapeIndex, orS1Angle.ZERO
if shapeIndex contains no polylines.static S1Angle
perimeter(S2ShapeIndex shapeIndex)
Returns the total perimeter of all polygons in shapeIndex (including both "shells" and "holes"), orS1Angle.ZERO
shapeIndex contains no polygons.
-
-
-
Method Detail
-
dimension
public static int dimension(S2ShapeIndex shapeIndex)
Returns the maximum dimension of any shape in shapeIndex, or -1 if shapeIndex has no shapes.The dimension does not depend on whether the shapes in shapeIndex contain any points. For example, the dimension of an empty point set is 0, and the dimension of an empty polygon is 2.
-
length
public static S1Angle length(S2ShapeIndex shapeIndex)
Returns the total length of all polylines in shapeIndex, orS1Angle.ZERO
if shapeIndex contains no polylines.
-
perimeter
public static S1Angle perimeter(S2ShapeIndex shapeIndex)
Returns the total perimeter of all polygons in shapeIndex (including both "shells" and "holes"), orS1Angle.ZERO
shapeIndex contains no polygons.
-
area
public static double area(S2ShapeIndex shapeIndex)
Returns the total area of all polygons in shapeIndex. Returns 0 if no polygons are present. This method has good relative accuracy for both very large and very small regions. Note that the result may exceed 4*Pi if shapeIndex contains overlapping polygons.
-
centroid
public static S2Point centroid(S2ShapeIndex shapeIndex)
Returns the centroid of all shapes whose dimension is maximal within shapeIndex, multiplied by the measure of those shapes. For example, if shapeIndex contains points and polylines, then the result is defined as the centroid of the polylines multiplied by the total length of those polylines. The points would be ignored when computing the centroid.The measure of a given shape is defined as follows:
- For dimension 0 shapes, the measure is
S2Shape.numEdges()
. - For dimension 1 shapes, the measure is
length(S2ShapeIndex)
. - For dimension 2 shapes, the measure is
area(S2ShapeIndex)
.
The returned centroid is not unit length, so
S2Point.normalize()
may need to be called before passing it to other S2 functions. (0, 0, 0) is returned if the index contains no geometry.The centroid is scaled by the total measure of the shapes for two reasons:
- It is cheaper to compute this way.
- This makes it easier to compute the centroid of a collection of shapes (since the individual centroids can simply be summed)
- For dimension 0 shapes, the measure is
-
-