GEOS 3.11.1
OverlayUtil.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
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#pragma once
16
17#include <geos/geom/Point.h>
18#include <geos/geom/Polygon.h>
19#include <geos/geom/LineString.h>
20#include <geos/geom/Geometry.h>
21
22#include <geos/export.h>
23
24#include <vector>
25#include <memory>
26
27// Forward declarations
28namespace geos {
29namespace geom {
30class Coordinate;
31class CoordinateSequence;
32class Envelope;
33class GeometryFactory;
34class PrecisionModel;
35}
36namespace operation {
37namespace overlayng {
38class InputGeometry;
39class OverlayGraph;
40}
41}
42}
43
44
45namespace geos { // geos.
46namespace operation { // geos.operation
47namespace overlayng { // geos.operation.overlayng
48
49using namespace geos::geom;
50
57class GEOS_DLL OverlayUtil {
58
59private:
60
61 static constexpr double SAFE_ENV_BUFFER_FACTOR = 0.1;
62 static constexpr int SAFE_ENV_GRID_FACTOR = 3;
63 static constexpr double AREA_HEURISTIC_TOLERANCE = 0.1;
64
76 static bool resultEnvelope(int opCode, const InputGeometry* inputGeom, const PrecisionModel* pm, Envelope& rsltEnvelope);
77 static double safeExpandDistance(const Envelope* env, const PrecisionModel* pm);
78 static bool safeEnv(const Envelope* env, const PrecisionModel* pm, Envelope& rsltEnvelope);
79
80 static bool isEmpty(const Geometry* geom);
81
87 static bool isDisjoint(const Envelope* envA, const Envelope* envB, const PrecisionModel* pm);
88
89 static bool isLess(double v1, double v2, double tol) {
90 return v1 <= v2 * (1 + tol);
91 };
92
93 static bool isGreater(double v1, double v2, double tol) {
94 return v1 >= v2 * (1 - tol);
95 }
96
97
98public:
99
100 static bool isFloating(const PrecisionModel* pm);
101
117 static bool clippingEnvelope(int opCode, const InputGeometry* inputGeom, const PrecisionModel* pm, Envelope& rsltEnvelope);
118
125 static bool isEmptyResult(int opCode, const Geometry* a, const Geometry* b, const PrecisionModel* pm);
126
132 static bool isEnvDisjoint(const Geometry* a, const Geometry* b, const PrecisionModel* pm);
133
141 static std::unique_ptr<Geometry> createEmptyResult(int dim, const GeometryFactory* geomFact);
142
156 static int resultDimension(int opCode, int dim0, int dim1);
157
161 static std::unique_ptr<Geometry> createResultGeometry(
162 std::vector<std::unique_ptr<Polygon>>& resultPolyList,
163 std::vector<std::unique_ptr<LineString>>& resultLineList,
164 std::vector<std::unique_ptr<Point>>& resultPointList,
165 const GeometryFactory* geometryFactory);
166
167 static std::unique_ptr<Geometry> toLines(OverlayGraph* graph, bool isOutputEdges, const GeometryFactory* geomFact);
168
186 const Geometry* geom0, const Geometry* geom1,
187 int opCode, const Geometry* result);
188
193 static bool round(const Point* pt, const PrecisionModel* pm, Coordinate& rsltCoord);
194
195 template<typename T>
196 static void moveGeometry(std::vector<std::unique_ptr<T>>& inGeoms, std::vector<std::unique_ptr<Geometry>>& outGeoms)
197 {
198 static_assert(std::is_base_of<Geometry, T>::value, "");
199 for (auto& geom: inGeoms) {
200 Geometry* outGeom = static_cast<Geometry*>(geom.release());
201 outGeoms.emplace_back(outGeom);
202 }
203 return;
204 }
205
206
207};
208
209
210} // namespace geos.operation.overlayng
211} // namespace geos.operation
212} // namespace geos
213
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: Point.h:63
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:90
Definition: OverlayGraph.h:54
Definition: OverlayUtil.h:57
static bool round(const Point *pt, const PrecisionModel *pm, Coordinate &rsltCoord)
static int resultDimension(int opCode, int dim0, int dim1)
static bool isEmptyResult(int opCode, const Geometry *a, const Geometry *b, const PrecisionModel *pm)
static std::unique_ptr< Geometry > createEmptyResult(int dim, const GeometryFactory *geomFact)
static bool isEnvDisjoint(const Geometry *a, const Geometry *b, const PrecisionModel *pm)
static bool isResultAreaConsistent(const Geometry *geom0, const Geometry *geom1, int opCode, const Geometry *result)
static std::unique_ptr< Geometry > createResultGeometry(std::vector< std::unique_ptr< Polygon > > &resultPolyList, std::vector< std::unique_ptr< LineString > > &resultLineList, std::vector< std::unique_ptr< Point > > &resultPointList, const GeometryFactory *geometryFactory)
static bool clippingEnvelope(int opCode, const InputGeometry *inputGeom, const PrecisionModel *pm, Envelope &rsltEnvelope)
Definition: Angle.h:26
Basic namespace for all GEOS functionalities.
Definition: geos.h:39