Class S2ShapeIndexMeasures

java.lang.Object
com.google.common.geometry.S2ShapeIndexMeasures

@GwtCompatible public final class S2ShapeIndexMeasures extends Object
Defines various angle and area measures for S2ShapeIndex objects. In general, these methods return the sum of the corresponding measure for all S2Shape in the index.
  • Constructor Details

    • S2ShapeIndexMeasures

      private S2ShapeIndexMeasures()
  • Method Details

    • 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, or S1Angle.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"), or S1Angle.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:

      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:

      1. It is cheaper to compute this way.
      2. This makes it easier to compute the centroid of a collection of shapes (since the individual centroids can simply be summed)