Package com.google.common.geometry
Class S2PaddedCell
- java.lang.Object
-
- com.google.common.geometry.S2PaddedCell
-
@GwtCompatible public class S2PaddedCell extends java.lang.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
Bound in (u,v)-space.private S2CellId
id
The cell being padded.private int
iLo
Minimum (i,j)-coordinates of this cell, before padding.private int
jLo
private int
level
Level of this cell.private R2Rect
middle
The rectangle in (u,v)-space that belongs to all four padded children.private int
orientation
Hilbert curve orientation of this cell.private double
padding
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description R2Rect
bound()
Returns the bound for this cell (including padding.)S2PaddedCell
childAtIJ(int i, int j)
Construct the child of this cell with the given (i,j) index.S2PaddedCell
childAtPos(int pos)
Construct the child of this cell with the given Hilbert curve position, from 0 to 3.private static int
floorLog2(long x)
Returns the floor of the log2 of x, assuming x is positive.S2Point
getCenter()
Returns the center of this cell.S2Point
getEntryVertex()
Returns the vertex where the S2 space-filling curve enters this cell.S2Point
getExitVertex()
Returns the vertex where the S2 space-filling curve exits this cell.S2CellId
id()
Returns the ID of this padded cell.int
level()
Returns the level of this cell.R2Rect
middle()
Return the "middle" of the padded cell, defined as the rectangle that belongs to all four children.int
orientation()
Returns the orientation of this cell.double
padding()
Returns the padding around this cell.S2CellId
shrinkToFit(R2Rect rect)
Returns the smallest cell that contains all descendants of this cell whose bounds intersect "rect".
-
-
-
Field Detail
-
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 Detail
-
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 Detail
-
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.
-
-