GEOS 3.14.0dev
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#pragma once
20
21#include <geos/export.h>
22#include <geos/geom/CoordinateSequence.h> // for inline
23#include <geos/geom/Envelope.h> // for inline
24#include <geos/geom/LineSegment.h> // for inline
25
26#include <memory> // for unique_ptr
27
28// Forward declarations
29namespace geos {
30namespace geom {
31class LineSegment;
32class CoordinateSequence;
33}
34namespace index {
35namespace chain {
38}
39}
40}
41
42namespace geos {
43namespace index { // geos::index
44namespace chain { // geos::index::chain
45
85class GEOS_DLL MonotoneChain {
86public:
87
99 std::size_t start, std::size_t end, void* context);
100
101 ~MonotoneChain() = default;
102
105 const geom::Envelope& getEnvelope(double expansionDistance) const;
106
107 size_t
108 getStartIndex() const
109 {
110 return start;
111 }
112
113 size_t
114 getEndIndex() const
115 {
116 return end;
117 }
118
123 void getLineSegment(std::size_t index, geom::LineSegment& ls) const {
124 pts->getAt(index, ls.p0);
125 pts->getAt(index + 1, ls.p1);
126 }
127
133 std::unique_ptr<geom::CoordinateSequence> getCoordinates() const;
134
139 void select(const geom::Envelope& searchEnv,
140 MonotoneChainSelectAction& mcs) const;
141
142 void computeOverlaps(const MonotoneChain* mc,
143 MonotoneChainOverlapAction* mco) const;
144
145 void computeOverlaps(const MonotoneChain* mc, double overlapTolerance,
146 MonotoneChainOverlapAction* mco) const;
147
148 void*
149 getContext() const
150 {
151 return context;
152 }
153
154private:
155
156 void computeSelect(const geom::Envelope& searchEnv,
157 std::size_t start0,
158 std::size_t end0,
159 MonotoneChainSelectAction& mcs) const;
160
161 void computeOverlaps(std::size_t start0, std::size_t end0, const MonotoneChain& mc,
162 std::size_t start1, std::size_t end1,
163 double overlapTolerance,
164 MonotoneChainOverlapAction& mco) const;
165
166 bool overlaps(std::size_t start0, std::size_t end0,
167 const MonotoneChain& mc, std::size_t start1, std::size_t end1,
168 double overlapTolerance) const {
169 if (overlapTolerance > 0.0) {
170 return overlaps(pts->getAt<geom::CoordinateXY>(start0),
171 pts->getAt<geom::CoordinateXY>(end0),
172 mc.pts->getAt<geom::CoordinateXY>(start1),
173 mc.pts->getAt<geom::CoordinateXY>(end1),
174 overlapTolerance);
175 }
176 return geom::Envelope::intersects(pts->getAt<geom::CoordinateXY>(start0),
177 pts->getAt<geom::CoordinateXY>(end0),
178 mc.pts->getAt<geom::CoordinateXY>(start1),
179 mc.pts->getAt<geom::CoordinateXY>(end1));
180 }
181
182 static bool overlaps(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2,
183 const geom::CoordinateXY& q1, const geom::CoordinateXY& q2,
184 double overlapTolerance);
185
187 const geom::CoordinateSequence* pts;
188
190 void* context;
191
193 std::size_t start;
194
196 std::size_t end;
197
199 mutable geom::Envelope env;
200
201};
202
203} // namespace geos::index::chain
204} // namespace geos::index
205} // namespace geos
206
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Definition LineSegment.h:61
Coordinate p1
Segment start.
Definition LineSegment.h:66
The action for the internal iterator for performing overlap queries on a MonotoneChain.
Definition MonotoneChainOverlapAction.h:42
Definition MonotoneChainSelectAction.h:44
Monotone Chains are a way of partitioning the segments of a linestring to allow for fast searching of...
Definition index/chain/MonotoneChain.h:85
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:123
void select(const geom::Envelope &searchEnv, MonotoneChainSelectAction &mcs) const
std::unique_ptr< geom::CoordinateSequence > getCoordinates() const
const T & getAt(std::size_t i) const
Returns a read-only reference to Coordinate at position i.
Definition CoordinateSequence.h:249
Basic namespace for all GEOS functionalities.
Definition geos.h:39