Package com.google.common.geometry
Class S2Iterator<T extends S2Iterator.Entry>
- java.lang.Object
-
- com.google.common.geometry.S2Iterator<T>
-
@GwtCompatible public final class S2Iterator<T extends S2Iterator.Entry> extends Object
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 acompareTo(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 Classes Modifier and Type Class Description static interfaceS2Iterator.EntryAn interface to provide the cell ID for an element in a sorted list.
-
Field Summary
Fields Modifier and Type Field Description protected intpos
-
Constructor Summary
Constructors Modifier Constructor Description protectedS2Iterator(List<T> entries)Create a new iterator based on the given list of entries.protectedS2Iterator(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanatBegin()Returns true if the iterator is positioned at the first index cell.S2Pointcenter()Returns the center of the cell (used as a reference point for shape interiors.)intcompareTo(S2CellId cellId)Returns the comparison from the current iterator cell to the given cell ID.S2Iterator<T>copy()Returns a copy of this iterator, positioned as this iterator is.booleandone()Returns true if the iterator is positioned past the last index cell.Tentry()Returns the current entry.<T extends S2Iterator.Entry>
booleanequalIterators(S2Iterator<T> it)Returns true if these iterators have the same entries and position.booleanequals(Object o)Returns true ifois anS2Iteratorwith equal entries and position.voidfinish()Positions the iterator so thatdone()is true.inthashCode()S2CellIdid()Returns the cell id for the current cell.S2ShapeIndex.CellRelationlocate(S2CellId target)Positions the iterator at the index cell containing the given cell, if possible, and returns theS2ShapeIndex.CellRelationthat describes the relationship between the index and the given target cell: ReturnsS2ShapeIndex.CellRelation.INDEXEDif the iterator was positioned at an index cell that is equal to or contains the given cell.booleanlocate(S2Point targetPoint)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.voidnext()Advances the iterator to the next cell in the index.voidposition(S2Iterator<T> it)Set this iterator to the position given by the other iterator.voidprev()Positions the iterator at the previous cell in the index.voidrestart()Positions the iterator so thatatBegin()is true.voidseek(S2CellId target)Positions the iterator at the first cell with id() >= target, or at the end of the index if no such cell exists.voidseekForward(S2CellId target)Advances the iterator to the next cell with id() >= target.
-
-
-
Constructor Detail
-
S2Iterator
protected S2Iterator(List<T> entries)
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 targetS2CellIdand returns an index to which this iterator will be repositioned.
-
-
Method Detail
-
copy
public S2Iterator<T> copy()
Returns a copy of this iterator, positioned as this iterator is.
-
restart
public void restart()
Positions the iterator so thatatBegin()is true.
-
compareTo
public int compareTo(S2CellId cellId)
Returns the comparison from the current iterator cell to the given cell ID.
-
equals
public boolean equals(Object o)
Returns true ifois anS2Iteratorwith equal entries and position.
-
equalIterators
public <T extends S2Iterator.Entry> boolean equalIterators(S2Iterator<T> it)
Returns true if these iterators have the same entries and position.
-
id
public S2CellId id()
Returns the cell id for the current cell.
-
entry
public T entry()
Returns the current entry.
-
center
public S2Point 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 ifposis 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 ifposis 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
public void seek(S2CellId target)
Positions the iterator at the first cell with id() >= target, or at the end of the index if no such cell exists.
-
seekForward
public void seekForward(S2CellId target)
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
public boolean locate(S2Point targetPoint)
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
targetPointandcenter().
-
locate
public S2ShapeIndex.CellRelation locate(S2CellId target)
Positions the iterator at the index cell containing the given cell, if possible, and returns theS2ShapeIndex.CellRelationthat describes the relationship between the index and the given target cell:- Returns
S2ShapeIndex.CellRelation.INDEXEDif 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.SUBDIVIDEDif 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.DISJOINTif the iterator had to be positioned arbitrarily because the given target cell does not intersect any of the index's cells.
- Returns
-
position
public void position(S2Iterator<T> it)
Set this iterator to the position given by the other iterator.
-
-