s2js
    Preparing search index...

    Class Polygon

    Polygon represents a sequence of zero or more loops; recall that the interior of a loop is defined to be its left-hand side (see Loop).

    When the polygon is initialized, the given loops are automatically converted into a canonical form consisting of "shells" and "holes". Shells and holes are both oriented CCW, and are nested hierarchically. The loops are reordered to correspond to a pre-order traversal of the nesting hierarchy.

    Polygons may represent any region of the sphere with a polygonal boundary, including the entire sphere (known as the "full" polygon). The full polygon consists of a single full loop (see Loop), whereas the empty polygon has no loops at all.

    Use FullPolygon() to construct a full polygon. The zero value of Polygon is treated as the empty polygon.

    Polygons have the following restrictions:

    • Loops may not cross, i.e. the boundary of a loop may not intersect both the interior and exterior of any other loop.

    • Loops may not share edges, i.e. if a loop contains an edge AB, then no other loop may contain AB or BA.

    • Loops may share vertices, however no vertex may appear twice in a single loop (see Loop).

    • No loop may be empty. The full loop may appear only in the full polygon.

    Implements

    Index

    Constructors

    • Constructs a polygon from the given set of loops. The polygon interior consists of the points contained by an odd number of loops. (Recall that a loop contains the set of points on its left-hand side.)

      This method determines the loop nesting hierarchy and assigns every loop a depth. Shells have even depths, and holes have odd depths.

      Note: The given set of loops are reordered by this method so that the hierarchy can be traversed using Parent, LastDescendant and the loops depths.

      Parameters

      Returns s2.Polygon

    • PolygonFromOrientedLoops returns a Polygon from the given set of loops, like PolygonFromLoops. It expects loops to be oriented such that the polygon interior is on the left-hand side of all loops. This implies that shells and holes should have opposite orientations in the input to this method. (During initialization, loops representing holes will automatically be inverted.)

      Parameters

      Returns s2.Polygon

    Other

    bound: s2.Rect = ...

    bound is a conservative bound on all points contained by this loop. If l.ContainsPoint(P), then l.bound.ContainsPoint(P).

    cumulativeEdges: number[] = []

    A slice where element i is the cumulative number of edges in the preceding loops in the polygon. This field is used for polygons that have a large number of loops, and may be empty for polygons with few loops.

    hasHoles: boolean = false

    hasHoles tracks if this polygon has at least one hole.

    index: ShapeIndex = ...

    index is a spatial index of all the polygon loops.

    loops: Loop[] = []
    nEdges: number = 0

    numEdges tracks the total number of edges in all the loops in this polygon.

    numVertices: number = 0

    numVertices keeps the running total of all of the vertices of the contained loops.

    subregionBound: s2.Rect = ...

    Since bound is not exact, it is possible that a loop A contains another loop B whose bounds are slightly larger. subregionBound has been expanded sufficiently to account for this error, i.e. if A.Contains(B), then A.subregionBound.Contains(B.bound).

    • Returns the area of the polygon interior, i.e. the region on the left side of an odd number of loops. The return value is between 0 and 4*Pi.

      Returns number

    • Reports whether the loop's boundary intersects cell. It may also return true when the loop boundary does not intersect cell but some edge comes within the worst-case error tolerance.

      This requires that it.Locate(cell) returned Indexed.

      Parameters

      • it: ShapeIndexIterator
      • cell: Cell

      Returns boolean

    • Returns the true centroid of the polygon multiplied by the area of the polygon. The result is not unit length, so you may want to normalize it. Also note that in general, the centroid may not be contained by the polygon.

      We prescale by the polygon area for two reasons: (1) it is cheaper to compute this way, and (2) it makes it easier to compute the centroid of more complicated shapes (by splitting them into disjoint regions and adding their centroids).

      Returns s2.Point

    • Returns the i-th edge Chain (loop) in the Shape.

      Parameters

      • chainID: number

      Returns Chain

    • Returns the j-th edge of the i-th edge Chain (loop).

      Parameters

      • i: number
      • j: number

      Returns Edge

    • Returns a pair (i, j) such that edgeID is the j-th edge of the i-th edge Chain.

      Parameters

      • edgeID: number

      Returns ChainPosition

    • Returns +1 if this polygon contains the boundary of B, -1 if A excludes the boundary of B, and 0 if the boundaries of A and B cross.

      Parameters

      Returns number

    • Defines a total ordering on Loops that does not depend on the cyclic order of loop vertices. This function is used to choose which loop to invert in the case where several loops have exactly the same area.

      Parameters

      Returns number

    • Reports whether this polygon contains the other polygon. Specifically, it reports whether all the points in the other polygon are also in this polygon.

      Parameters

      Returns boolean

    • Reports whether polygon A contains the boundary of loop B. Shared edges are handled according to the rule described in loops containsNonCrossingBoundary.

      Parameters

      • o: Loop
      • reverse: boolean

      Returns boolean

    • Returns the dimension of the geometry represented by this Polygon.

      Returns number

    • Returns endpoints for the given edge index.

      Parameters

      • e: number

      Returns Edge

    • Reports whether given two polygons A and B such that the boundary of A does not cross any loop of B, if A excludes all shell boundaries of the complement of B.

      Parameters

      Returns boolean

    • Reports wheterh given two polygons A and B such that the boundary of A does not cross any loop of B, if A excludes all shell boundaries of B.

      Parameters

      Returns boolean

    • Performs the shape related initializations and adds the final polygon to the index.

      Returns void

    • Walks the mapping of loops to all of their children, and adds them in order into to the polygons set of loops.

      Parameters

      • lm: LoopMap

      Returns void

    • Takes the set of loops in this polygon and performs the nesting computations to set the proper nesting and parent/child relationships.

      Returns void

    • Reports whether this is the special "empty" polygon (consisting of no loops).

      Returns boolean

    • Reports whether this is the special "full" polygon (consisting of a single loop that encompasses the entire sphere).

      Returns boolean

    • Reports whether the iterator that is positioned at the ShapeIndexCell that may contain p, contains the point p.

      Parameters

      • it: ShapeIndexIterator
      • point: s2.Point

      Returns boolean

    • Returns the index of the last loop that is contained within loop k. If k is negative, it returns the last loop in the polygon. Note that loops are indexed according to a pre-order traversal of the nesting hierarchy, so the immediate children of loop k can be found by iterating over the loops (k+1)..LastDescendant(k) and selecting those whose depth is equal to Loop(k).depth+1.

      Parameters

      • k: number

      Returns number

    • Returns the loop at the given index. Note that during initialization, the given loops are reordered according to a pre-order traversal of the loop nesting hierarchy. This implies that every loop is immediately followed by its descendants. This hierarchy can be traversed using the methods Parent, LastDescendant, and Loop.depth.

      Parameters

      • k: number

      Returns Loop

    • Reports the number of contiguous edge chains in the Polygon.

      Returns number

    • Returns the index of the parent of loop k. If the loop does not have a parent, ok=false is returned.

      Parameters

      • k: number

      Returns [number, boolean]

    • We do not support implementations of this interface outside this package.

      Returns void

    • Returns the reference point for this polygon.

      Returns ReferencePoint

    • Returns a value that can be used to identify the type of an encoded Shape.

      Returns number

    • Checks whether this is a valid polygon, including checking whether all the loops are themselves valid.

      Returns null | Error