GEOS  3.10.2
index/chain/MonotoneChain.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2001-2002 Vivid Solutions Inc.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: index/chain/MonotoneChain.java rev. 1.15 (JTS-1.10)
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_IDX_CHAIN_MONOTONECHAIN_H
20 #define GEOS_IDX_CHAIN_MONOTONECHAIN_H
21 
22 #include <geos/export.h>
23 #include <geos/geom/CoordinateSequence.h> // for inline
24 #include <geos/geom/Envelope.h> // for inline
25 #include <geos/geom/LineSegment.h> // for inline
26 
27 #include <memory> // for unique_ptr
28 
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32 class LineSegment;
33 class CoordinateSequence;
34 }
35 namespace index {
36 namespace chain {
39 }
40 }
41 }
42 
43 namespace geos {
44 namespace index { // geos::index
45 namespace chain { // geos::index::chain
46 
86 class GEOS_DLL MonotoneChain {
87 public:
88 
100  std::size_t start, std::size_t end, void* context);
101 
102  ~MonotoneChain() = default;
103 
105  const geom::Envelope& getEnvelope() const;
106  const geom::Envelope& getEnvelope(double expansionDistance) const;
107 
108  size_t
109  getStartIndex() const
110  {
111  return start;
112  }
113 
114  size_t
115  getEndIndex() const
116  {
117  return end;
118  }
119 
124  void getLineSegment(std::size_t index, geom::LineSegment& ls) const {
125  pts->getAt(index, ls.p0);
126  pts->getAt(index + 1, ls.p1);
127  }
128 
134  std::unique_ptr<geom::CoordinateSequence> getCoordinates() const;
135 
140  void select(const geom::Envelope& searchEnv,
141  MonotoneChainSelectAction& mcs) const;
142 
143  void computeOverlaps(const MonotoneChain* mc,
144  MonotoneChainOverlapAction* mco) const;
145 
146  void computeOverlaps(const MonotoneChain* mc, double overlapTolerance,
147  MonotoneChainOverlapAction* mco) const;
148 
149  void*
150  getContext() const
151  {
152  return context;
153  }
154 
155 private:
156 
157  void computeSelect(const geom::Envelope& searchEnv,
158  std::size_t start0,
159  std::size_t end0,
160  MonotoneChainSelectAction& mcs) const;
161 
162  void computeOverlaps(std::size_t start0, std::size_t end0, const MonotoneChain& mc,
163  std::size_t start1, std::size_t end1,
164  double overlapTolerance,
165  MonotoneChainOverlapAction& mco) const;
166 
167  bool overlaps(std::size_t start0, std::size_t end0,
168  const MonotoneChain& mc, std::size_t start1, std::size_t end1,
169  double overlapTolerance) const {
170  if (overlapTolerance > 0.0) {
171  return overlaps(pts->getAt(start0), pts->getAt(end0),
172  mc.pts->getAt(start1), mc.pts->getAt(end1), overlapTolerance);
173  }
174  return geom::Envelope::intersects(pts->getAt(start0), pts->getAt(end0),
175  mc.pts->getAt(start1), mc.pts->getAt(end1));
176  }
177 
178  static bool overlaps(const geom::Coordinate& p1, const geom::Coordinate& p2,
179  const geom::Coordinate& q1, const geom::Coordinate& q2,
180  double overlapTolerance);
181 
183  const geom::CoordinateSequence* pts;
184 
186  void* context;
187 
189  std::size_t start;
190 
192  std::size_t end;
193 
195  mutable geom::Envelope env;
196 };
197 
198 } // namespace geos::index::chain
199 } // namespace geos::index
200 } // namespace geos
201 
202 #endif // GEOS_IDX_CHAIN_MONOTONECHAIN_H
203 
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
virtual const Coordinate & getAt(std::size_t i) const =0
Returns a read-only reference to Coordinate at position i.
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
static bool intersects(const Coordinate &p1, const Coordinate &p2, const Coordinate &q)
Test the point q to see whether it intersects the Envelope defined by p1-p2.
Definition: LineSegment.h:59
Coordinate p1
Segment start.
Definition: LineSegment.h:66
The action for the internal iterator for performing overlap queries on a MonotoneChain.
Definition: MonotoneChainOverlapAction.h:43
Definition: MonotoneChainSelectAction.h:45
Monotone Chains are a way of partitioning the segments of a linestring to allow for fast searching of...
Definition: index/chain/MonotoneChain.h:86
MonotoneChain(const geom::CoordinateSequence &pts, std::size_t start, std::size_t end, void *context)
const geom::Envelope & getEnvelope() const
Returned envelope is owned by this class.
void getLineSegment(std::size_t index, geom::LineSegment &ls) const
Set given LineSegment with points of the segment starting at the given index.
Definition: index/chain/MonotoneChain.h:124
std::unique_ptr< geom::CoordinateSequence > getCoordinates() const
void select(const geom::Envelope &searchEnv, MonotoneChainSelectAction &mcs) const
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26