Package com.google.common.geometry
Class S2Iterator<T extends S2Iterator.Entry>
java.lang.Object
com.google.common.geometry.S2Iterator<T>
A random access iterator that provides low-level access to entries sorted by cell ID. The
behavior of this iterator is more like a database cursor, where accessing properties at the
current position does not alter the position of the cursor. The cursor has a
compareTo(com.google.common.geometry.S2CellId)
method to compare the value at the current position of the iterator with a given S2CellId.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface to provide the cell ID for an element in a sorted list. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
S2Iterator
(List<T> entries) Create a new iterator based on the given list of entries.protected
S2Iterator
(List<T> entries, com.google.common.base.Function<S2CellId, Integer> seekFunction) Same asS2Iterator(List)
, but acceptsseekFunction
, which is used as the implementation ofseek(S2CellId)
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
atBegin()
Returns true if the iterator is positioned at the first index cell.center()
Returns the center of the cell (used as a reference point for shape interiors.)int
Returns the comparison from the current iterator cell to the given cell ID.copy()
Returns a copy of this iterator, positioned as this iterator is.(package private) static <T extends S2Iterator.Entry>
S2Iterator<T> copy
(S2Iterator<T> it) Creates a new iterator with the same entries and position asit
.(package private) static <T extends S2Iterator.Entry>
S2Iterator<T> Creates an iterator given a list of entries.(package private) static <T extends S2Iterator.Entry>
S2Iterator<T> Same ascreate(List)
, but acceptsseekFunction
, which is used as the implementation ofseek(S2CellId)
.boolean
done()
Returns true if the iterator is positioned past the last index cell.entry()
Returns the current entry.<T extends S2Iterator.Entry>
booleanequalIterators
(S2Iterator<T> it) Returns true if these iterators have the same entries and position.boolean
Returns true ifo
is anS2Iterator
with equal entries and position.void
finish()
Positions the iterator so thatdone()
is true.int
hashCode()
id()
Returns the cell id for the current cell.Positions the iterator at the index cell containing the given cell, if possible, and returns theS2ShapeIndex.CellRelation
that describes the relationship between the index and the given target cell: ReturnsS2ShapeIndex.CellRelation.INDEXED
if the iterator was positioned at an index cell that is equal to or contains the given cell.boolean
Positions the iterator at the index cell containing "target" and returns true, or if no such cell exists in the index, the iterator is positioned arbitrarily and this method returns false.void
next()
Advances the iterator to the next cell in the index.void
position
(S2Iterator<T> it) Set this iterator to the position given by the other iterator.void
prev()
Positions the iterator at the previous cell in the index.void
restart()
Positions the iterator so thatatBegin()
is true.void
Positions the iterator at the first cell with id() >= target, or at the end of the index if no such cell exists.void
seekForward
(S2CellId target) Advances the iterator to the next cell with id() >= target.
-
Field Details
-
entries
-
seekFunction
-
pos
protected int pos
-
-
Constructor Details
-
S2Iterator
Create a new iterator based on the given list of entries. Results are undefined if the entries are not in ascending sorted order.- Parameters:
entries
- the list of entries which back this iterator.
-
S2Iterator
protected S2Iterator(List<T> entries, com.google.common.base.Function<S2CellId, Integer> seekFunction) Same asS2Iterator(List)
, but acceptsseekFunction
, which is used as the implementation ofseek(S2CellId)
.- Parameters:
entries
- the list of entries which back this iterator.seekFunction
- a function which takes a targetS2CellId
and returns an index to which this iterator will be repositioned.
-
-
Method Details
-
create
Creates an iterator given a list of entries. Package private and not public, since only S2 classes guarantee the necessary preconditions onentries
-- that the cell IDs of each entry are sorted in ascending order. -
create
static <T extends S2Iterator.Entry> S2Iterator<T> create(List<T> entries, com.google.common.base.Function<S2CellId, Integer> seekFunction) Same ascreate(List)
, but acceptsseekFunction
, which is used as the implementation ofseek(S2CellId)
.- Parameters:
entries
- the list of entries which back this iterator.seekFunction
- a function which takes a targetS2CellId
and returns an index to which this iterator will be repositioned.
-
copy
Creates a new iterator with the same entries and position asit
. -
copy
Returns a copy of this iterator, positioned as this iterator is. -
restart
public void restart()Positions the iterator so thatatBegin()
is true. -
compareTo
Returns the comparison from the current iterator cell to the given cell ID. -
equals
Returns true ifo
is anS2Iterator
with equal entries and position. -
hashCode
public int hashCode() -
equalIterators
Returns true if these iterators have the same entries and position. -
id
Returns the cell id for the current cell. -
entry
Returns the current entry. -
center
Returns the center of the cell (used as a reference point for shape interiors.) -
next
public void next()Advances the iterator to the next cell in the index. Does not advance the iterator ifpos
is equal to the number of cells in the index. -
prev
public void prev()Positions the iterator at the previous cell in the index. Does not move the iterator ifpos
is equal to 0. -
done
public boolean done()Returns true if the iterator is positioned past the last index cell. -
atBegin
public boolean atBegin()Returns true if the iterator is positioned at the first index cell. -
seek
Positions the iterator at the first cell with id() >= target, or at the end of the index if no such cell exists. -
seekForward
Advances the iterator to the next cell with id() >= target. If the iterator isdone()
or already satisfies id() >= target, there is no effect. -
finish
public void finish()Positions the iterator so thatdone()
is true. -
locate
Positions the iterator at the index cell containing "target" and returns true, or if no such cell exists in the index, the iterator is positioned arbitrarily and this method returns false.The resulting index position is guaranteed to contain all edges that might intersect the line segment between
targetPoint
andcenter()
. -
locate
Positions the iterator at the index cell containing the given cell, if possible, and returns theS2ShapeIndex.CellRelation
that describes the relationship between the index and the given target cell:- Returns
S2ShapeIndex.CellRelation.INDEXED
if the iterator was positioned at an index cell that is equal to or contains the given cell. I.e. the given target exists in the index as a leaf cell. - Returns
S2ShapeIndex.CellRelation.SUBDIVIDED
if the iterator was positioned at the first of one or more cells contained by the given target cell. I.e. the target does not exist in the index, but the first of its descendants was selected. - Returns
S2ShapeIndex.CellRelation.DISJOINT
if the iterator had to be positioned arbitrarily because the given target cell does not intersect any of the index's cells.
- Returns
-
position
Set this iterator to the position given by the other iterator.
-