public class MonotoneChain extends Object
Property 2 allows an efficient binary search to be used to find the intersection points of two monotone chains. For many types of real-world data, these properties eliminate a large number of segment comparisons, producing substantial speed gains.
One of the goals of this implementation of MonotoneChains is to be as space and time efficient as possible. One design choice that aids this is that a MonotoneChain is based on a subarray of a list of points. This means that new arrays of points (potentially very large) do not have to be allocated.
MonotoneChains support the following kinds of queries:
MonotoneChainSelectAction and
MonotoneChainOverlapAction) to return the results for queries. This has time and space advantages, since it is not necessary to build lists of instantiated objects to represent the segments returned by the query. Queries made in this manner are thread-safe.
| Constructor and Description |
|---|
MonotoneChain(Coordinate
|
| Modifier and Type | Method and Description |
|---|---|
void |
computeOverlaps(MonotoneChain
Determine all the line segments in two chains which may overlap, and process them.
|
Object |
getContext()
|
Coordinate |
getCoordinates()
Return the subsequence of coordinates forming this chain.
|
int |
getEndIndex()
|
Envelope |
getEnvelope()
|
int |
getId()
|
void |
getLineSegment(int index, LineSegment
Gets the line segment starting at
index
|
int |
getStartIndex()
|
void |
select(Envelope
Determine all the line segments in the chain whose envelopes overlap the searchEnvelope, and process them.
|
void |
setId(int id)
|
public MonotoneChain(Coordinate[] pts, int start, int end, Object context)
public void setId(int id)
public int getId()
public ObjectgetContext()
public EnvelopegetEnvelope()
public int getStartIndex()
public int getEndIndex()
public void getLineSegment(int index,
LineSegment ls)
index
index - index of segment
ls - line segment to extract into
public Coordinate[] getCoordinates()
public void select(EnvelopesearchEnv, MonotoneChainSelectAction mcs)
The monotone chain search algorithm attempts to optimize performance by not calling the select action on chain segments which it can determine are not in the search envelope. However, it *may* call the select action on segments which do not intersect the search envelope. This saves on the overhead of checking envelope intersection each time, since clients may be able to do this more efficiently.
searchEnv - the search envelope
mcs - the select action to execute on selected segments
public void computeOverlaps(MonotoneChainmc, MonotoneChainOverlapAction mco)
The monotone chain search algorithm attempts to optimize performance by not calling the overlap action on chain segments which it can determine do not overlap. However, it *may* call the overlap action on segments which do not actually interact. This saves on the overhead of checking intersection each time, since clients may be able to do this more efficiently.
searchEnv - the search envelope
mco - the overlap action to execute on selected segments