GEOS 3.14.0dev
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
47class GEOS_DLL PrecisionUtil {
52
53private:
54
55 static double robustScale(double inherentScale, double safeScale);
56
64 static double maxBoundMagnitude(const Envelope* env);
65
80 static double precisionScale(double value, int precisionDigits);
81
82
83
84public:
85
86 static constexpr int MAX_ROBUST_DP_DIGITS = 14;
87
88 PrecisionUtil() {};
89
101 static PrecisionModel robustPM(const Geometry* a, const Geometry* b);
102
115
123 static double robustScale(const Geometry* a, const Geometry* b);
124
132 static double robustScale(const Geometry* a);
133
140 static double safeScale(double value);
141
148 static double safeScale(const Geometry* geom);
149
156 static double safeScale(const Geometry* a, const Geometry* b);
157
169 static double inherentScale(double value);
170
181 static double inherentScale(const Geometry* geom);
182
193 static double inherentScale(const Geometry* a, const Geometry* b);
194
204 static int numberOfDecimals(double value);
205
210 class GEOS_DLL InherentScaleFilter: public CoordinateFilter {
211
212 private:
213
214 double scale;
215
216 void updateScaleMax(double value) {
217 double scaleVal = PrecisionUtil::inherentScale(value);
218 if (scaleVal > scale) {
219 scale = scaleVal;
220 }
221 }
222
223 public:
224
226 : scale(0.0)
227 {}
228
229 void filter_ro(const geom::Coordinate* coord) override
230 {
231 updateScaleMax(coord->x);
232 updateScaleMax(coord->y);
233 }
234
235 double getScale() const {
236 return scale;
237 }
238 };
239
240
241};
242
243
244} // namespace geos.operation.overlayng
245} // namespace geos.operation
246} // namespace geos
247
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition CoordinateFilter.h:43
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:88
Definition PrecisionUtil.h:47
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)
Basic namespace for all GEOS functionalities.
Definition geos.h:39