Package com.google.common.geometry
Class S2PaddedCell
java.lang.Object
com.google.common.geometry.S2PaddedCell
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
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsModifierConstructorDescriptionS2PaddedCell
(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 TypeMethodDescriptionbound()
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
level()
Returns the level of this cell.middle()
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
padding()
Returns the padding around this cell.shrinkToFit
(R2Rect rect) Returns the smallest cell that contains all descendants of this cell whose bounds intersect "rect".
-
Field Details
-
id
The cell being padded. -
padding
private double paddingUV padding on all sides. -
bound
Bound in (u,v)-space. Includes padding. -
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 iLoMinimum (i,j)-coordinates of this cell, before padding. -
jLo
private int jLo -
orientation
private int orientationHilbert curve orientation of this cell. -
level
private int levelLevel of this cell.
-
-
Constructor Details
-
S2PaddedCell
Construct an S2PaddedCell for the given cell id and padding. -
S2PaddedCell
Private constructor to create a new S2PaddedCell for the child at the given (i,j) position.
-
-
Method Details
-
childAtIJ
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
Construct the child of this cell with the given Hilbert curve position, from 0 to 3. -
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
Returns the bound for this cell (including padding.) -
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
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
Returns the center of this cell. -
getEntryVertex
Returns the vertex where the S2 space-filling curve enters this cell. -
getExitVertex
Returns the vertex where the S2 space-filling curve exits this cell.
-