GEOS 3.11.1
PrecisionUtil.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/export.h>
18
19#include <geos/geom/CoordinateFilter.h>
20#include <geos/geom/Coordinate.h>
21
22#include <vector>
23#include <map>
24
25
26// Forward declarations
27namespace geos {
28namespace geom {
29class Geometry;
30class Envelope;
31class PrecisionModel;
32}
33namespace operation {
34}
35}
36
37namespace geos { // geos.
38namespace operation { // geos.operation
39namespace overlayng { // geos.operation.overlayng
40
41using namespace geos::geom;
42
49class GEOS_DLL PrecisionUtil {
50
51private:
52
53 static double robustScale(double inherentScale, double safeScale);
54
62 static double maxBoundMagnitude(const Envelope* env);
63
78 static double precisionScale(double value, int precisionDigits);
79
80
81
82public:
83
84 static constexpr int MAX_ROBUST_DP_DIGITS = 14;
85
86 PrecisionUtil() {};
87
99 static PrecisionModel robustPM(const Geometry* a, const Geometry* b);
100
113
121 static double robustScale(const Geometry* a, const Geometry* b);
122
130 static double robustScale(const Geometry* a);
131
138 static double safeScale(double value);
139
146 static double safeScale(const Geometry* geom);
147
154 static double safeScale(const Geometry* a, const Geometry* b);
155
167 static double inherentScale(double value);
168
179 static double inherentScale(const Geometry* geom);
180
191 static double inherentScale(const Geometry* a, const Geometry* b);
192
202 static int numberOfDecimals(double value);
203
208 class GEOS_DLL InherentScaleFilter: public CoordinateFilter {
209
210 private:
211
212 double scale;
213
214 void updateScaleMax(double value) {
215 double scaleVal = PrecisionUtil::inherentScale(value);
216 if (scaleVal > scale) {
217 scale = scaleVal;
218 }
219 }
220
221 public:
222
224 : scale(0.0)
225 {}
226
227 void filter_ro(const geom::Coordinate* coord) override
228 {
229 updateScaleMax(coord->x);
230 updateScaleMax(coord->y);
231 }
232
233 double getScale() const {
234 return scale;
235 }
236 };
237
238
239};
240
241
242} // namespace geos.operation.overlayng
243} // namespace geos.operation
244} // namespace geos
245
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:41
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
double y
y-coordinate
Definition: Coordinate.h:81
double x
x-coordinate
Definition: Coordinate.h:78
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:90
void filter_ro(const geom::Coordinate *coord) override
Performs an operation with coord.
Definition: PrecisionUtil.h:227
Definition: PrecisionUtil.h:49
static double inherentScale(const Geometry *geom)
static double robustScale(const Geometry *a, const Geometry *b)
static PrecisionModel robustPM(const Geometry *a, const Geometry *b)
static double safeScale(const Geometry *a, const Geometry *b)
static double inherentScale(double value)
static double robustScale(const Geometry *a)
static int numberOfDecimals(double value)
static PrecisionModel robustPM(const Geometry *a)
static double safeScale(double value)
static double inherentScale(const Geometry *a, const Geometry *b)
static double safeScale(const Geometry *geom)
Definition: Angle.h:26
Basic namespace for all GEOS functionalities.
Definition: geos.h:39