Class S2PaddedCell

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

@GwtCompatible public class S2PaddedCell extends Object
S2PaddedCell represents an S2Cell whose (u,v)-range has been expanded on all sides by a given amount of "padding". Unlike S2Cell, its methods and representation are optimized for clipping edges against S2Cell boundaries to determine which cells are intersected by a given set of edges.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private R2Rect
    Bound in (u,v)-space.
    private S2CellId
    The cell being padded.
    private int
    Minimum (i,j)-coordinates of this cell, before padding.
    private int
     
    private int
    Level of this cell.
    private R2Rect
    The rectangle in (u,v)-space that belongs to all four padded children.
    private int
    Hilbert curve orientation of this cell.
    private double
    UV padding on all sides.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    S2PaddedCell(S2CellId id, double padding)
    Construct an S2PaddedCell for the given cell id and padding.
    private
    S2PaddedCell(S2PaddedCell parent, int pos, int i, int j)
    Private constructor to create a new S2PaddedCell for the child at the given (i,j) position.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the bound for this cell (including padding.)
    childAtIJ(int i, int j)
    Construct the child of this cell with the given (i,j) index.
    childAtPos(int pos)
    Construct the child of this cell with the given Hilbert curve position, from 0 to 3.
    private static final int
    floorLog2(long x)
    Returns the floor of the log2 of x, assuming x is positive.
    Returns the center of this cell.
    Returns the vertex where the S2 space-filling curve enters this cell.
    Returns the vertex where the S2 space-filling curve exits this cell.
    id()
    Returns the ID of this padded cell.
    int
    Returns the level of this cell.
    Return the "middle" of the padded cell, defined as the rectangle that belongs to all four children.
    int
    Returns the orientation of this cell.
    double
    Returns the padding around this cell.
    Returns the smallest cell that contains all descendants of this cell whose bounds intersect "rect".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      private S2CellId id
      The cell being padded.
    • padding

      private double padding
      UV padding on all sides.
    • bound

      private R2Rect bound
      Bound in (u,v)-space. Includes padding.
    • middle

      private R2Rect middle
      The rectangle in (u,v)-space that belongs to all four padded children. It is computed on demand by the middle() accessor method.
    • iLo

      private int iLo
      Minimum (i,j)-coordinates of this cell, before padding.
    • jLo

      private int jLo
    • orientation

      private int orientation
      Hilbert curve orientation of this cell.
    • level

      private int level
      Level of this cell.
  • Constructor Details

    • S2PaddedCell

      public S2PaddedCell(S2CellId id, double padding)
      Construct an S2PaddedCell for the given cell id and padding.
    • S2PaddedCell

      private S2PaddedCell(S2PaddedCell parent, int pos, int i, int j)
      Private constructor to create a new S2PaddedCell for the child at the given (i,j) position.
  • Method Details

    • childAtIJ

      public S2PaddedCell childAtIJ(int i, int j)
      Construct the child of this cell with the given (i,j) index. The four child cells have indices of (0,0), (0,1), (1,0), (1,1), where the i and j indices correspond to increasing u- and v-values respectively.
    • childAtPos

      public S2PaddedCell childAtPos(int pos)
      Construct the child of this cell with the given Hilbert curve position, from 0 to 3.
    • id

      public S2CellId id()
      Returns the ID of this padded cell.
    • padding

      public double padding()
      Returns the padding around this cell.
    • level

      public int level()
      Returns the level of this cell.
    • orientation

      public int orientation()
      Returns the orientation of this cell.
    • bound

      public R2Rect bound()
      Returns the bound for this cell (including padding.)
    • middle

      public R2Rect middle()
      Return the "middle" of the padded cell, defined as the rectangle that belongs to all four children.

      Note that this method is *not* thread-safe, because the return value is computed on demand and cached. (It is expected that this class will be mainly useful in the context of single- threaded recursive algorithms.)

    • shrinkToFit

      public S2CellId shrinkToFit(R2Rect rect)
      Returns the smallest cell that contains all descendants of this cell whose bounds intersect "rect". For algorithms that use recursive subdivision to find the cells that intersect a particular object, this method can be used to skip all the initial subdivision steps where only one child needs to be expanded.

      Note that this method is not the same as returning the smallest cell that contains the intersection of this cell with "rect". Because of the padding, even if one child completely contains "rect" it is still possible that a neighboring child also intersects "rect".

      Results are undefined if bound() does not intersect the given rectangle.

    • floorLog2

      private static final int floorLog2(long x)
      Returns the floor of the log2 of x, assuming x is positive.
    • getCenter

      public S2Point getCenter()
      Returns the center of this cell.
    • getEntryVertex

      public S2Point getEntryVertex()
      Returns the vertex where the S2 space-filling curve enters this cell.
    • getExitVertex

      public S2Point getExitVertex()
      Returns the vertex where the S2 space-filling curve exits this cell.