GEOS  3.13.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
27 namespace geos {
28 namespace geom {
29 class Geometry;
30 class Envelope;
31 class PrecisionModel;
32 }
33 namespace operation {
34 }
35 }
36 
37 namespace geos { // geos.
38 namespace operation { // geos.operation
39 namespace overlayng { // geos.operation.overlayng
40 
41 using namespace geos::geom;
42 
49 class GEOS_DLL PrecisionUtil {
50 
51 private:
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 
82 public:
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 
112  static PrecisionModel robustPM(const Geometry* a);
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:43
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
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:88
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: Angle.h:25