GEOS  3.9.1dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
geos::index::chain::MonotoneChain Class Reference

Monotone Chains are a way of partitioning the segments of a linestring to allow for fast searching of intersections. More...

#include <MonotoneChain.h>

Collaboration diagram for geos::index::chain::MonotoneChain:
[legend]

Public Member Functions

 MonotoneChain (const geom::CoordinateSequence &pts, std::size_t start, std::size_t end, void *context)
 
 ~MonotoneChain ()=default
 
const geom::EnvelopegetEnvelope ()
 Returned envelope is owned by this class. More...
 
const geom::EnvelopegetEnvelope (double expansionDistance)
 
size_t getStartIndex () const
 
size_t getEndIndex () const
 
void getLineSegment (std::size_t index, geom::LineSegment &ls) const
 Set given LineSegment with points of the segment starting at the given index. More...
 
std::unique_ptr< geom::CoordinateSequencegetCoordinates () const
 
void select (const geom::Envelope &searchEnv, MonotoneChainSelectAction &mcs)
 
void computeOverlaps (MonotoneChain *mc, MonotoneChainOverlapAction *mco)
 
void computeOverlaps (MonotoneChain *mc, double overlapTolerance, MonotoneChainOverlapAction *mco)
 
void setId (int nId)
 
int getId () const
 
void * getContext ()
 

Private Member Functions

void computeSelect (const geom::Envelope &searchEnv, size_t start0, size_t end0, MonotoneChainSelectAction &mcs)
 
void computeOverlaps (std::size_t start0, std::size_t end0, MonotoneChain &mc, std::size_t start1, std::size_t end1, double overlapTolerance, MonotoneChainOverlapAction &mco)
 
bool overlaps (size_t start0, size_t end0, const MonotoneChain &mc, size_t start1, size_t end1, double overlapTolerance) const
 
bool overlaps (const geom::Coordinate &p1, const geom::Coordinate &p2, const geom::Coordinate &q1, const geom::Coordinate &q2, double overlapTolerance) const
 
 MonotoneChain (const MonotoneChain &other)=delete
 
MonotoneChainoperator= (const MonotoneChain &rhs)=delete
 

Private Attributes

const geom::CoordinateSequencepts
 Externally owned. More...
 
void * context
 user-defined information More...
 
size_t start
 Index of chain start vertex into the CoordinateSequence, 0 based. More...
 
size_t end
 Index of chain end vertex into the CoordinateSequence, 0 based. More...
 
geom::Envelope env
 Owned by this class. More...
 
bool envIsSet
 
int id
 useful for optimizing chain comparisons More...
 

Detailed Description

Monotone Chains are a way of partitioning the segments of a linestring to allow for fast searching of intersections.

They have the following properties:

Property 1 means that there is no need to test pairs of segments from within the same monotone chain for intersection. 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:

This implementation of MonotoneChains uses the concept of internal iterators to return the resultsets for the above 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. However, it does mean that the queries are not thread-safe.

Definition at line 84 of file index/chain/MonotoneChain.h.

Constructor & Destructor Documentation

geos::index::chain::MonotoneChain::MonotoneChain ( const geom::CoordinateSequence pts,
std::size_t  start,
std::size_t  end,
void *  context 
)
Parameters
ptsOwnership left to caller, this class holds a reference.
start
end
contextOwnership left to caller, this class holds a reference.
geos::index::chain::MonotoneChain::~MonotoneChain ( )
default
geos::index::chain::MonotoneChain::MonotoneChain ( const MonotoneChain other)
privatedelete

Member Function Documentation

void geos::index::chain::MonotoneChain::computeOverlaps ( MonotoneChain mc,
MonotoneChainOverlapAction mco 
)
void geos::index::chain::MonotoneChain::computeOverlaps ( MonotoneChain mc,
double  overlapTolerance,
MonotoneChainOverlapAction mco 
)
void geos::index::chain::MonotoneChain::computeOverlaps ( std::size_t  start0,
std::size_t  end0,
MonotoneChain mc,
std::size_t  start1,
std::size_t  end1,
double  overlapTolerance,
MonotoneChainOverlapAction mco 
)
private
void geos::index::chain::MonotoneChain::computeSelect ( const geom::Envelope searchEnv,
size_t  start0,
size_t  end0,
MonotoneChainSelectAction mcs 
)
private
void* geos::index::chain::MonotoneChain::getContext ( )
inline

Definition at line 157 of file index/chain/MonotoneChain.h.

std::unique_ptr<geom::CoordinateSequence> geos::index::chain::MonotoneChain::getCoordinates ( ) const

Return the subsequence of coordinates forming this chain. Allocates a new CoordinateSequence to hold the Coordinates

size_t geos::index::chain::MonotoneChain::getEndIndex ( ) const
inline

Definition at line 113 of file index/chain/MonotoneChain.h.

const geom::Envelope& geos::index::chain::MonotoneChain::getEnvelope ( )

Returned envelope is owned by this class.

const geom::Envelope& geos::index::chain::MonotoneChain::getEnvelope ( double  expansionDistance)
int geos::index::chain::MonotoneChain::getId ( ) const
inline

Definition at line 151 of file index/chain/MonotoneChain.h.

void geos::index::chain::MonotoneChain::getLineSegment ( std::size_t  index,
geom::LineSegment ls 
) const

Set given LineSegment with points of the segment starting at the given index.

size_t geos::index::chain::MonotoneChain::getStartIndex ( ) const
inline

Definition at line 107 of file index/chain/MonotoneChain.h.

MonotoneChain& geos::index::chain::MonotoneChain::operator= ( const MonotoneChain rhs)
privatedelete
bool geos::index::chain::MonotoneChain::overlaps ( size_t  start0,
size_t  end0,
const MonotoneChain mc,
size_t  start1,
size_t  end1,
double  overlapTolerance 
) const
private
bool geos::index::chain::MonotoneChain::overlaps ( const geom::Coordinate p1,
const geom::Coordinate p2,
const geom::Coordinate q1,
const geom::Coordinate q2,
double  overlapTolerance 
) const
private
void geos::index::chain::MonotoneChain::select ( const geom::Envelope searchEnv,
MonotoneChainSelectAction mcs 
)

Determine all the line segments in the chain whose envelopes overlap the searchEnvelope, and process them

void geos::index::chain::MonotoneChain::setId ( int  nId)
inline

Definition at line 145 of file index/chain/MonotoneChain.h.

Member Data Documentation

void* geos::index::chain::MonotoneChain::context
private

user-defined information

Definition at line 186 of file index/chain/MonotoneChain.h.

size_t geos::index::chain::MonotoneChain::end
private

Index of chain end vertex into the CoordinateSequence, 0 based.

Definition at line 192 of file index/chain/MonotoneChain.h.

geom::Envelope geos::index::chain::MonotoneChain::env
private

Owned by this class.

Definition at line 195 of file index/chain/MonotoneChain.h.

bool geos::index::chain::MonotoneChain::envIsSet
private

Definition at line 196 of file index/chain/MonotoneChain.h.

int geos::index::chain::MonotoneChain::id
private

useful for optimizing chain comparisons

Definition at line 199 of file index/chain/MonotoneChain.h.

const geom::CoordinateSequence& geos::index::chain::MonotoneChain::pts
private

Externally owned.

Definition at line 183 of file index/chain/MonotoneChain.h.

size_t geos::index::chain::MonotoneChain::start
private

Index of chain start vertex into the CoordinateSequence, 0 based.

Definition at line 189 of file index/chain/MonotoneChain.h.


The documentation for this class was generated from the following file: