Class S2Polygon.Shape

  • All Implemented Interfaces:
    S2Shape, java.io.Serializable
    Enclosing class:
    S2Polygon

    public abstract class S2Polygon.Shape
    extends java.lang.Object
    implements S2Shape, java.io.Serializable
    Wrapper class for indexing a polygon via S2ShapeIndex. This class has several subtypes to store additional data based on the kind of polygon being indexed.

    Note that unlike S2Polygon, the edges of this shape are directed such that the polygon interior is always on the left.

    See Also:
    Serialized Form
    • Constructor Detail

      • Shape

        public Shape()
    • Method Detail

      • numEdges

        public int numEdges()
        Description copied from interface: S2Shape
        Returns the number of edges in this shape.
        Specified by:
        numEdges in interface S2Shape
      • hasInterior

        public boolean hasInterior()
        Description copied from interface: S2Shape
        Returns true if this shape has an interior, i.e. the shape consists of one or more closed non-intersecting loops.
        Specified by:
        hasInterior in interface S2Shape
      • containsOrigin

        public boolean containsOrigin()
        Description copied from interface: S2Shape
        Returns true if this shape contains S2.origin(). Should return false for shapes that do not have an interior.
        Specified by:
        containsOrigin in interface S2Shape
      • numChains

        public int numChains()
        Description copied from interface: S2Shape
        Returns the number of contiguous edge chains in the shape. For example, a shape whose edges are [AB, BC, CD, AE, EF] may consist of two chains [A, B, C, D] and [A, E, F]. Every chain is assigned a chain id numbered sequentially starting from zero.

        An empty shape has no chains. A full shape (which contains the entire globe) has one chain with no edges. Other shapes should have at least one chain, and the sum of all valid chain lengths should equal S2Shape.numEdges() (that is, edges may only be used by a single chain).

        Note that it is always acceptable to implement this method by returning S2Shape.numEdges() (i.e. every chain consists of a single edge), but this may reduce the efficiency of some algorithms.

        Specified by:
        numChains in interface S2Shape
      • getChainLength

        public int getChainLength​(int chainId)
        Description copied from interface: S2Shape
        Returns the number of edge ids corresponding to the edge chain for the given chain id. The edge chains must form contiguous, non-overlapping ranges that cover the entire range of edge ids.
        Specified by:
        getChainLength in interface S2Shape
        Parameters:
        chainId - which edge chain to return its length, from 0 to S2Shape.numChains() - 1
      • getChainEdge

        public void getChainEdge​(int chainId,
                                 int offset,
                                 S2Shape.MutableEdge result)
        Description copied from interface: S2Shape
        Returns the edge for the given chain id and offset in result. Must not return zero-length edges.
        Specified by:
        getChainEdge in interface S2Shape
        Parameters:
        chainId - which chain contains the edge to return, from 0 to S2Shape.numChains() - 1
        offset - position from chain start for the edge to return, from 0 to S2Shape.getChainLength(int) - 1
      • dimension

        public int dimension()
        Description copied from interface: S2Shape
        Returns the dimension of the geometry represented by this shape.
        • 0 - Point geometry. Each point is represented as a degenerate edge.
        • 1 - Polyline geometry. Polyline edges may be degenerate. A shape may represent any number of polylines. Polylines edges may intersect.
        • 2 - Polygon geometry. Edges should be oriented such that the polygon interior is always on the left. In theory the edges may be returned in any order, but typically the edges are organized as a collection of edge chains where each chain represents one polygon loop. Polygons may have degeneracies, e.g., degenerate edges or sibling pairs consisting of an edge and its corresponding reversed edge. A polygon loop may also be full (containing all points on the sphere); by convention this is represented as a chain with no edges.

        Note that this method allows degenerate geometry of different dimensions to be distinguished, e.g., it allows a point to be distinguished from a polyline or polygon that has been simplified to a single point.

        Specified by:
        dimension in interface S2Shape