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.
MonotoneChains support being assigned an integer id value to provide a total ordering for a set of chains. This can be used during some kinds of processing to avoid redundant comparisons (i.e. by comparing only chains where the first id is less than the second).
MonotoneChains support using an tolerance distance for overlap tests.
This allows reporting overlap in situations where
intersection snapping is being used.
If this is used the chain envelope must be computed
providing an expansion distance using getEnvelope(double)
.
Constructor and Description |
---|
MonotoneChain(Coordinate[] pts,
int start,
int end,
Object context)
Creates a new MonotoneChain based on the given array of points.
|
Modifier and Type | Method and Description |
---|---|
void |
computeOverlaps(MonotoneChain mc,
double overlapTolerance,
MonotoneChainOverlapAction mco)
Determines the line segments in two chains which may overlap,
using an overlap distance tolerance,
and passes them to an overlap action.
|
void |
computeOverlaps(MonotoneChain mc,
MonotoneChainOverlapAction mco)
Determines the line segments in two chains which may overlap,
and passes them to an overlap action.
|
Object |
getContext()
Gets the user-defined context data value.
|
Coordinate[] |
getCoordinates()
Return the subsequence of coordinates forming this chain.
|
int |
getEndIndex()
Gets the index of the end of the monotone chain
in the underlying array of points.
|
Envelope |
getEnvelope()
Gets the envelope of the chain.
|
Envelope |
getEnvelope(double expansionDistance)
Gets the envelope for this chain,
expanded by a given distance.
|
int |
getId()
Gets the id of this chain.
|
void |
getLineSegment(int index,
LineSegment ls)
Gets the line segment starting at
index |
int |
getStartIndex()
Gets the index of the start of the monotone chain
in the underlying array of points.
|
void |
select(Envelope searchEnv,
MonotoneChainSelectAction mcs)
Determine all the line segments in the chain whose envelopes overlap
the searchEnvelope, and process them.
|
void |
setId(int id)
Sets the id of this chain.
|
void |
setOverlapDistance(double distance)
Sets the overlap distance used in overlap tests
with other chains.
|
public MonotoneChain(Coordinate[] pts, int start, int end, Object context)
pts
- the points containing the chainstart
- the index of the first coordinate in the chainend
- the index of the last coordinate in the chaincontext
- a user-defined data objectpublic void setId(int id)
id
- an id valuepublic void setOverlapDistance(double distance)
distance
- the distance to buffer overlap tests bypublic int getId()
public Object getContext()
public Envelope getEnvelope()
public Envelope getEnvelope(double expansionDistance)
expansionDistance
- distance to expand the envelope bypublic int getStartIndex()
public int getEndIndex()
public void getLineSegment(int index, LineSegment ls)
index
index
- index of segmentls
- line segment to extract intopublic Coordinate[] getCoordinates()
public void select(Envelope searchEnv, 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 envelopemcs
- the select action to execute on selected segmentspublic void computeOverlaps(MonotoneChain mc, 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.
mc
- the chain to compare tomco
- the overlap action to execute on overlapping segmentspublic void computeOverlaps(MonotoneChain mc, double overlapTolerance, MonotoneChainOverlapAction mco)
mc
- the chain to compare tooverlapTolerance
- the distance tolerance for the overlap testmco
- the overlap action to execute on selected segmentsCopyright © 2022. All rights reserved.